上週習題
- 除了手動測試外,有沒有更聰明一點的方式,可以幫你找到程式碼中,
未看先猜未初始化就使用的可能錯誤?
參考解答
==22043== Conditional jump or move depends on uninitialised value(s)
==22043== at 0x539AF90: vfprintf (vfprintf.c:1655)
==22043== by 0x53A1FF8: printf (printf.c:34)
==22043== by 0x400982: bar() (main.cpp:33)
==22043== by 0x400A1C: main (main.cpp:48)
==22043== Use of uninitialised value of size 8
==22043== at 0x5397551: _itoa_word (_itoa.c:180)
==22043== by 0x539BAE1: vfprintf (vfprintf.c:1654)
==22043== by 0x53A1FF8: printf (printf.c:34)
==22043== by 0x4009B6: bar() (main.cpp:38)
==22043== by 0x400A1C: main (main.cpp:48)
==22043==
==22043== HEAP SUMMARY:
==22043== in use at exit: 0 bytes in 0 blocks
==22043== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==22043==
==22043== All heap blocks were freed -- no leaks are possible
==22043==
==22043== For counts of detected and suppressed errors, rerun with: -v
==22043== Use --track-origins=yes to see where uninitialised values come from
==22043== ERROR SUMMARY: 109 errors from 15 contexts (suppressed: 0 from 0)
參考工具(廣為人知,但也很多人選擇不用的)
http://valgrind.org/
沒有留言:
張貼留言