Re: [PATCH] Fix newlib/testsuite/newlib.time/tzset.c compilation for targets with a 16-bit int.
Jeff Johnston <[email protected]> Tue, 14 Jul 2026 20:09:21 -0400
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <CAOox84tJtC6A826BP_Wz4NOQF=JLT5MK9-c6wG3-0g97h2m6xw@mail.gmail.com> |
--00000000000056626406569b239a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Patch merged. -- Jeff J. On Sun, Jul 12, 2026 at 8:40=E2=80=AFPM Jan Dubiec <[email protected]> wrote: > When the test case is compiled for a target with a 16-bit int, the compil= er > 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 patc= h > 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/tzse= t.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 <[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). */ > #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 > > --00000000000056626406569b239a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:verdana,= sans-serif">Patch merged.</div><div class=3D"gmail_default" style=3D"font-f= amily:verdana,sans-serif"><br></div><div class=3D"gmail_default" style=3D"f= ont-family:verdana,sans-serif">-- Jeff J.</div></div><br><div class=3D"gmai= l_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Sun= , Jul 12, 2026 at 8:40=E2=80=AFPM Jan Dubiec <<a href=3D"mailto:[email protected]= l">[email protected]</a>> wrote:<br></div><blockquote class=3D"gmail_quote" styl= e=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddin= g-left:1ex">When the test case is compiled for a target with a 16-bit int, = the compiler<br> emits the two warnings shown below, causing the test to fail. The code<br> assumes that int is 32 bits wide, which is not always the case. This patch<= br> removes that assumption and fixes the resulting compilation warnings.<br> <br> h8300-elf-gcc=C2=A0 /mnt/Works/newlib/newlib/testsuite/newlib.time/tzset.c= =C2=A0 =C2=A0 =C2=A0 =C2=A0-I/mnt/Works/newlib/newlib/testsuite/include -lm= =C2=A0 -o /mnt/Works/xcomp/build-newlib-h8300-linux/h8300-elf/newlib/testsu= ite/tzset.x<br> /mnt/Works/newlib/newlib/testsuite/newlib.time/tzset.c:9:34: warning: integ= er overflow in expression of type 'int' results in '-15136'= [-Woverflow]<br> =C2=A0 =C2=A0 9 | #define IN_SECONDS(h, m, s) ((h) * 3600 + (m) * 60 + (s))= <br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ^<br> /mnt/Works/newlib/newlib/testsuite/newlib.time/tzset.c:102:73: note: in exp= ansion of macro 'IN_SECONDS'<br> =C2=A0 102 | /GMT-14 */=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &qu= ot;<+14>-14",=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 -IN_SECONDS(14, 0, 0),=C2=A0 =C2=A0 =C2= =A0NO_TIME},<br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0^~~~~~~~~~<br> /mnt/Works/newlib/newlib/testsuite/newlib.time/tzset.c:9:34: warning: integ= er overflow in expression of type 'int' results in '-22336'= [-Woverflow]<br> =C2=A0 =C2=A0 9 | #define IN_SECONDS(h, m, s) ((h) * 3600 + (m) * 60 + (s))= <br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ^<br> /mnt/Works/newlib/newlib/testsuite/newlib.time/tzset.c:103:73: note: in exp= ansion of macro 'IN_SECONDS'<br> =C2=A0 103 | /GMT+12 */=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &qu= ot;<-12>12",=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 IN_SECONDS(12, 0, 0),=C2=A0 =C2=A0 = =C2=A0NO_TIME},<br> =C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0^~~~~~~~~~<br> <br> Signed-off-by: Jan Dubiec <<a href=3D"mailto:[email protected]" target=3D"_blank= ">[email protected]</a>><br> ---<br> =C2=A0newlib/testsuite/newlib.time/tzset.c | 7 ++++---<br> =C2=A01 file changed, 4 insertions(+), 3 deletions(-)<br> <br> diff --git a/newlib/testsuite/newlib.time/tzset.c b/newlib/testsuite/newlib= .time/tzset.c<br> index db25077ce..870d42642 100644<br> --- a/newlib/testsuite/newlib.time/tzset.c<br> +++ b/newlib/testsuite/newlib.time/tzset.c<br> @@ -1,18 +1,19 @@<br> =C2=A0/* Test that valid POSIX timezone strings are correctly parsed by tzs= et(3). */<br> =C2=A0#include <stdio.h><br> =C2=A0#include <stdlib.h><br> +#include <stdint.h><br> <br> =C2=A0// BEGIN test vectors<br> =C2=A0#include <time.h><br> =C2=A0#include <limits.h><br> <br> -#define IN_SECONDS(h, m, s) ((h) * 3600 + (m) * 60 + (s))<br> +#define IN_SECONDS(h, m, s) ((h) * INT32_C(3600) + (m) * INT32_C(60) + (s)= )<br> =C2=A0#define NO_TIME INT_MIN<br> <br> =C2=A0struct tz_test {<br> =C2=A0 =C2=A0 =C2=A0const char* tzstr;<br> -=C2=A0 =C2=A0 int offset_seconds;<br> -=C2=A0 =C2=A0 int dst_offset_seconds;<br> +=C2=A0 =C2=A0 int32_t offset_seconds;<br> +=C2=A0 =C2=A0 int32_t dst_offset_seconds;<br> =C2=A0};<br> <br> =C2=A0extern struct tm winter_tm;<br> -- <br> 2.54.0<br> <br> </blockquote></div> --00000000000056626406569b239a--