[PATCH] Fix newlib/testsuite/newlib.time/tzset.c compilation for targets with a 16-bit int.
Jan Dubiec <[email protected]> Mon, 13 Jul 2026 02:39:54 +0200
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
When the test case is compiled for a target with a 16-bit int, the compiler
emits the two warnings shown below, causing the test to fail. The code
assumes that int is 32 bits wide, which is not always the case. This patch
removes that assumption and fixes the resulting compilation warnings.
h8300-elf-gcc /mnt/Works/newlib/newlib/testsuite/newlib.time/tzset.c =
-I/mnt/Works/newlib/newlib/testsuite/include -lm -o /mnt/Works/xcomp/buil=
d-newlib-h8300-linux/h8300-elf/newlib/testsuite/tzset.x
/mnt/Works/newlib/newlib/testsuite/newlib.time/tzset.c:9:34: warning: integ=
er overflow in expression of type 'int' results in '-15136' [-Woverflow]
9 | #define IN_SECONDS(h, m, s) ((h) * 3600 + (m) * 60 + (s))
| ^
/mnt/Works/newlib/newlib/testsuite/newlib.time/tzset.c:102:73: note: in exp=
ansion of macro 'IN_SECONDS'
102 | /GMT-14 */ "<+14>-14", -IN_SECO=
NDS(14, 0, 0), NO_TIME},
| ^~~~~~~=
~~~
/mnt/Works/newlib/newlib/testsuite/newlib.time/tzset.c:9:34: warning: integ=
er overflow in expression of type 'int' results in '-22336' [-Woverflow]
9 | #define IN_SECONDS(h, m, s) ((h) * 3600 + (m) * 60 + (s))
| ^
/mnt/Works/newlib/newlib/testsuite/newlib.time/tzset.c:103:73: note: in exp=
ansion of macro 'IN_SECONDS'
103 | /GMT+12 */ "<-12>12", IN_SECO=
NDS(12, 0, 0), NO_TIME},
| ^~~~~~~=
~~~
Signed-off-by: Jan Dubiec <[email protected]>
---
newlib/testsuite/newlib.time/tzset.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/newlib/testsuite/newlib.time/tzset.c b/newlib/testsuite/newlib=
.time/tzset.c
index db25077ce..870d42642 100644
--- a/newlib/testsuite/newlib.time/tzset.c
+++ b/newlib/testsuite/newlib.time/tzset.c
@@ -1,18 +1,19 @@
/* Test that valid POSIX timezone strings are correctly parsed by tzset(3)=
. */=0D
#include <stdio.h>=0D
#include <stdlib.h>=0D
+#include <stdint.h>=0D
=0D
// BEGIN test vectors=0D
#include <time.h>=0D
#include <limits.h>=0D
=0D
-#define IN_SECONDS(h, m, s) ((h) * 3600 + (m) * 60 + (s))=0D
+#define IN_SECONDS(h, m, s) ((h) * INT32_C(3600) + (m) * INT32_C(60) + (s)=
)=0D
#define NO_TIME INT_MIN=0D
=0D
struct tz_test {=0D
const char* tzstr;=0D
- int offset_seconds;=0D
- int dst_offset_seconds;=0D
+ int32_t offset_seconds;=0D
+ int32_t dst_offset_seconds;=0D
};=0D
=0D
extern struct tm winter_tm;=0D
--=20
2.54.0