-
Notifications
You must be signed in to change notification settings - Fork 152
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
Replace uses of strncpy()
with strlcpy()
#266
Comments
IMHO using |
Sorry, @jens-maus, but Also, implementations of |
Consider the code in src/cmd/ksh93/sh/io.c, lines 1870 and 1871:
Suppose that we want to use strncpy(). We may calculate the size so we don't write too many NULs,
but then we can change |
That is a good point @kernigh. But if performance is the issue then the example you linked to doesn't need to use Too, at the end of the day, even if we all agree that |
I've been thinking about this some more. I reread the article I linked to in my initial comment as well as every document it linked to. As a grey beard who prides myself on my knowledge of CS trivia I was surprised to realize I did not remember that The reason for that behavior is that So I now agree that the entire project should be uniformly using It also turns out that even though GNU libc does not provide |
strlcpy()
with strncpy()
strncpy()
with strlcpy()
@krader1961 Great that you finally came to the same conclusion like me at the beginning of the year ;-). Looking forward to see strncpy() dying in ast. |
This small addition to the man page adds a description for the -l (login shell) option. It was mentioned on the old mailing list: https://www.mail-archive.com/ast-users@lists.research.att.com/msg00299.html
A recent change broke building ksh on macOS because on macOS
strlcpy()
andstrlcat()
are macros. And those macros break the declarations in src/lib/libast/include/ast_sys.h. That problem has been worked around, imperfectly, by moving the#include <string.h>
preprocessor directive to the end of the file. Long term we should replaces uses ofstrlcpy()
withstrncpy()
(there are no uses ofstrlcat()
AFAICT) then remove those functions from the libast code base.See https://lwn.net/Articles/507319/ for some excellent background on why these functions are not part of GNU libc.
The text was updated successfully, but these errors were encountered: