nob__walk_dir_opt_impl() tries to close zeroed handle for non directory entries

Open Beginner friendly
#266 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, cpp

Research direction

Start at nob__walk_dir_opt_impl() and follow its deferred call to nob_dir_entry_close(), then compare the Linux and Windows handle behavior described in the issue. The fix is done when walking non-directory entries no longer calls FindClose with a null handle or triggers the debugger, while directory walking continues normally.

Written by the indexing model from the issue text.

Description

The nob__walk_dir_opt_impl() function calls nob_dir_entry_close() in the defer, to close the current entry.
It also does this when the entry is not a directory, and therefore the directory handle is NULL.
On Linux, there is a check not to close NULL handles in the nob_dir_entry_close() function, as they are returned on erroneous open.
On Windows, on the other hand, the error handle is INVALID_HANDLE_VALUE, which is not checked anyway.
This results in calls to FindClose with a NULL handle. The result of the close function is not checked, so it continues normally in C.
But FindClose throws an exception, ending the program when used from C++, and more annoyingly triggers the debugger.

Dominant language
C++
Stars
3.3k
Forks
213
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tsoding/nob.h

All issues in tsoding/nob.h

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.