0

由于某种原因在机器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在 machine 中运行相同的 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
}
4

0 回答 0