[PROPOSED 1/2] Do not assume unsigned->signed conversion style
* localtime.c (detzcode64): Use int_fast64_t, not uint_fast64_t, for local variable, to avoid an implementation-defined conversion when the variable’s value is returned. --- localtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/localtime.c b/localtime.c index 6c88b6e..9dd496d 100644 --- a/localtime.c +++ b/localtime.c @@ -237,7 +237,7 @@ detzcode(const char *const codep) static int_fast64_t detzcode64(const char *const codep) { - register uint_fast64_t result; + register int_fast64_t result; register int i; int_fast64_t one = 1; int_fast64_t halfmaxval = one << (64 - 2); -- 2.27.0
* private.h (uint_fast32_t) [!UINT_FAST32_MAX]: New backwards-compatibility typedef. * zic.c (convert, convert64): Arguments are now unsigned, to avoid implementation-defined behavior when shifting negative values right. Callers can still pass signed values, which are automatically converted at the point of call by C’s type-conversion rules. --- private.h | 4 ++++ zic.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/private.h b/private.h index 912cb20..cee3b11 100644 --- a/private.h +++ b/private.h @@ -321,6 +321,10 @@ typedef long intmax_t; # endif #endif +#ifndef UINT_FAST32_MAX +typedef unsigned long uint_fast32_t; +#endif + #ifndef UINT_FAST64_MAX # if defined ULLONG_MAX || defined __LONG_LONG_MAX__ typedef unsigned long long uint_fast64_t; diff --git a/zic.c b/zic.c index a930d57..88b1531 100644 --- a/zic.c +++ b/zic.c @@ -1920,7 +1920,7 @@ rulesub(struct rule *rp, const char *loyearp, const char *hiyearp, } static void -convert(const int_fast32_t val, char *const buf) +convert(uint_fast32_t val, char *buf) { register int i; register int shift; @@ -1931,7 +1931,7 @@ convert(const int_fast32_t val, char *const buf) } static void -convert64(const zic_t val, char *const buf) +convert64(uint_fast64_t val, char *buf) { register int i; register int shift; -- 2.27.0
participants (1)
-
Paul Eggert