After writing thousands of lines of code, I use valgrind and am horrified to see the number of errors. I used to use GDB. Most of my errors are related to string functions. I am sending a piece. I understand that an error occurs because strlen does not account for the final NULL, while strcpy adds it. How serious is this? Do I really need to fix them? I can fix this, but am worried if this can lead to more errors, since my code did not remember it when I was in it.
Will strcpy copy trailing NULL even if no space has been reserved for it?
t.write_length = (strlen("NA\n"); t.data = malloc(strlen("NA\n"); strcpy(t.data,"NA\n");
Valgrind:
==3287== Invalid write of size 1 ==3287== at 0x400764E: memcpy (mc_replace_strmem.c:497) ==3287== by 0x804A714: log_txn_commit (Log_manager.c:118) ==3287== by 0x8049D3C: on_txn_commit (TxFS_manager.c:85) ==3287== by 0x804939E: handler (Reader.c:139) ==3287== by 0xBF5F18: start_thread (in /lib/libpthread-2.12.90.so) ==3287== by 0xB37A2D: clone (in /lib/libc-2.12.90.so) ==3287== Address 0x403282b is 0 bytes after a block of size 3 alloc'd ==3287== at 0x4005BDC: malloc (vg_replace_malloc.c:195) ==3287== by 0x804A6F5: log_txn_commit (Log_manager.c:117) ==3287== by 0x8049D3C: on_txn_commit (TxFS_manager.c:85) ==3287== by 0x804939E: handler (Reader.c:139) ==3287== by 0xBF5F18: start_thread (in /lib/libpthread-2.12.90.so) ==3287== by 0xB37A2D: clone (in /lib/libc-2.12.90.so)
source share