valgrind - 地址是大小为16的块之前的8个字节

时间:2015-04-21 15:37:16

标签: c valgrind

我遇到了“消化”valgrind输出的问题。这是一个片段:

==15145== Invalid write of size 8
==15145==    at 0x40168E: split_node_at_letter (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x4018E7: pass_word_further (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x401A35: insert_word (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x401BD5: main (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==  Address 0x52237d8 is 8 bytes before a block of size 16 alloc'd
==15145==    at 0x4C29BCF: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==15145==    by 0x401063: add_to_trie_word_list (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x40173B: pass_word_further (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x40183D: pass_word_further (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x401906: pass_word_further (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x401A35: insert_word (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x401BD5: main (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)

地址是“分配大小为16的块之前的8个字节”是什么意思?

1 个答案:

答案 0 :(得分:18)

这意味着Valgrind检测到您为程序分配的一块内存(通过malloc()或类似内容),并尝试访问之前8字节的地址。

简而言之,这是一个数组超出界限错误,您尝试访问数据之前实际数组数据

incorrect write表示您为此数据段中的某些内容指定值。例如,执行word.length = 4

以下是valgrind的输出细分:

==15145== Invalid write of size 8
             //This is the function doing the incorrect accessing
==15145==    at 0x40168E: split_node_at_letter (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
           [... stack trace ...]

                //This is the address you are trying to access
==15145==  Address 0x52237d8 is 8 bytes before a block of size 16 alloc'd
==15145==    at 0x4C29BCF: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)

             //This is the function that alloc'd the 'block of size 16' (calling malloc as shown in the above line)
==15145==    by 0x401063: add_to_trie_word_list (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)

           [... stack trace ...]