2012-01-27 45 views
3

第一次(在我的新開發環境中),我看到valgrind抱怨mktime,但我不確定這是libc庫,valgrind還是我的代碼中的錯誤。我會從錯誤開始(下面) - 是否有足夠的信息來解釋原因?valgrind抱怨__mktime - 是我的錯嗎?

==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: ??? 

回答

5

對於其他人誰運行到這...

的結構是由strptime,這顯然並不在結構成員填補未使用(DST)充滿...但mktime不喜歡這樣:)所以memset它爲零

+0

這是一個非常普遍的錯誤。如果您希望mktime確定tm_isdst的正確值,請將其設置爲-1(如mktime手冊頁中所述)。 – 2012-01-28 17:20:50

+3

或者 - 建議[這裏](http://www.ex-parrot.com/~chris/random/initialise.html) - 而不是memset'ting,用struct struct tm date來初始化零結構= {0};' – freitass 2013-05-23 16:08:03