When I run valgrind on my software it gives a condition jump or move depends on uninitialised value(s) error. The output from valgrind is as follows:
==17787== Conditional jump or move depends on uninitialised value(s)
==17787== at 0x402688: directory_findname (directory.c:36)
==17787== by 0x402750: directory_findname (directory.c:41)
==17787== by 0x402038: pathname_lookup (pathname.c:28)
==17787== by 0x402239: chksumfile_bypathname (chksumfile.c:55)
==17787== by 0x4011F9: DumpPathAndChildren (diskimageaccess.c:143)
==17787== by 0x4014E9: DumpPathAndChildren (diskimageaccess.c:182)
==17787== by 0x4014E9: DumpPathAndChildren (diskimageaccess.c:182)
==17787== by 0x40155D: DumpPathnameChecksum (diskimageaccess.c:193)
==17787== by 0x400F39: main (diskimageaccess.c:80)
==17787== Uninitialised value was created by a stack allocation
==17787== at 0x402576: directory_findname (directory.c:27)
==17787==
==17787== Conditional jump or move depends on uninitialised value(s)
==17787== at 0x4C2F1BC: strcmp (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==17787== by 0x4026B6: directory_findname (directory.c:37)
==17787== by 0x402750: directory_findname (directory.c:41)
==17787== by 0x402038: pathname_lookup (pathname.c:28)
==17787== by 0x402239: chksumfile_bypathname (chksumfile.c:55)
==17787== by 0x4011F9: DumpPathAndChildren (diskimageaccess.c:143)
==17787== by 0x4014E9: DumpPathAndChildren (diskimageaccess.c:182)
==17787== by 0x4014E9: DumpPathAndChildren (diskimageaccess.c:182)
==17787== by 0x40155D: DumpPathnameChecksum (diskimageaccess.c:193)
==17787== by 0x400F39: main (diskimageaccess.c:80)
==17787== Uninitialised value was created by a stack allocation
==17787== at 0x402576: directory_findname (directory.c:27)
==17787==
==17787== Conditional jump or move depends on uninitialised value(s)
==17787== at 0x4026B9: directory_findname (directory.c:37)
==17787== by 0x402750: directory_findname (directory.c:41)
==17787== by 0x402038: pathname_lookup (pathname.c:28)
==17787== by 0x402239: chksumfile_bypathname (chksumfile.c:55)
==17787== by 0x4011F9: DumpPathAndChildren (diskimageaccess.c:143)
==17787== by 0x4014E9: DumpPathAndChildren (diskimageaccess.c:182)
==17787== by 0x4014E9: DumpPathAndChildren (diskimageaccess.c:182)
==17787== by 0x40155D: DumpPathnameChecksum (diskimageaccess.c:193)
==17787== by 0x400F39: main (diskimageaccess.c:80)
==17787== Uninitialised value was created by a stack allocation
==17787== at 0x402576: directory_findname (directory.c:27)
==17787==
The code itself runs fine and gives me all the output I expect. Also valgrind only gives me this error on a select few inputs to my software. On the majority of the inputs I get no errors what-so-ever. The 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; i < direntPerBlock; i++){
if(buf[i].d_name[0] != '\0'){
if(strcmp(buf[i].d_name, dirName)==0){
if(strlen(name) == strlen(dirName))
return buf[i].d_inumber;
else
return directory_findname(fs, name+(strlen(dirName)+1)*sizeof(char), buf[i].d_inumber, dirEnt);
}
}
}
}
}
Where line 27, the supposed uninitalised value, is struct direntv6 buf[direntPerBlock];. And line 36 and 37 are
if(buf[i].d_name[0] != '\0'){
if(strcmp(buf[i].d_name, dirName)==0){
The function, diskimg_readsector(...) takes buf and fills it with the appropriate data. The function is implemented as:
int diskimg_readsector(int fd, int sectorNum, void *buf) {
if (lseek(fd, sectorNum * DISKIMG_SECTOR_SIZE, SEEK_SET) == (off_t) -1) return -1;
return read(fd, buf, DISKIMG_SECTOR_SIZE);
}
Any clues as to why valgrind is occasionally giving me this issue would be greatly appreciated.
edit:
`dirName' is found as:
// extract the name of the current root directory
char dirName[sizeof(dirEnt->d_name)];
int i = 0;
while(name[i] != '/' && name[i] != '\0'){
dirName[i] = name[i];
i++;
}
dirName[i] = '\0';
Edit**:
Issues are gone. I just added:
struct direntv6 buf[direntPerBlock];
memset(buf, 0, sizeof(buf));