让我们考虑一下这个简单的测试程序:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char buf[256];
int i;
strcpy(buf,"Hello world!");
i = strlen(buf);
printf("Length of string is %d.\n",i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在使用英特尔c ++编译器进行编译并打开优化(O3)时,我从valgrind得到以下错误:
==8727== Conditional jump or move depends on uninitialised value(s)
==8727== at 0x4009EF: main (strtest.cpp:11)
==8727== Use of uninitialised value of size 8
==8727== at 0x4FC61ED: _itoa_word (in /lib64/libc-2.4.so)
==8727== by 0x4FC9317: vfprintf (in /lib64/libc-2.4.so)
==8727== by 0x4FD02A9: printf (in /lib64/libc-2.4.so)
==8727== by 0x400A09: main (strtest.cpp:13)
==8727== Conditional jump or move …Run Code Online (Sandbox Code Playgroud)