Terminate string *pszExePath after readlink and before passing to operator <<.
ssize_t readlink(const char *pathname, char *buf, size_t bufsiz)does not append a null byte tobuf.- Operator
<<expects a null-terminated string.
Terminate string *pszExePath after readlink and before passing to operator <<.
ssize_t readlink(const char *pathname, char *buf, size_t bufsiz) does not append a null byte to buf.<< expects a null-terminated string.Doesn't the memset to all zeros before the readlink ensures that it will be null byte terminated?
@jonasschnelli Yes, you're correct but the current memset method seems a bit overkill for the task at hand. Instead of prematurely setting 1025 bytes to zero my suggestion is to set only one byte to zero when needed :-)
In addition to being more efficient and less surprising, this has the added benefit of making some static analyzers happy - I've seen at least one static analyzer getting confused by the current "indirect" string termination logic via memset used here.
IMO the PR title should be reworded - we already take care of NUL-terminating, just in a different way. This does not fix a potential bug or edge case as is implied.
the current memset method seems a bit overkill for the task at hand.
True in general, although this is not a performance sensitive place. Not sure this change is worth it.
PR title and commit message reworded :-)
utACK 3a4401a This is obviously correct, but I suggest focusing on actual problems and issues in future PRs instead of "this looks better".
Postumous utACK, though feels like needless code churn, agree with @laanwj it just creates more review burden/time.