From 591e10a121bae5851a796dead0b2df97d08b628f Mon Sep 17 00:00:00 2001 From: Michael Gran Date: Thu, 10 Nov 2022 14:45:31 -0800 Subject: [PATCH] Avoids sign extension error in bytevector construction Without this, negative numbers may change signedness * libguile/bytevectors (is_signed_int8, is_unsigned_int8) (is_signed_int16, is_unsigned_int16)[__MINGW32__ __x86_64__]: use long long type. --- libguile/bytevectors.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c index 58e398b61..4e697318a 100644 --- a/libguile/bytevectors.c +++ b/libguile/bytevectors.c @@ -71,14 +71,18 @@ #define INT16_T_unsigned uint16_t #define INT32_T_signed int32_t #define INT32_T_unsigned uint32_t +#if !(__MINGW32__ && __x86_64__) #define is_signed_int8(_x) (((_x) >= -128L) && ((_x) <= 127L)) #define is_unsigned_int8(_x) ((_x) <= 255UL) #define is_signed_int16(_x) (((_x) >= -32768L) && ((_x) <= 32767L)) #define is_unsigned_int16(_x) ((_x) <= 65535UL) -#if !(__MINGW32__ && __x86_64__) #define is_signed_int32(_x) (((_x) >= -2147483648L) && ((_x) <= 2147483647L)) #define is_unsigned_int32(_x) ((_x) <= 4294967295UL) #else /* (__MINGW32__ && __x86_64__) */ +#define is_signed_int8(_x) (((_x) >= -128LL) && ((_x) <= 127LL)) +#define is_unsigned_int8(_x) ((_x) <= 255ULL) +#define is_signed_int16(_x) (((_x) >= -32768LL) && ((_x) <= 32767LL)) +#define is_unsigned_int16(_x) ((_x) <= 65535ULL) #define is_signed_int32(_x) (((_x) >= -2147483648LL) && ((_x) <= 2147483647LL)) #define is_unsigned_int32(_x) ((_x) <= 4294967295ULL) #endif /* (__MINGW32__ && __x86_64__) */