From d55d9d2fc869461382d8b802a4f97597c0a7ff54 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 4 May 2017 22:21:50 -0700 Subject: Disallow negative bits in two logical operations. * arith.c (comp_trunc, logtrunc): Check for a negative bits value and throw. --- arith.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'arith.c') 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) -- cgit v1.2.3