I've said it before: there should only be one str* function in the standard lib: `strnlen`, and it should only be used to implement safer \
-
-
Replying to @stephentyrone
@stephentyrone Don't you mean memchr? It can be used to implement strnlen but also "strnchr", etc.2 replies 0 retweets 0 likes -
Replying to @RichFelker
@stephentyrone And don't forget strstr which has no easy substitute, although of course strnstr would be preferable.1 reply 0 retweets 0 likes -
Replying to @RichFelker
@RichFelker `strstr` is horrific. If strings are short, you're better off using stupid algorithm. If long, you want the length anyway.2 replies 0 retweets 1 like -
Replying to @stephentyrone
@stephentyrone There's no standard function like strstr to work with known-size strings.2 replies 0 retweets 0 likes -
Replying to @RichFelker
@stephentyrone And even if there were, you DON'T want to compute strlen(haystack) when you expect or know needle will occur early.2 replies 0 retweets 0 likes -
Replying to @RichFelker
@RichFelker For an isolated call, yes. But if you don't have pervasive implicit-length strings, you already know strlen(haystack).1 reply 0 retweets 0 likes -
Replying to @stephentyrone
@RichFelker I'm willing to accept inefficiency for a few cases to gain robustness everywhere.1 reply 0 retweets 0 likes -
Replying to @stephentyrone
@stephentyrone Processing null-terminated strings does not hurt robustness. Only the string.h funcs that write are actually dangerous.1 reply 0 retweets 0 likes
@stephentyrone Everything else is a matter of style. And I don't like imposing style.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.