Giriş
Açıklaması şöyle.
Örnek
Elimizde şöyle bir kod olsun.
Açıklaması şöyle.
An Invalid read means that the memory location that the process was trying to read is outside of the memory addresses that are available to the process. size 8 means that the process was trying to read 8 bytes. On 64-bit platforms this could be a pointer, but also for example a long int.by ile başlayan satırdan itibaren hatanın nerede oluştuğu takip edilebilir. at ile başlayan satır hatanın tam yerini belirtir.
The last line of the error report says Address 0x38 is not stack'd, malloc'd or (recently) free'd, which means that the address that the process was trying to read 8 bytes from starts at 0x38. The line also says that the address is unavailable through stack space, heap space (malloc), or that it was recently a valid memory location.
Örnek
Şuna benzer bir çıktı alırız.
==6254== Invalid read of size 8
==6254== at 0x4008C0: main (readin-test.c:26)
==6254== Address 0x51fc2e0 is 0 bytes after a block of size 32 alloc'd
==6254== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6254== by 0x400835: main (readin-test.c:16)
Elimizde şöyle bir kod olsun.
FILE *file_pointer = fopen("humans.txt","r");
value = (char *) malloc(sizeof(char)); //burada 1 byte ayrılır
while( fscanf(file_pointer,"%s", value) != EOF ){
printf("Name: %s Size of name: %d",value,strlen(value));
}
Çıktı olarak şunu alırız.==22726== Invalid read of size 4
==22726== at 0x4EA21BD: __isoc99_fscanf (in /usr/lib64/libc-2.17.so)
==22726== by 0x400716: main (in /mnt//ogr/bxxxxx/a)
==22726== Address 0x0 is not stack'd, malloc'd or (recently) free'd
Hiç yorum yok:
Yorum Gönder