- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 strtod() 来转换一些输入字符串。在用 valgrind 检查我的代码时,我遇到了“大小为 8 的无效读取”。如果 b 以“i”或“n”开头,则会显示该消息,这就是我到目前为止所发现的。另外,如果我直接创建一个 const char*(不调用 c_str()),strtod 似乎也可以。这是代码:
#include <cstdlib>
#include <string>
int main(int argc, char** argv) {
char* a = 0;
std::string b = "i";
const char* c = b.c_str();
double d = strtod(c, &a);
}
和(详细的)valgrind 输出:
==12638== Memcheck, a memory error detector
==12638== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==12638== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==12638== Command: ./leak
==12638==
--12638-- Valgrind options:
--12638-- --suppressions=/usr/lib/valgrind/debian-libc6-dbg.supp
--12638-- --show-reachable=yes
--12638-- --leak-check=full
--12638-- -v
--12638-- Contents of /proc/version:
--12638-- Linux version 3.2.0-24-generic (buildd@yellow) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #37-Ubuntu SMP Wed Apr 25 08:43:22 UTC 2012
--12638-- Arch and hwcaps: AMD64, amd64-sse3-cx16
--12638-- Page sizes: currently 4096, max supported 4096
--12638-- Valgrind library directory: /usr/lib/valgrind
--12638-- Reading syms from /media/userdata/NetBeansProjects/leak/dist/Debug/GNU-Linux-x86/leak (0x400000)
--12638-- Reading syms from /lib/x86_64-linux-gnu/ld-2.15.so (0x4000000)
--12638-- Considering /lib/x86_64-linux-gnu/ld-2.15.so ..
--12638-- .. CRC mismatch (computed c5d70380 wanted 7d4a76d0)
--12638-- Considering /usr/lib/debug/lib/x86_64-linux-gnu/ld-2.15.so ..
--12638-- .. CRC is valid
--12638-- Reading syms from /usr/lib/valgrind/memcheck-amd64-linux (0x38000000)
--12638-- Considering /usr/lib/valgrind/memcheck-amd64-linux ..
--12638-- .. CRC mismatch (computed b9a585cc wanted 749d1a67)
--12638-- object doesn't have a symbol table
--12638-- object doesn't have a dynamic symbol table
--12638-- Reading suppressions file: /usr/lib/valgrind/debian-libc6-dbg.supp
--12638-- Reading suppressions file: /usr/lib/valgrind/default.supp
==12638== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-12638-by-chri-on-???
==12638== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-12638-by-chri-on-???
==12638== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-12638-by-chri-on-???
==12638==
==12638== TO CONTROL THIS PROCESS USING vgdb (which you probably
==12638== don't want to do, unless you know exactly what you're doing,
==12638== or are doing some strange experiment):
==12638== /usr/lib/valgrind/../../bin/vgdb --pid=12638 ...command...
==12638==
==12638== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==12638== /path/to/gdb ./leak
==12638== and then give GDB the following command
==12638== target remote | /usr/lib/valgrind/../../bin/vgdb --pid=12638
==12638== --pid is optional if only one valgrind process is running
==12638==
--12638-- REDIR: 0x40189e0 (strlen) redirected to 0x380625c7 (???)
--12638-- Reading syms from /usr/lib/valgrind/vgpreload_core-amd64-linux.so (0x4a25000)
--12638-- Considering /usr/lib/valgrind/vgpreload_core-amd64-linux.so ..
--12638-- .. CRC mismatch (computed c82927cb wanted 1861273b)
--12638-- object doesn't have a symbol table
--12638-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so (0x4c27000)
--12638-- Considering /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so ..
--12638-- .. CRC mismatch (computed 72e29ec9 wanted f3ad49da)
--12638-- object doesn't have a symbol table
--12638-- REDIR: 0x4018850 (index) redirected to 0x4c2bc60 (index)
--12638-- REDIR: 0x40188d0 (strcmp) redirected to 0x4c2cc20 (strcmp)
--12638-- Reading syms from /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16 (0x4e32000)
--12638-- Considering /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16 ..
--12638-- .. CRC mismatch (computed ef748751 wanted e44c0328)
--12638-- object doesn't have a symbol table
--12638-- Reading syms from /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x5132000)
--12638-- Considering /lib/x86_64-linux-gnu/libgcc_s.so.1 ..
--12638-- .. CRC mismatch (computed c8e4b229 wanted 098e39f6)
--12638-- object doesn't have a symbol table
--12638-- Reading syms from /lib/x86_64-linux-gnu/libc-2.15.so (0x5348000)
--12638-- Considering /lib/x86_64-linux-gnu/libc-2.15.so ..
--12638-- .. CRC mismatch (computed 0dfc7f92 wanted 306696b6)
--12638-- Considering /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.15.so ..
--12638-- .. CRC is valid
--12638-- Reading syms from /lib/x86_64-linux-gnu/libm-2.15.so (0x5705000)
--12638-- Considering /lib/x86_64-linux-gnu/libm-2.15.so ..
--12638-- .. CRC mismatch (computed 84e90409 wanted 8a8fcc58)
--12638-- Considering /usr/lib/debug/lib/x86_64-linux-gnu/libm-2.15.so ..
--12638-- .. CRC is valid
--12638-- REDIR: 0x53d48c0 (strcasecmp) redirected to 0x4a25610 (_vgnU_ifunc_wrapper)
--12638-- REDIR: 0x53d0c60 (strnlen) redirected to 0x4a25610 (_vgnU_ifunc_wrapper)
--12638-- REDIR: 0x53d6b90 (strncasecmp) redirected to 0x4a25610 (_vgnU_ifunc_wrapper)
--12638-- REDIR: 0x53d2650 (__GI_strrchr) redirected to 0x4c2ba80 (__GI_strrchr)
--12638-- REDIR: 0x53d0b30 (strlen) redirected to 0x4a25610 (_vgnU_ifunc_wrapper)
--12638-- REDIR: 0x54a93d0 (__strlen_sse2_pminub) redirected to 0x4c2bfa0 (strlen)
--12638-- REDIR: 0x4ee7dd0 (operator new(unsigned long)) redirected to 0x4c2b160 (operator new(unsigned long))
--12638-- REDIR: 0x53d0b80 (__GI_strlen) redirected to 0x4c2bfc0 (__GI_strlen)
==12638== Invalid read of size 8
==12638== at 0x53D6C4F: __GI___strncasecmp_l (strcmp.S:213)
==12638== by 0x538900A: ____strtod_l_internal (strtod_l.c:566)
==12638== by 0x40088B: main (main.cpp:9)
==12638== Address 0x59ff058 is 24 bytes inside a block of size 26 alloc'd
==12638== at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==12638== by 0x4ED0A88: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==12638== by 0x4ED2494: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==12638== by 0x4ED25E2: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==12638== by 0x40085C: main (main.cpp:7)
==12638==
==12638== Invalid read of size 8
==12638== at 0x53D6C57: __GI___strncasecmp_l (strcmp.S:215)
==12638== by 0x538900A: ____strtod_l_internal (strtod_l.c:566)
==12638== by 0x40088B: main (main.cpp:9)
==12638== Address 0x59ff060 is 6 bytes after a block of size 26 alloc'd
==12638== at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==12638== by 0x4ED0A88: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==12638== by 0x4ED2494: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==12638== by 0x4ED25E2: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==12638== by 0x40085C: main (main.cpp:7)
==12638==
--12638-- REDIR: 0x4ee6150 (operator delete(void*)) redirected to 0x4c2a450 (operator delete(void*))
--12638-- REDIR: 0x53cb010 (free) redirected to 0x4c2a7c0 (free)
==12638==
==12638== HEAP SUMMARY:
==12638== in use at exit: 0 bytes in 0 blocks
==12638== total heap usage: 1 allocs, 1 frees, 26 bytes allocated
==12638==
==12638== All heap blocks were freed -- no leaks are possible
==12638==
==12638== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 2 from 2)
==12638==
==12638== 1 errors in context 1 of 2:
==12638== Invalid read of size 8
==12638== at 0x53D6C57: __GI___strncasecmp_l (strcmp.S:215)
==12638== by 0x538900A: ____strtod_l_internal (strtod_l.c:566)
==12638== by 0x40088B: main (main.cpp:9)
==12638== Address 0x59ff060 is 6 bytes after a block of size 26 alloc'd
==12638== at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==12638== by 0x4ED0A88: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==12638== by 0x4ED2494: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==12638== by 0x4ED25E2: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==12638== by 0x40085C: main (main.cpp:7)
==12638==
==12638==
==12638== 1 errors in context 2 of 2:
==12638== Invalid read of size 8
==12638== at 0x53D6C4F: __GI___strncasecmp_l (strcmp.S:213)
==12638== by 0x538900A: ____strtod_l_internal (strtod_l.c:566)
==12638== by 0x40088B: main (main.cpp:9)
==12638== Address 0x59ff058 is 24 bytes inside a block of size 26 alloc'd
==12638== at 0x4C2B1C7: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==12638== by 0x4ED0A88: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==12638== by 0x4ED2494: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==12638== by 0x4ED25E2: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16)
==12638== by 0x40085C: main (main.cpp:7)
==12638==
--12638--
--12638-- used_suppression: 2 dl-hack3-cond-1
==12638==
==12638== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 2 from 2)
是否有错误或我遗漏了什么?
最佳答案
我认为您的代码中没有错误。我认为这是 Valgrind 中的错误。
Valgrind 有自己的函数实现,例如 strchr
、strcasecmp
等,它会重定向您的应用程序使用,而不是 libgcc 中的版本。 Valgrind 中的评论 mc_replace_strmem.c
文件说明:
/* ---------------------------------------------------------------------
We have our own versions of these functions for two reasons:
(a) it allows us to do overlap checking
(b) some of the normal versions are hyper-optimised, which fools
Memcheck and cause spurious value warnings. Our versions are
simpler.
Note that overenthusiastic use of PLT bypassing by the glibc people also
means that we need to patch multiple versions of some of the functions to
our own implementations.
THEY RUN ON THE SIMD CPU!
------------------------------------------------------------------ */
您可以在日志的 REDIR
输出中看到这些重定向。
从 mc_replace_strmem.c
的检查来看,Valgrind 似乎没有替换 __GI___strncasecmp_l
,您的日志表明它正在被调用。我建议 filing a bug针对 Valgrind 并将您的程序作为测试用例。
关于c++ - Valgrind: "Invalid read"与 c_str 和 strtod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10572715/
我有一个阅读器,其中包含有关 51*51 网格的信息,其中网格上的每个点都由 f32 表示。 .我想将这些数据读入一个向量,以便我可以轻松处理它: pub fn from_reader(reader:
我重新启动了 SQL Server 2005 并运行了统计 IO 的查询。 我得到了这些结果:表“xxx”。扫描计数 1,逻辑读取 789,物理读取 3,预读读取 794,... 预读读取数是读取并放
在 CLHS 中,我为 :read-only x 读到:“当 x 为真时,这指定不能更改此插槽;它将始终包含构造时提供的值。” 我可以做到这一点(CCL、SBCL): CL-USER> (defstr
让我们考虑一下这句话(Total Store Ordering): reads are ordered before reads, writes before writes, and reads be
我正在开发一个 SMTP 库,它使用缓冲读取器通过网络读取行。 我想要一种安全的方式来从网络读取数据,而不依赖于 Rust 内部机制来确保代码按预期工作。具体来说,我想知道 Read trait 是否
我不清楚所有这些读取字符串函数之间的关系。嗯,很明显clojure.core/read-string可以读取 pr[n] 输出的任何序列化字符串甚至 print-dup .也很清楚clojure.ed
所以我做了这个功能,就像倒计时一样。我想在倒计时减少时读取命令。我的大问题是让 read() 在倒计时减少时等待输入。如您所见,我尝试使用 select() 但在第一个 printf 之后("time
这是我vue3+echart5 遇到的报错:Cannot read properties of undefined (reading ‘type‘) 这个问题需要搞清楚两个关键方法: toRaw: 作
下图中,左边是C代码,右边是未优化的LLVM IR形式。 The Figure 在 IR 上运行 MemoryDependenceAnalysis 可查找内存依赖性。原始代码及其 IR 等效代码中
这个问题在这里已经有了答案: Read values into a shell variable from a pipe (17 个答案) 关闭 3 年前。 我一直在尝试像这样从程序输出中读取环境变
当我输入相同的整数时,如何将整数转换为与使用 read(0,buff,nbytes) 获得的缓冲区相同的值/编码字符?我正在尝试编写类似 read() 的东西,但用整数数据代替读取到缓冲区的文件描述符
This question already has answers here: Closed 2 years ago. Read input in bash inside a while loop (
我正在尝试处理来自 MySQL 数据库的一些数据(主要是 double 值)。我收到此错误消息: Invalid attempt to access a field before calling Re
我正在制作一个简单的 TCP/IP 套接字应用 这样做有什么不同: DataInputStream in = new DataInputStream(clientSocket.getInputStre
我操作API服务器。 手机APP访问API服务器时,有时会出现该异常。 我尝试在测试服务器上进行测试,但无法重现。(我改变了apache和tomcat的连接时间。) 有什么问题?? 我该如何解决这个问
我在段落末尾使用“阅读更多”只是为了提醒像P.T.O一样的用户 为什么会有问题? 最佳答案 您必须明白,许多屏幕阅读器用户不会等到整个页面都读给他们听。他们使用键盘快捷键在页面中导航。 JAWS(可以
我已将我的 Angular 应用程序从 12 版本升级到 13 版本。我在单元测试运行期间开始遇到此错误。 Chrome Headless 94.0.4606.61 (Windows 10) AppC
我正在尝试为以下组件编写一个。我正在使用 queryParams 然后使用 switchmap 来调用服务。这是 url 的样子: http://localhost:4200/test-fee/det
我的代码有什么问题? Uncaught TypeError: Cannot read properties of undefined (reading 'remove') 和 Uncaught Typ
我在我的 React 应用程序中遇到了这个问题。 类型错误:无法读取未定义的属性(读取“requestContent”) 我在我的应用程序中使用 commercejs。代码指向 isEmpty=!ca
我是一名优秀的程序员,十分优秀!