Skip to content

Conversation

@ysoftware
Copy link
Contributor

Following code leads to segfault

int main(int argc, char **argv) {
    Nob_File_Paths entries = {0};
    if (!nob_read_entire_dir("", &entries)) return 1;
    return 0;
}

Reason is incorrect check after opendir

dir->nob__private.posix_dir = opendir(dir_path);
if (dir == NULL) { ... return false; }

Must check the freshly returned value

if (dir->nob__private.posix_dir == NULL)

@ysoftware ysoftware changed the title Check correct value after opendir Segfault: Check correct value after opendir Jan 30, 2026
@ysoftware
Copy link
Contributor Author

In the test that I added, I validated that with empty path nob_read_entire_dir will return false, but it seems to get triggered on Windows and fail the test.

It seems that on Windows passing empty string results in us searching in the root directory.

char *buffer = nob_temp_sprintf("%s\\*", dir_path);
results in \*
which maps to C:\* in my case.

I think at this point it must be decided, which behavior is more correct.

@ysoftware ysoftware changed the title Segfault: Check correct value after opendir nob_read_entire_dir with empty path string: segfault and different in behavior on Windows Feb 2, 2026
@ysoftware ysoftware changed the title nob_read_entire_dir with empty path string: segfault and different in behavior on Windows nob_read_entire_dir with empty path string: segfault and different behavior on Windows Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant