gpt4 book ai didi

gcc - c 库中的 Valgrind 错误?

转载 作者:行者123 更新时间:2023-12-04 14:52:09 25 4
gpt4 key购买 nike

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跟踪附加信息以查明未初始化值的来源,以便在未初始化值最终被使用时显示。

关于gcc - c 库中的 Valgrind 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3681652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com