diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-01-24 07:14:19 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-01-24 07:14:19 -0800 |
commit | 8e785a1f47e49a411abadc8b690b175ff0e231e6 (patch) | |
tree | 1bf3a99eebe43be5dd3a560bf445eb8a22fd5351 | |
parent | 2bc30dec3b2c43145afdbb199341fc023733189d (diff) | |
download | txr-8e785a1f47e49a411abadc8b690b175ff0e231e6.tar.gz txr-8e785a1f47e49a411abadc8b690b175ff0e231e6.tar.bz2 txr-8e785a1f47e49a411abadc8b690b175ff0e231e6.zip |
ffi: fix range checks in be/le i64 put ops.
* ffi.c (ffi_be_i64_put, ffi_le_i64_put): Fix incorrect range
check, causing most negative two values to be rejected.
The aim here is to accept the #x-80..00 most negative two's
complement value. We can't express that directly using the C
expression -0x8000000000000000 because it's not a simple
constant; it's the unary minus applied an unsigned number.
-rw-r--r-- | ffi.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -929,7 +929,7 @@ static void ffi_be_i64_put(struct txr_ffi_type *tft, val n, #if CHAR_BIT * SIZEOF_PTR >= 64 cnum v = c_num(n); - if (v < -convert(cnum, 0x7FFFFFFFFFFFFFFF - 1) || v > 0x7FFFFFFFFFFFFFFF) + if (v < -convert(cnum, 0x7FFFFFFFFFFFFFFF) - 1 || v > 0x7FFFFFFFFFFFFFFF) goto range; dst[0] = (v >> 56) & 0xff; @@ -944,7 +944,7 @@ static void ffi_be_i64_put(struct txr_ffi_type *tft, val n, cnum hi32 = c_num(ash(n, num_fast(-32))); ucnum lo32 = c_unum(logtrunc(n, num_fast(32))); - if (hi32 < -convert(cnum, 0x7FFFFFFF - 1) || hi32 > 0x7FFFFFFF) + if (hi32 < -convert(cnum, 0x7FFFFFFF) - 1 || hi32 > 0x7FFFFFFF) goto range; dst[0] = (hi32 >> 24) & 0xff; @@ -1043,7 +1043,7 @@ static void ffi_le_i64_put(struct txr_ffi_type *tft, val n, #if CHAR_BIT * SIZEOF_PTR >= 64 cnum v = c_num(n); - if (v < -convert(cnum, 0x7FFFFFFFFFFFFFFF - 1) || v > 0x7FFFFFFFFFFFFFFF) + if (v < -convert(cnum, 0x7FFFFFFFFFFFFFFF) - 1 || v > 0x7FFFFFFFFFFFFFFF) goto range; dst[7] = (v >> 56) & 0xff; @@ -1058,7 +1058,7 @@ static void ffi_le_i64_put(struct txr_ffi_type *tft, val n, cnum hi32 = c_num(ash(n, num_fast(-32))); ucnum lo32 = c_unum(logtrunc(n, num_fast(32))); - if (hi32 < -convert(cnum, 0x7FFFFFFF - 1) || hi32 > 0x7FFFFFFF) + if (hi32 < -convert(cnum, 0x7FFFFFFF) - 1 || hi32 > 0x7FFFFFFF) goto range; dst[7] = (hi32 >> 24) & 0xff; |