Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc

2021-04-21 Thread Lars Munch
My tests show (with recent glibc version) that with TZ=UTC mktime will return -1 for tm_isdst=1. For tm_isdst=0 and tm_isdst=-1 mktime returns the same value. IMHO, tm_isdst=0 makes the most sense for TZ=UTC as UTC does not support DST. On Wed, Apr 21, 2021 at 6:50 PM Richard Cochran wrote: >

Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc

2021-04-21 Thread Richard Cochran
On Wed, Apr 21, 2021 at 07:28:59PM +0200, Lars Munch wrote: > My tests show (with recent glibc version) that with TZ=UTC mktime will > return -1 for tm_isdst=1. For tm_isdst=0 and tm_isdst=-1 mktime returns the > same value. > > IMHO, tm_isdst=0 makes the most sense for TZ=UTC as UTC does not

Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc

2021-04-21 Thread Richard Cochran
On Wed, Apr 21, 2021 at 11:51:55AM +, Geva, Erez wrote: > Looks like the man page is not accurate. > Looking in > https://pubs.opengroup.org/onlinepubs/009695399/functions/mktime.html Okay, I see now, in the man page we read: The value specified in the tm_isdst field informs mktime()

Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc

2021-04-21 Thread Geva, Erez
) (DI PA DCP R 3) Cc: Richard Cochran ; linuxptp-devel@lists.sourceforge.net Subject: Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc My Arch system does indeed have daylight saving set, but nmea.c forces the TZ to UTC where a positive value of tm_isdst does not make

Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc

2021-04-21 Thread Geva, Erez
To: Michael Galassi Cc: linuxptp-devel@lists.sourceforge.net Subject: Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc Sorry for the noise. In my previous example I had by accident pasted a huge number into the example. New example: #include #include #include int main

Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc

2021-04-21 Thread Lars Munch
chard Cochran > Sent: Tuesday, 20 April 2021 16:05 > To: Lars Munch > Cc: linuxptp-devel@lists.sourceforge.net > Subject: Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in > nmea_scan_rmc > > On Tue, Apr 20, 2021 at 11:44:06AM +0200, Lars Munch wrote: > > tm_isdst needs t

Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc

2021-04-21 Thread Lars Munch
bug report in the > relevant packages/systems. > > > > Erez > > > > > > *From:* Lars Munch > *Sent:* Tuesday, 20 April 2021 22:24 > *To:* Michael Galassi > *Cc:* linuxptp-devel@lists.sourceforge.net > *Subject:* Re: [Linuxptp-devel] [PATCH] Fix uninitia

Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc

2021-04-21 Thread Geva, Erez
Message- From: Richard Cochran Sent: Tuesday, 20 April 2021 16:05 To: Lars Munch Cc: linuxptp-devel@lists.sourceforge.net Subject: Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc On Tue, Apr 20, 2021 at 11:44:06AM +0200, Lars Munch wrote: > tm_isdst ne

Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc

2021-04-20 Thread Michael Galassi
I think that no matter what any particular implementation might do, we are relying on undefined behavior which is at best unsafe. I wonder if maybe we shouldn't consider initializing the entire structure (and all others?) after it is allocated. The performance price feels small and the safety

Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc

2021-04-20 Thread Lars Munch
Sorry for the noise. In my previous example I had by accident pasted a huge number into the example. New example: #include #include #include int main() { struct tm t; time_t now = time((void*)0); localtime_r(, ); setenv("TZ", "UTC", 1); t.tm_isdst = 1; printf("%ld\n",

Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc

2021-04-20 Thread Lars Munch
Indeed, any positive random number in tm.tm_isdst will set DST in effect it seems. On my stripped down ARM system with no timezone information, it will simply return -1. On Tue, Apr 20, 2021 at 4:26 PM Michael Galassi wrote: > Somewhere lies a bug. The following code snippet: > #include >

Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc

2021-04-20 Thread Lars Munch
Ok, so mktime is forced to return in time UTC time scale earlier in the code: #include #include #include int main() { struct tm t; time_t now = time((void*)0); localtime_r(, ); setenv("TZ", "UTC", 1); t.tm_isdst = 41; printf("%ld\n", mktime()); t.tm_isdst =

Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc

2021-04-20 Thread Michael Galassi
Somewhere lies a bug. The following code snippet: #include #include int main() { struct tm t; time_t now = time((void*)0); localtime_r(, ); t.tm_isdst = 1; printf("%ld\n", mktime()); t.tm_isdst = 0; printf("%ld\n", mktime()); t.tm_isdst = -1; printf("%ld\n",

Re: [Linuxptp-devel] [PATCH] Fix uninitialized variable in nmea_scan_rmc

2021-04-20 Thread Richard Cochran
On Tue, Apr 20, 2021 at 11:44:06AM +0200, Lars Munch wrote: > tm_isdst needs to be initialized to make sure mktime does not fail > or calculates the wrong time. No, take a look at the mktime(3) man page. There you will read the following. The mktime() function modifies the fields of the