Valgrind 显示大小为 8 的错误的未初始化值。
有时,以下条件跳转会出现未初始化值错误。
我所做的就是使用 gcc 附带的 stdc++ 库打印格式化字符串
和内置的 vsnprintf。
这是一个名为 format 的方法,它是自定义字符串类的一部分。
现在怎么办?一切看起来都是正确的。错误似乎在 _itoa.c 内部。但我在外面能想到的就是不要使用这个功能,这不太可能!
==4229== Memcheck, a memory error detector
==4229== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==4229== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==4229== Command: ./test
==4229==
==4229== Use of uninitialised value of size 8
==4229== at 0x54A3DF1: _itoa_word (_itoa.c:196)
==4229== by 0x54A5138: vfprintf (vfprintf.c:1613)
==4229== by 0x555C74F: __vsnprintf_chk (vsnprintf_chk.c:65)
==4229== by 0x407E57: myString::format(char const*, ...) (stdio2.h:79)
==4229== by 0x419D14: ID::toString() (id.cpp:151)
==4229== by 0x41D03D: main (test.cpp:126)
==4229==
==4229== Conditional jump or move depends on uninitialised value(s)
==4229== at 0x54A3DF8: _itoa_word (_itoa.c:196)
==4229== by 0x54A5138: vfprintf (vfprintf.c:1613)
==4229== by 0x555C74F: __vsnprintf_chk (vsnprintf_chk.c:65)
==4229== by 0x407E57: myString::format(char const*, ...) (stdio2.h:79)
==4229== by 0x419D14: ID::toString() (uuid.cpp:151)
==4229== by 0x41D03D: main (test.cpp:126)
==4229==
==4229==
==4229== HEAP SUMMARY:
==4229== in use at exit: 0 bytes in 0 blocks
==4229== total heap usage: 6 allocs, 6 frees, 1,340 bytes allocated
==4229==
==4229== All heap blocks were freed -- no leaks are possible
==4229==
==4229== For counts of detected and suppressed errors, rerun with: -v
==4229== Use --track-origins=yes to see where uninitialised values come from
==4229== ERROR SUMMARY: 3 errors from 2 contexts (suppressed: 4 from 4)
这是 C 库中实际查看您的数字以便将其格式化为字符串的位置,它表明您正在格式化的数字来自未初始化的存储。
添加 valgrind 选项--track-origins=yes
有关未初始化值的来源的更多详细信息。
因为在未初始化的内存中进行复制是很常见的,例如通过结构中的填充,valgrind 会跟踪未初始化值的复制,并且不会抱怨,直到实际使用该值的方式可能会影响程序的外部可见行为。这可能会使确定未初始化值的原始来源变得混乱,因为在对其进行任何其他操作之前它可能已被复制了多次。选项--track-origins=yes
跟踪附加信息以查明未初始化值的来源,以便在未初始化值最终被使用时可以显示该信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)