Skip to content

Use correct size in System::executable() on macOS#51

Merged
cwbaker merged 8 commits into
mainfrom
use-correct-size-in-macos-executable-function
May 26, 2026
Merged

Use correct size in System::executable() on macOS#51
cwbaker merged 8 commits into
mainfrom
use-correct-size-in-macos-executable-function

Conversation

@cwbaker

@cwbaker cwbaker commented May 26, 2026

Copy link
Copy Markdown
Owner

The call to _NSGetExecutablePath() only updates its size parameter if the size of the buffer passed in is too small. If the buffer is large enough it is simply filled and the size is left as is. This ends up returning a 4096 byte path on macOS even when the actual path is much shorter.

Fixed by leaving out the size parameter when constructing the returned string, let search for the null terminator determine the length.

cwbaker added 8 commits May 18, 2026 10:35
The Process::exit_code() call didn't differentiate between the process
exiting cleanly and returning an exit code and the process being
terminated by a signal or exception, e.g. segfaulting.

Fixed by differentiating between those two cases.  Also refactors exit
code retrieval to Process::wait() on Windows so that the killed by
signal and exception error is generated from Process::wait() on all
platforms.
The call to _NSGetExecutablePath() only updates it size parameter if
the size of the buffer passed in is too small.  If the buffer is large
enough it is simply filled and the size is left as is.  This always
returns a 4096 byte path on macOS.

Fixed by leaving out the size parameter when constructing the returned
string, let search for the null terminator determine the length.
@cwbaker cwbaker self-assigned this May 26, 2026
@cwbaker cwbaker merged commit 3cc6ebd into main May 26, 2026
3 checks passed
@cwbaker cwbaker deleted the use-correct-size-in-macos-executable-function branch May 26, 2026 08:41
@cwbaker cwbaker temporarily deployed to github-pages May 26, 2026 08:41 — with GitHub Pages Inactive
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