diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-05-04 22:21:50 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-05-04 22:21:50 -0700 |
commit | d55d9d2fc869461382d8b802a4f97597c0a7ff54 (patch) | |
tree | 9353960d958065c18e48329a57e14a0610e2454e | |
parent | 89ad4e6e250183c2d865f376b0a44cfb4d5e1a77 (diff) | |
download | txr-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.
-rw-r--r-- | arith.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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) |