[tz] [PROPOSED] Do not assume bytes have 8 bits
Paul Eggert
eggert at cs.ucla.edu
Fri Apr 23 19:27:08 UTC 2021
* zic.c (convert, convert64): Mask bytes with 0xff before storing
them, for portability to machines where bytes have more than 8 bits.
Although this is surely only of theoretical interest, we might as
well be portable.
---
zic.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/zic.c b/zic.c
index 88b1531..77a5698 100644
--- a/zic.c
+++ b/zic.c
@@ -1927,7 +1927,7 @@ convert(uint_fast32_t val, char *buf)
unsigned char *const b = (unsigned char *) buf;
for (i = 0, shift = 24; i < 4; ++i, shift -= 8)
- b[i] = val >> shift;
+ b[i] = (val >> shift) & 0xff;
}
static void
@@ -1938,7 +1938,7 @@ convert64(uint_fast64_t val, char *buf)
unsigned char *const b = (unsigned char *) buf;
for (i = 0, shift = 56; i < 8; ++i, shift -= 8)
- b[i] = val >> shift;
+ b[i] = (val >> shift) & 0xff;
}
static void
--
2.27.0
More information about the tz
mailing list