Valgrind在多台机器上的不同输出

时间:2013-05-19 18:40:24

标签: c valgrind

在机器A出于某种原因,我得到了一堆:

==21855== Invalid read of size 4
==21855==    at 0x422A26F: ??? (in /lib/i686/cmov/libc-2.11.3.so)
==21855==    by 0x4216E2F: vsnprintf (in /lib/i686/cmov/libc-2.11.3.so)
==21855==    by 0x41FE421: snprintf (in /lib/i686/cmov/libc-2.11.3.so)
==21855==    by 0x804F95B: put_lines (lines.c:354)
==21855==    by 0x805076B: examine_lines (lines.c:658)
==21855==    by 0x80509D8: read_lines (lines.c:715)
==21855==    by 0x804EED0: main (app.c:564)
==21855==  Address 0x444230c is 12 bytes inside a block of size 13 alloc'd
==21855==    at 0x40255BC: malloc (vg_replace_malloc.c:270)
==21855==    by 0x804FF80: read_str (lines.c:464)
==21855==    by 0x80501A2: read_type (lines.c:522)
==21855==    by 0x8050663: examine_lines (lines.c:631)
==21855==    by 0x80509D8: read_lines (lines.c:715)
==21855==    by 0x804EED0: main (app.c:564)
==21855== 
==21855== Conditional jump or move depends on uninitialised value(s)
==21855==    at 0x422A27D: ??? (in /lib/i686/cmov/libc-2.11.3.so)
==21855==    by 0x804F9A8: put_lines (lines.c:364)
==21855==    by 0x805076B: examine_lines (lines.c:658)
==21855==    by 0x80509D8: read_lines (lines.c:715)
==21855==    by 0x804EED0: main (app.c:564)
==21855==  Uninitialised value was created by a stack allocation
==21855==    at 0x804F8F2: put_lines (lines.c:343)

在机器--leak-check=full中运行相同的valgrind命令(即使使用B),我没有收到任何错误

我在两台机器上使用相同的valgrind版 valgrind-3.8.1

当我运行其他程序时也会出现相同的行为,例如htop(同样的版本)。

valgrind --log-file="logfile" --tool=memcheck --leak-check=yes ./program

为什么这样开心呢?以及如何让valgrind在机器上保持一致?

更新

代码段:

void put_lines (char * name, char * date, char * month) {
    char main_str[2048]; 
    snprintf(main_str, sizeof (main_str), "%s-%s-%s", name, date, month);
    main_str[sizeof(main_str)-1] = 0;
    // more code
}

0 个答案:

没有答案