Morally I view “what do I do with my truncated string” to be a separate issue from “how do I truncate the string” as described in the article. Like, yes, you absolutely should not concatenate after doing this operation. But maybe you shouldn’t be showing the user a truncated string either even if it’s all ASCII. The question of “did you make an unparseable UTF-8 string” is answered with “no” and the more complicated but also more interesting question of “did you actually want this” remains unanswered.
Re:I'm Not a Fan of Strlcpy(3)
by Levitating on Monday July 15, 2024 @10:25AM
(#40968152)
This is fair, the article takes truncating a string to fit in a status bar as an example.
Re:I'm Not a Fan of Strlcpy(3)
by actionfromafar on Monday July 15, 2024 @10:35AM
(#40968237)
Also consider Unicode is not only international characters, but superscripts and other stuff ♥ᵃ
a: there was a list somewhere over which characters hackernews allows?
Especially because concatenation is a very common operation so those sliced codepoints will be everywhere, including in the middle of text.