-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Couple of thoughts #14
Comments
Here is my safer strncpy, verbatim paste from my core lib. If you want to adapt or use any part of this, I release it under the public domain. The FTG_ATTRIBUTES() thing is a macro that generates a compiler warning if the truncation bit is ignored. Since it is a potential security risk if a string is truncated, I force a check. This is appropriate for my code. (I wish I could conditionally avoid this warning if *src was a literal).
|
I'll take your comments on restrict on board for sure - I'm not certain I like the assert myself personally (but I'm willing to spend some brain cycles on the thought before I commit one way or the other!) Thanks for the input though - all comments are good comments 😄 |
Just for clarity - I've decided against adding the assert, but I have done the restrict change. Thanks again for spending time reviewing my lib! |
Hey, nice library! I am looking for utf-8 C string parsing and this fits the bill. I had a couple of thoughts after reading the code.
For instance, a safer utf8ncpy function that guarantees a null terminator (possibly truncating last char) and returns boolean whether the string was truncated or not can be helpful, if certainly, not conformant with anything in string.h. Also, only filling one NULL character in at the end, because zeroing after termination is a waste of cycles. I have been using such a workhorse function for years.
Here is a snippet that lets you portably apply the restrict keyword if you're interested:
The text was updated successfully, but these errors were encountered: