-
Notifications
You must be signed in to change notification settings - Fork 31
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
Avoid program_invocation_name which is available only on Linux #242
Conversation
Boss/Main.cpp
Outdated
@@ -62,6 +64,7 @@ class Main::Impl { | |||
{ | |||
assert(argv.size() >= 1); | |||
argv0 = argv[0]; | |||
g_argv0 = argv0.c_str(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have a lifetime issue? If Main::Impl::argv0
is destroyed, then the global g_argv0
will become dangling. Maybe copy the string to a global buffer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that is dangerous. ChatGPT recommends a fix:
https://chatgpt.com/share/6712ab8d-b780-8008-8bba-468bea99aad2
Can you fix and re-push?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, used std::string
(which holds the data) rather than a bare pointer, pointing to some other place that can be destroyed too early.
fbcde82
to
2442b30
Compare
I found a problem w/ the unit tests; they don't set the g_argv0 var on startup. Normally they don't have unhandled exceptions, but when developing they do and are very useful. I have a patch to use the built-ins as a fallback. I'll try to push it here ... |
@vasild could you make sure that compiles with FreeBSD? |
`program_invocation_name` is defined by the system headers only on Linux, or at least it is not available on FreeBSD. Introduce own global variable that contains the program name. If it is unset then use `getprogname()` or `program_invocation_name`. Co-authored-by: Ken Sedgwick <[email protected]>
1016acf
to
f545cbf
Compare
Yes, it compiles and I squashed the two commits and made some further changes:
|
program_invocation_name
is defined by the system headers only on Linux, or at least it is not available on FreeBSD.Thus, maintain own global variable that contains the program name.