c - Valgrind :: Conditional jump or move depends on uninitialised value(s) -
when run valgrind on software gives status jump or move depends on uninitialised value(s) error. output valgrind follows:
==17787== conditional jump or move depends on uninitialised value(s) ==17787== @ 0x402688: directory_findname (directory.c:36) ==17787== 0x402750: directory_findname (directory.c:41) ==17787== 0x402038: pathname_lookup (pathname.c:28) ==17787== 0x402239: chksumfile_bypathname (chksumfile.c:55) ==17787== 0x4011f9: dumppathandchildren (diskimageaccess.c:143) ==17787== 0x4014e9: dumppathandchildren (diskimageaccess.c:182) ==17787== 0x4014e9: dumppathandchildren (diskimageaccess.c:182) ==17787== 0x40155d: dumppathnamechecksum (diskimageaccess.c:193) ==17787== 0x400f39: main (diskimageaccess.c:80) ==17787== uninitialised value created stack allocation ==17787== @ 0x402576: directory_findname (directory.c:27) ==17787== ==17787== conditional jump or move depends on uninitialised value(s) ==17787== @ 0x4c2f1bc: strcmp (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==17787== 0x4026b6: directory_findname (directory.c:37) ==17787== 0x402750: directory_findname (directory.c:41) ==17787== 0x402038: pathname_lookup (pathname.c:28) ==17787== 0x402239: chksumfile_bypathname (chksumfile.c:55) ==17787== 0x4011f9: dumppathandchildren (diskimageaccess.c:143) ==17787== 0x4014e9: dumppathandchildren (diskimageaccess.c:182) ==17787== 0x4014e9: dumppathandchildren (diskimageaccess.c:182) ==17787== 0x40155d: dumppathnamechecksum (diskimageaccess.c:193) ==17787== 0x400f39: main (diskimageaccess.c:80) ==17787== uninitialised value created stack allocation ==17787== @ 0x402576: directory_findname (directory.c:27) ==17787== ==17787== conditional jump or move depends on uninitialised value(s) ==17787== @ 0x4026b9: directory_findname (directory.c:37) ==17787== 0x402750: directory_findname (directory.c:41) ==17787== 0x402038: pathname_lookup (pathname.c:28) ==17787== 0x402239: chksumfile_bypathname (chksumfile.c:55) ==17787== 0x4011f9: dumppathandchildren (diskimageaccess.c:143) ==17787== 0x4014e9: dumppathandchildren (diskimageaccess.c:182) ==17787== 0x4014e9: dumppathandchildren (diskimageaccess.c:182) ==17787== 0x40155d: dumppathnamechecksum (diskimageaccess.c:193) ==17787== 0x400f39: main (diskimageaccess.c:80) ==17787== uninitialised value created stack allocation ==17787== @ 0x402576: directory_findname (directory.c:27) ==17787==
the code runs fine , gives me output expect. valgrind gives me error on select few inputs software. on bulk of inputs no errors what-so-ever. code section in question is:
const int direntperblock = diskimg_sector_size/sizeof(dirent); struct direntv6 buf[direntperblock]; int inodesize = inode_getsize(&in); int ttlblocknum = inode_getsize(&in)/diskimg_sector_size + 1; int j; for(j = 0; j < ttlblocknum; j++){ if(diskimg_readsector(fs->dfd, inode_indexlookup(fs, &in, j), buf)){ for(i = 0; < direntperblock; i++){ if(buf[i].d_name[0] != '\0'){ if(strcmp(buf[i].d_name, dirname)==0){ if(strlen(name) == strlen(dirname)) homecoming buf[i].d_inumber; else homecoming directory_findname(fs, name+(strlen(dirname)+1)*sizeof(char), buf[i].d_inumber, dirent); } } } } }
where line 27, supposed uninitalised value, struct direntv6 buf[direntperblock];
. , line 36 , 37
if(buf[i].d_name[0] != '\0'){ if(strcmp(buf[i].d_name, dirname)==0){
the function, diskimg_readsector(...)
takes buf
, fills appropriate data. function implemented as:
int diskimg_readsector(int fd, int sectornum, void *buf) { if (lseek(fd, sectornum * diskimg_sector_size, seek_set) == (off_t) -1) homecoming -1; homecoming read(fd, buf, diskimg_sector_size); }
any clues why valgrind giving me issue appreciated.
edit:
`dirname' found as:
// extract name of current root directory char dirname[sizeof(dirent->d_name)]; int = 0; while(name[i] != '/' && name[i] != '\0'){ dirname[i] = name[i]; i++; } dirname[i] = '\0';
edit**:
issues gone. added:
struct direntv6 buf[direntperblock]; memset(buf, 0, sizeof(buf));
try initializing info this:
struct direntv6 buf[direntperblock] = {0};
this way never uninitialized, , unset strings within should appear empty instead of having garbage inside. guess issue might how you're using diskimg_readsector, don't see code can't sure.
c valgrind
No comments:
Post a Comment