odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.17k stars 550 forks source link

Error handling in read_dir on Windows #3705

Closed leidegre closed 1 month ago

leidegre commented 1 month ago

According to the documentation the return value of FindFirstFileW is INVALID_HANDLE_VALUE not nil.

https://github.com/odin-lang/Odin/blob/575e5a255b98727c304cf6a23fbb8f235c6eaa7f/core/os/dir_windows.odin#L89-L91

This be seen in other places in the Odin source tree. For example,

https://github.com/odin-lang/Odin/blob/575e5a255b98727c304cf6a23fbb8f235c6eaa7f/core/os/stat_windows.odin#L55-L59

It's unclear what the purpose of this find_handle != nil check, since find_handle is not written to within the loop body.

I'd consider inserting,

if find_handle == win32.INVALID_HANDLE_VALUE { 
    e = Errno(win32.GetLastError()) 
    return 
}

...between the call to FindFirstFileW and defer win32.FindClose(find_handle) and removing the find_handle != nil check.