Here's the following code that I compile on my Windows PC:
#include <windows.h>
int main() {
WIN32_FIND_DATA file = {0, {0, 0}, {0, 0}, {0, 0}, 0, 0, 0, 0, "", ""};
HANDLE file_handle = INVALID_HANDLE_VALUE;
file_handle = FindFirstFile("C:\\*", &file);
if (file_handle != INVALID_HANDLE_VALUE)
FindClose(file_handle);
return 0;
}
When I run it through Dr. Memory, I get the following error:
Error #1: UNINITIALIZED READ: reading 0x0000004f792ff3f4-0x0000004f792ff3f8 4 byte(s) within 0x0000004f792ff3f0-0x0000004f792ff3f8
# 0 system call NtQueryDirectoryFileEx parameter value #6
# 1 KERNELBASE.dll!FindFirstFileExW
# 2 KERNELBASE.dll!FindFirstFileW
# 3 main
I spent the whole day trying to figure out where the uninitialized read is, but I can't for the life of me figure it out. I thought this was maybe some sort of false positive (like this one) because I was compiling the code with GCC/MinGW, but it also happens with MSVC/Visual Studio.
As far as I understand it, file and file_handle are initialized, but I guess I'm missing something...
EDIT: "Some programmer dude" suggested that my issue might being related to me using narrow-character strings whereas wide-character strings are required. I tried the following code (which compiles fine with MSVC/Visual Studio, but not GCC/MinGW), but I get the same error with Dr. Memory:
#include <windows.h>
int main() {
WIN32_FIND_DATA file = {0, {0, 0}, {0, 0}, {0, 0}, 0, 0, 0, 0, L"", L""};
HANDLE file_handle = INVALID_HANDLE_VALUE;
file_handle = FindFirstFile(L"C:\\*", &file);
if (file_handle != INVALID_HANDLE_VALUE)
FindClose(file_handle);
return 0;
}