stl图简单插入内存问题
不清楚发生了什么:我有以下两行代码适用于代码的其他部分:
map<short,string> params;
params.insert( std::pair<short, string>(5, string("ee")) );
当我将其放入例程中时,我从一开始就收到此 valgring 错误,并且程序崩溃了。不完全清楚为什么它最终出现在字符串析构函数中。我的二进制文件可能有问题,但我有点困惑为什么它会在开始时发生以及为什么它在字符串析构函数中?下面的内容是否意味着我必须在其他地方查找错误?
==2052== Conditional jump or move depends on uninitialised value(s)
==2052== at 0x6073EC2: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib/libstdc++.so.6.0.13)
==2052== by 0x42428B: std::pair<short const, std::string>::~pair() (stl_pair.h:68)
==2052== by 0x4B99FB: NLGSearch::Search::Calc() (Search.cpp:409)
请注意,如果我使用 map
,它就会通过 谢谢。
-------------------------------------------------- - 编辑
这在方法的开头使用。我想我已经找到了问题的答案,我必须看看代码中的其他地方......
lef@dxml:~$ more /etc/issue
Debian GNU/Linux 6.0 \n \l
lef@dxml:~$ g++ -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)
Not clear what is going on: I have the 2 following lines that works in other parts of the code:
map<short,string> params;
params.insert( std::pair<short, string>(5, string("ee")) );
when I put it into my routine, I get this valgring error right at the beginning, and the program crashes. Not totally clear why it ends up in the string destructor. I may have something wrong with my binary but I am a little confused why it happens right at the beginning and why is it in the string destructor ? Does what is herebelow MEANS that I must look for the error somewhere else ?
==2052== Conditional jump or move depends on uninitialised value(s)
==2052== at 0x6073EC2: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib/libstdc++.so.6.0.13)
==2052== by 0x42428B: std::pair<short const, std::string>::~pair() (stl_pair.h:68)
==2052== by 0x4B99FB: NLGSearch::Search::Calc() (Search.cpp:409)
Note that it goes through if I use map<short,short>
Thank you.
--------------------------------------------------- EDIT
This is used right at the beginning of a method. I guess I have the answer to my question, I have to look at somewhere else in my code...
lef@dxml:~$ more /etc/issue
Debian GNU/Linux 6.0 \n \l
lef@dxml:~$ g++ -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我有用。该程序与您正在测试的程序有何不同?
Ubuntu 10.04.3 LTS 上的 gcc 4.4.3。 valgrind 没有抱怨。
It works for me. How does this program differ from the one you are testing?
gcc 4.4.3 on Ubuntu 10.04.3 LTS. No complaints from valgrind.