I wrote a program in C that prints all of the files in a folder using dirent.h (in windows) and it is working fine, but when I check the .exe file with dr.memory I get lots of UNINITIALIZED READ errors. All dr.memory results: https://pastebin.com/kiiGeg3c

I checked the dr.memory page for Uninitialized Read (https://drmemory.org/docs/page_uninit.html) but I didn't understand why it happened in my code.

void printFolder(char* folderPath)
{
    DIR* d = 0;
    struct dirent* file = 0;

    d = opendir(folderPath);

    if (!d)
    {
        printf("Folder not found!\n");

        return;
    }

    while ((file = readdir(d)))
    {
        if (strcmp(file->d_name, ".") && strcmp(file->d_name, ".."))
        {
            printf("file: %s\n", file->d_name);
        }
    }

    closedir(d);
}


int main(void)
{
    char folderPath[] = "C:\\folder";


    printFolder(folderPath);

    getchar();
    return 0;
}
0

There are 0 best solutions below