关于C#:valgrind-地址是在分配大小为16的块之前的8个字节

valgrind - address is 8 bytes before a block of size 16 alloc'd

我在"消化" valgrind输出时遇到问题。这是一个片段:

1
2
3
4
5
6
7
8
9
10
11
12
13
==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个字节"是什么意思?


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

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

incorrect write表示您为该数据段中的某物分配了一个值。例如做word.length = 4

以下是valgrind的输出明细:

1
2
3
4
5
6
7
8
9
10
11
12
13
==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 ...]