News for hackers. Stuff that matters.
Re:Strlcpy and strlcat added to glibc 2.38 by IvyMike on Tuesday July 18, 2023 @02:14AM (#36768517)
The question is: Is string truncation a good solution when the strings you have are unexpectedly long? Like, it's probably ok in a lot of cases, and once you start using these functions, it's very tempting to use them almost everywhere... but truncating "Attack at dawn on Friday" to "Attack at dawn" could be a disaster as well.

On the other hand, his recommendation to always know string lengths and use memcpy didn't really become common practice over the last 20+ years either, so I'm not sure it was worth all the arguing.

At this point, I'm kind of joining the camp of "C has proven to be too bug-prone for most organizations to use safely and therefore we should all go to Rust".

Re:Strlcpy and strlcat added to glibc 2.38 by saagarjha on Tuesday July 18, 2023 @02:27AM (#36768620)
I suspect the eventual end result is major compilers start implementing a "fat pointer" string ABI for internal translation units (decaying to char * at the edge where necessary) and people start turning that on.
Re:Strlcpy and strlcat added to glibc 2.38 by eru on Tuesday July 18, 2023 @03:02AM (#36768860)
> On the other hand, his recommendation to always know string lengths and use memcpy didn't really become common practice over the last 20+ years either, so I'm not sure it was worth all the arguing.

It hasn't become common practice in C. But other languages (like JavaScript or Python) have become hugely popular, and don't use null-terminated strings.

Re:Strlcpy and strlcat added to glibc 2.38 by tomjakubowski on Tuesday July 18, 2023 @03:16AM (#36768961)
Even languages in C's niche encode strings as pointer + length, like Rust.
Re:Strlcpy and strlcat added to glibc 2.38 by bonzini on Tuesday July 18, 2023 @06:30AM (#36770234)
It has in the sense that people allocate strings much more than using fixed-size, stack-allocated arrays.

Modern C uses things like glib's GString, which (in addition to keeping the NUL terminator) track the length and can resize the underlying memory. And people also use a lot more asprintf instead of strcpy and strcat.

Re:Strlcpy and strlcat added to glibc 2.38 by jacquesm on Tuesday July 18, 2023 @09:35AM (#36771920)
> On the other hand, his recommendation to always know string lengths and use memcpy didn't really become common practice over the last 20+ years either

It was the way plenty of languages from the 70s stored their strings, including such popular ones as BASIC.

Re:Strlcpy and strlcat added to glibc 2.38 by radiator on Tuesday July 18, 2023 @03:14AM (#36768941)
The second part "and therefore we should all go to Rust" does not follow necessarily from the first. Maybe the reason not everybody is gone to Rust is that it lacks something. Maybe we will all go somewhere else.
Re:Strlcpy and strlcat added to glibc 2.38 by lelanthran on Tuesday July 18, 2023 @09:21AM (#36771716)
It lacks developer ergo omics, for me personally.

Source is for humans to read, it shouldn't look like alphabet soup for the idiomatic cases.