7 ms·
Safe string handling in C can be done, but not with char*. PHP's Zend Engine has safely-handled strings, for example, but we do that by reference-counting them
by TazeTSchnitzel 12y ago
Safe string handling in C can be done, but not with char*.
PHP's Zend Engine has safely-handled strings, for example, but we do that by reference-counting them and having an explicit length.
- dmm 12y agoMy understanding is that strlcpy() exists to update existing programs that use NULL-terminated char arrays as strings. New programs should probably use some other more sophisticated implementation of strings, such as Git's strbuf: https://github.com/git/git/blob/master/strbuf.c https://github.com/git/git/blob/master/strbuf.c https://www.kernel.org/pub/software/scm/git/docs/technical/api-strbuf.html https://www.kernel.org/pub/software/scm/git/docs/technical/a...
- michaelmior 12y agoSDS[0] from the creator of Redis is also useful. It doesn't do reference counting, but is helpful for many other string manipulation issues. [0] https://github.com/antirez/sds https://github.com/antirez/sds
- TazeTSchnitzel 12y agoThe clever implementation allowing it to function like any other char* and that makes indexing work is what really sets it apart from the alternatives.