[tz] [PROPOSED 2/2] Do not assume negative >> behavior

Paul Eggert eggert at cs.ucla.edu
Fri Apr 23 19:07:06 UTC 2021


* 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



More information about the tz mailing list