4

For the first time (in my new dev environment) I'm seeing valgrind complain about mktime, but I'm not sure if this is a bug in the libc library, valgrind, or my code. I'll start with the error (below) - is this enough info to explain the cause?

==3682==    at 0x38ACE9A505: __mktime_internal (in /lib64/libc-2.12.so)
==3682==    by 0x4D66F7: ???
==3682==    by 0x4D7611: ???
==3682==    by 0x4D23CD: ???
==3682==    by 0x4D175B: ???
==3682==    by 0x38ACE1ECDC: (below main) (in /lib64/libc-2.12.so)
==3682==  Uninitialised value was created by a stack allocation
==3682==    at 0x4D64BE: ???
==3682== 
==3682== Conditional jump or move depends on uninitialised value(s)
==3682==    at 0x38ACE9A505: __mktime_internal (in /lib64/libc-2.12.so)
==3682==    by 0x4D67DA: ???
==3682==    by 0x4D7611: ???
==3682==    by 0x4D23CD: ???
==3682==    by 0x4D175B: ???
==3682==    by 0x38ACE1ECDC: (below main) (in /lib64/libc-2.12.so)
==3682==  Uninitialised value was created by a stack allocation
==3682==    at 0x4D64BE: ???
Michelle Dupuis
  • 337
  • 1
  • 5
  • 20

1 Answers1

5

For anyone else who runs into this...

The struct was filled by strptime, which apparently doesn't fill in struct members that aren't used (dst)...but mktime doesn't like this :) so memset it to zero

Michelle Dupuis
  • 337
  • 1
  • 5
  • 20
  • This is a very common bug. If you want mktime to determine proper value of tm_isdst, set it to -1 (as documented in mktime man page). – Employed Russian Jan 28 '12 at 17:20
  • 3
    Or -- as suggested [here](http://www.ex-parrot.com/~chris/random/initialise.html) -- instead of `memset`ting, initialize the struct with zeroes using `struct tm date = {0};` – freitass May 23 '13 at 16:08