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 gua

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(&now, &t); setenv("TZ", "UTC", 1); t.tm_isdst = 1; printf("%ld

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 > #in

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(&now, &t); setenv("TZ", "UTC", 1); t.tm_isdst = 41; printf("%ld\n", mktime(&t)); t.tm_

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(&now, &t); t.tm_isdst = 1; printf("%ld\n", mktime(&t)); t.tm_isdst = 0; printf("%ld\n", mktime(&t)); t.tm_isdst = -1; printf(

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

[Linuxptp-devel] [PATCH] RFC: add port.twoStepFlag option in order to handle one step on port basis.

2021-04-20 Thread Luigi 'Comio' Mantellini
port.twoStepFlag. When -1, inherit the global twoStepFlag value, otherwise enable two-step mode for sync messages on port basis. One-step mode can be used only with hardware time stamping. The default is -1 (as global twoStepFlag value). --- config.c | 1 + port.c | 40

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

2021-04-20 Thread Lars Munch
tm_isdst needs to be initialized to make sure mktime does not fail or calculates the wrong time. Signed-off-by: Lars Munch --- nmea.c | 1 + 1 file changed, 1 insertion(+) diff --git a/nmea.c b/nmea.c index dc865d0..44c7c01 100644 --- a/nmea.c +++ b/nmea.c @@ -157,6 +157,7 @@ static int nmea_sc