diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-06-05 19:21:44 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-06-05 19:21:44 -0700 |
commit | 6d11126e4643599b38b1d8b92ad468ef02539b95 (patch) | |
tree | a6a3b7651ca92607fcba4f1d70d9187285ada31c /itypes.c | |
parent | 936e52d347430fe6f60de29f8cfce44435d5094e (diff) | |
download | txr-6d11126e4643599b38b1d8b92ad468ef02539b95.tar.gz txr-6d11126e4643599b38b1d8b92ad468ef02539b95.tar.bz2 txr-6d11126e4643599b38b1d8b92ad468ef02539b95.zip |
itypes: avoid out of range literal.
* itypes.c (c_i32): Avoid the troublesome expressions
-0x80000000. Instead, cast 0x7FFFFFFF to the cnum type,
then invert, and subtract one.
(c_i64): Similarly for -0x8000000000000000.
Diffstat (limited to 'itypes.c')
-rw-r--r-- | itypes.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -81,7 +81,7 @@ u16_t c_u16(val n, val self) i32_t c_i32(val n, val self) { cnum v = c_num(n); - if (v < (cnum) -0x80000000 || v > (cnum) 0x7FFFFFFF) + if (v < (- (cnum) 0x7FFFFFFF - 1) || v > (cnum) 0x7FFFFFFF) uw_throwf(error_s, lit("~a: value ~s is out of signed 32 bit range"), self, n, nao); return v; @@ -102,7 +102,7 @@ u32_t c_u32(val n, val self) i64_t c_i64(val n, val self) { cnum v = c_num(n); - if (v < (cnum) -0x8000000000000000 || v > (cnum) 0x7FFFFFFFFFFFFFFF) + if (v < (- (cnum) 0x7FFFFFFFFFFFFFFF - 1) || v > (cnum) 0x7FFFFFFFFFFFFFFF) uw_throwf(error_s, lit("~a: value ~s is out of signed 64 bit range"), self, n, nao); return v; |