C Null-Terminated Strings
Comments criticize C's null-terminated strings for performance issues, safety risks like buffer overflows, and inconsistent standard library functions, while discussing alternatives like length-prefixed strings and safer APIs such as strlcpy.
Activity Over Time
Top Contributors
Keywords
Sample Comments
C already has bad performance due to null terminated strings.
String handling is certainly one of C's main weaknesses
C style null terminated strings were a mistake. They are almost never the right answer. Even C itself should start transitioning to length prefixed strings instead.
I think BSD has strlcpy and strlcat for exactly this reason
E.g. null-terminated strings without length perform badly in some operations.
Wiki on subj:https://en.wikipedia.org/wiki/C_string_handling#Replacements
Many of the str functions in the C standard library assume a nul terminator.
Strings! The bane of C programming, and a big reason I prefer C++. :D
Nice. Is there a similar standalone C library for safe/sane string handling? (Please don't tell me to use C++.)
C-coders of HN, do you use plain vanilla C strings in your project (s)? I was under the impression that most (at least bigger ones) use some custom length carrying string type to avoid exactly these sort of problems