Valgrind甚至在一个简单的“Hello World"程序(std :: cout)

时间:2015-06-07 10:55:25

标签: c++ std valgrind

我得到一些源自std::的valgrind错误。所以我将我的程序划分为非常简单的" Hello World"例如:

#include <iostream>
using namespace std;
int main(int argc, char *argv[]){
    cout << "Hello World!" << endl;  // (Line 8)
}

但我仍然收到以下错误:

==1311== Conditional jump or move depends on uninitialised value(s)
==1311==    at 0x1004E8C3F: _platform_memchr$VARIANT$Haswell (in /usr/lib/system/libsystem_platform.dylib)
==1311==    by 0x1002DCB96: __sfvwrite (in /usr/lib/system/libsystem_c.dylib)
==1311==    by 0x1002DD0AA: fwrite (in /usr/lib/system/libsystem_c.dylib)
==1311==    by 0x100029D29: std::__1::__stdoutbuf<char>::overflow(int) (in /usr/lib/libc++.1.dylib)
==1311==    by 0x10001F91C: std::__1::basic_streambuf<char, std::__1::char_traits<char> >::xsputn(char const*, long) (in /usr/lib/libc++.1.dylib)
==1311==    by 0x100001C88: std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) (streambuf:360)
==1311==    by 0x1000016A6: std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) (ostream:743)
==1311==    by 0x1000012C3: std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) (ostream:882)
==1311==    by 0x100001257: main (main.cpp:8)
==1311==  Uninitialised value was created by a stack allocation
==1311==    at 0x100029CD8: std::__1::__stdoutbuf<char>::overflow(int) (in /usr/lib/libc++.1.dylib)

编译和运行valgrind的命令(在OSX Yosemite上):

g++ -o main main.cpp --std=c++0x -O0 -g
valgrind --log-file=vg1.txt --leak-check=full --track-origins=yes ./main

我不确定如何处理此错误:

  1. 我想这不是我的错。但是这些库的配置可能有问题吗?

  2. 我是否需要担心错误?如果没有,是否有办法过滤此类错误?

0 个答案:

没有答案