summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2011-02-12 23:44:05 +0000
committerjilles <jilles@FreeBSD.org>2011-02-12 23:44:05 +0000
commit2fb060368627dc29279d5ac969e6c3eb6b0e7ea3 (patch)
treecc8681e662bed68e4af8833df6725164bd71882d /tools
parent4fe7a7870a6da7d72489d152af4b1a951eb50ae4 (diff)
downloadFreeBSD-src-2fb060368627dc29279d5ac969e6c3eb6b0e7ea3.zip
FreeBSD-src-2fb060368627dc29279d5ac969e6c3eb6b0e7ea3.tar.gz
sh: Detect dividing the smallest integer by -1.
This overflows and on some architectures such as amd64 it generates SIGFPE. Generate an error on all architectures.
Diffstat (limited to 'tools')
-rw-r--r--tools/regression/bin/sh/expansion/arith11.012
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/regression/bin/sh/expansion/arith11.0 b/tools/regression/bin/sh/expansion/arith11.0
new file mode 100644
index 0000000..6bc7369
--- /dev/null
+++ b/tools/regression/bin/sh/expansion/arith11.0
@@ -0,0 +1,12 @@
+# $FreeBSD$
+# Try to divide the smallest integer by -1.
+# On amd64 this causes SIGFPE, so make sure the shell checks.
+
+# Calculate the minimum possible value, assuming two's complement and
+# a certain interpretation of overflow when shifting left.
+minint=1
+while [ $((minint <<= 1)) -gt 0 ]; do
+ :
+done
+v=$( eval ': $((minint / -1))' 2>&1 >/dev/null)
+[ $? -ne 0 ] && [ -n "$v" ]
OpenPOWER on IntegriCloud