Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path_from_handle implementation is incorrect (redux) #63

Open
relapids opened this issue Dec 16, 2022 · 0 comments
Open

path_from_handle implementation is incorrect (redux) #63

relapids opened this issue Dec 16, 2022 · 0 comments

Comments

@relapids
Copy link

Previous issue: #57
PR which was intending to fix that issue: #59

@apolukhin I believe this fix is incorrect. Per the documentation from GetModuleFileNameW (emphasis mine):

If the function succeeds, the return value is the length of the string that is copied to the buffer, in characters, not including the terminating null character. If the buffer is too small to hold the module name, the string is truncated to nSize characters including the terminating null character, the function returns nSize, and the function sets the last error to ERROR_INSUFFICIENT_BUFFER.

The important thing to note here is that the returned size can be non-zero even in failure cases. This appears to not be handled any more, which is the entire purpose of that loop which grows the buffer on each iteration afaict.

Likely the original structure of the code was correct, but what it meant to do instead of calling GetLastError was this:
SetLastError(0);

apolukhin added a commit that referenced this issue Oct 20, 2023
Use boost::core::invoke_swap instead of deprecated boost::swap
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

No branches or pull requests

1 participant