(I asked multiple questions to the implementation of the huffman code here, if I ask too many questions please tell me and I ll stop. Any tips on how to learn to find those mistakes myself are appreciated, I spent hours and couldn t find the problem.)
I try to implement huffman code in C. Right now I can successfully read a file, generate the tree and write the compressed data to the output file.
However if my input file is random generated (using something like dd if=/dev/random of=foo bs=100 count=1
) the program aborts with a segfault. The weird thing is, this only happens on some random files, some others work.
I m confident that the null character isn t the problem because I don t use any str*() functions (I know printTree()
does rely on
Huffman 代码安全格在随机输入而不是文本输入上
原标题:Huffman code segfaults on random input but not on text input