Fix newlib/testsuite/newlib.time/tzset.c compilation for targets with a 16-bit int.

Message ID 20260713004018.744543-1-jdx@o2.pl
State New
Headers
Series Fix newlib/testsuite/newlib.time/tzset.c compilation for targets with a 16-bit int. |

Commit Message

Jan Dubiec July 13, 2026, 12:39 a.m. UTC
  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/build-newlib-h8300-linux/h8300-elf/newlib/testsuite/tzset.x
/mnt/Works/newlib/newlib/testsuite/newlib.time/tzset.c:9:34: warning: integer 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 expansion of macro 'IN_SECONDS'
  102 | /GMT-14 */              "<+14>-14",                        -IN_SECONDS(14, 0, 0),     NO_TIME},
      |                                                             ^~~~~~~~~~
/mnt/Works/newlib/newlib/testsuite/newlib.time/tzset.c:9:34: warning: integer 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 expansion of macro 'IN_SECONDS'
  103 | /GMT+12 */              "<-12>12",                          IN_SECONDS(12, 0, 0),     NO_TIME},
      |                                                             ^~~~~~~~~~

Signed-off-by: Jan Dubiec <jdx@o2.pl>
---
 newlib/testsuite/newlib.time/tzset.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
  

Comments

Jeff Johnston July 15, 2026, 12:09 a.m. UTC | #1
Patch merged.

-- Jeff J.

On Sun, Jul 12, 2026 at 8:40 PM Jan Dubiec <jdx@o2.pl> wrote:

> 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/build-newlib-h8300-linux/h8300-elf/newlib/testsuite/tzset.x
> /mnt/Works/newlib/newlib/testsuite/newlib.time/tzset.c:9:34: warning:
> integer 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
> expansion of macro 'IN_SECONDS'
>   102 | /GMT-14 */              "<+14>-14",
> -IN_SECONDS(14, 0, 0),     NO_TIME},
>       |
>  ^~~~~~~~~~
> /mnt/Works/newlib/newlib/testsuite/newlib.time/tzset.c:9:34: warning:
> integer 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
> expansion of macro 'IN_SECONDS'
>   103 | /GMT+12 */              "<-12>12",
> IN_SECONDS(12, 0, 0),     NO_TIME},
>       |
>  ^~~~~~~~~~
>
> Signed-off-by: Jan Dubiec <jdx@o2.pl>
> ---
>  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). */
>  #include <stdio.h>
>  #include <stdlib.h>
> +#include <stdint.h>
>
>  // BEGIN test vectors
>  #include <time.h>
>  #include <limits.h>
>
> -#define IN_SECONDS(h, m, s) ((h) * 3600 + (m) * 60 + (s))
> +#define IN_SECONDS(h, m, s) ((h) * INT32_C(3600) + (m) * INT32_C(60) +
> (s))
>  #define NO_TIME INT_MIN
>
>  struct tz_test {
>      const char* tzstr;
> -    int offset_seconds;
> -    int dst_offset_seconds;
> +    int32_t offset_seconds;
> +    int32_t dst_offset_seconds;
>  };
>
>  extern struct tm winter_tm;
> --
> 2.54.0
>
>
  

Patch

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). */
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 
 // BEGIN test vectors
 #include <time.h>
 #include <limits.h>
 
-#define IN_SECONDS(h, m, s) ((h) * 3600 + (m) * 60 + (s))
+#define IN_SECONDS(h, m, s) ((h) * INT32_C(3600) + (m) * INT32_C(60) + (s))
 #define NO_TIME INT_MIN
 
 struct tz_test {
     const char* tzstr;
-    int offset_seconds;
-    int dst_offset_seconds;
+    int32_t offset_seconds;
+    int32_t dst_offset_seconds;
 };
 
 extern struct tm winter_tm;