小编Mar*_* B.的帖子

简单C字符串函数上的Valgrind错误

让我们考虑一下这个简单的测试程序:

#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)

c string valgrind strlen

5
推荐指数
1
解决办法
3994
查看次数

标签 统计

c ×1

string ×1

strlen ×1

valgrind ×1