Valgrind を使用して、メモリの一部に無効な書き込みを行った場所を見つけようとしています。どの関数にもそのような問題があることを示していますが、どの行にはありません。関数はかなり小さいですが、Valgrind に行番号を表示したいと思います。Valgrind のいくつかの出力でこれを見たことがありますが、現在は表示されていません。
出力は次のとおりです。
niklas@emerald:~/Arbeitsfläche/spyr/bin/Debug$ valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./spyr
[...]
==4404== Invalid write of size 4
==4404== at 0x8048849: sp_ParticleBuffer_init (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404== by 0x8048BFC: sp_ParticleSystem_createParticle (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404== by 0x8048691: main (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404== Address 0x422a0a0 is 4 bytes after a block of size 4 alloc'd
==4404== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==4404== by 0x8048BC1: sp_ParticleSystem_createParticle (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404== by 0x8048691: main (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404==
==4404== Invalid write of size 4
==4404== at 0x8048865: sp_ParticleBuffer_init (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404== by 0x8048BFC: sp_ParticleSystem_createParticle (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404== by 0x8048691: main (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404== Address 0x422a09c is 0 bytes after a block of size 4 alloc'd
==4404== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==4404== by 0x8048BC1: sp_ParticleSystem_createParticle (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404== by 0x8048691: main (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
[...]
ファイル名の後ろの二重コロンの後に行番号が表示される出力を見ました。つまり/home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr:23
、または同様の。
どうすればこれを有効にできますか?
参考までに、これがsp_ParticleBuffer_init
関数です。
int sp_ParticleBuffer_init(sp_ParticleBuffer* buffer, sp_Uint32 buffer_size, int init_zero) {
size_t size = sizeof(sp_Particle) * buffer_size;
buffer->next = null;
buffer->array = (sp_Particle*) malloc(size);
buffer->alive_count = 0;
if (!buffer->array) return SPYR_ALLOCFAILED;
if (init_zero) memset((void*) buffer->array, 0, size);
return SPYR_NOERR;
}