summaryrefslogtreecommitdiffstats
path: root/arith.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-04 22:21:50 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-04 22:21:50 -0700
commitd55d9d2fc869461382d8b802a4f97597c0a7ff54 (patch)
tree9353960d958065c18e48329a57e14a0610e2454e /arith.c
parent89ad4e6e250183c2d865f376b0a44cfb4d5e1a77 (diff)
downloadtxr-d55d9d2fc869461382d8b802a4f97597c0a7ff54.tar.gz
txr-d55d9d2fc869461382d8b802a4f97597c0a7ff54.tar.bz2
txr-d55d9d2fc869461382d8b802a4f97597c0a7ff54.zip
Disallow negative bits in two logical operations.
* arith.c (comp_trunc, logtrunc): Check for a negative bits value and throw.
Diffstat (limited to 'arith.c')
-rw-r--r--arith.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/arith.c b/arith.c
index c17ab743..a4a65ad7 100644
--- a/arith.c
+++ b/arith.c
@@ -2285,6 +2285,9 @@ static val comp_trunc(val a, val bits)
bn = c_num(bits);
+ if (bn < 0)
+ goto bad4;
+
switch (type(a)) {
case NUM:
an = c_num(a);
@@ -2311,6 +2314,9 @@ bad2:
bad3:
uw_throwf(error_s, lit("lognot: non-integral operand ~s"), a, nao);
+
+bad4:
+ uw_throwf(error_s, lit("lognot: negative bits value ~s"), bits, nao);
}
val lognot(val a, val bits)
@@ -2348,6 +2354,9 @@ val logtrunc(val a, val bits)
bn = c_num(bits);
+ if (bn < 0)
+ goto bad4;
+
switch (type(a)) {
case NUM:
an = c_num(a);
@@ -2374,6 +2383,9 @@ bad2:
bad3:
uw_throwf(error_s, lit("logtrunc: non-integral operand ~s"), a, nao);
+
+bad4:
+ uw_throwf(error_s, lit("logtrunc: negative bits value ~s"), bits, nao);
}
val sign_extend(val n, val nbits)