News for hackers. Stuff that matters.
Re:I'm Not a Fan of Strlcpy(3) by cyberpunk on Monday July 15, 2024 @09:29AM (#40967730)
I mean just use bstrlib why is it difficult?
Re:I'm Not a Fan of Strlcpy(3) by rwmj on Monday July 15, 2024 @09:35AM (#40967772)
Because no one can agree on which string library / abstraction to use, if they even use one at all which is rare.
Re:I'm Not a Fan of Strlcpy(3) by dark-star on Monday July 15, 2024 @09:45AM (#40967851)
I mean just use C++ w/ std::string why is it difficult?
Re:I'm Not a Fan of Strlcpy(3) by smallstepforman on Monday July 15, 2024 @11:05AM (#40968509)
std::u8string
Re:I'm Not a Fan of Strlcpy(3) by account42 on Monday July 15, 2024 @11:31AM (#40968752)
No, std::string.
Re:I'm Not a Fan of Strlcpy(3) by bluGill on Monday July 15, 2024 @12:57PM (#40969541)
Most C programs compile and work correctly compiled as C++. The exceptions are often places you shouldn't write code like that, sometimes even outright bugs that C++'s stricter type system caught for you.
Re:I'm Not a Fan of Strlcpy(3) by Pesthuf on Monday July 15, 2024 @10:13AM (#40968070)
I'd be happy if developers did that, but they don't:

So many C developer seem to think they're "smart enough" to handle strings correctly using only the standard library, not needing "training wheels" like the plebs - but then where do the countless string related memory safety errors and all the broken Unicode handling come from that plague every C program, no matter how clever the programmers, no matter how tough the review process, no matter how much static analysis is used?

The issue is that many C developers simply can't seem to admit that C string handling, as it was invented many decades ago, was simply fundamentally flawed. So easy to misuse with catastrophic results, even for plain 1-byte-strings. It has nothing to do with how "smart" you are or how careful you are.

Re:I'm Not a Fan of Strlcpy(3) by johnnyanmac on Monday July 15, 2024 @11:38AM (#40968838)
Are there really people defending string manipulation in C? C is a slight abstraction on top of assembly. Assembly speaks in addresses and bytes. It's always been bad at trying to interpret human text because Assembly's job lies in the digital realm.

I think it's more a case that programming is English skewed and localization concerns are rare for the programmers these day who still need to work in the realm of C (so, mostly for older legacy software or the embedded realm).

Re:I'm Not a Fan of Strlcpy(3) by Pesthuf on Tuesday July 16, 2024 @03:17PM (#40979395)
It doesn't matter if anyone is defending it - C developers still use C strings and the broken C standard library's string functions (exclusively) rather than using one of the many good string libraries they have available.

The result is that the same mistakes with string handling get repeated again and again, often with catastrophic results.

Re:I'm Not a Fan of Strlcpy(3) by johnnyanmac on Tuesday July 16, 2024 @11:51PM (#40982391)
Developers do a lot of unoptimal things for unoptimal reasons. Ultimately what's "right" or "wrong" is a case by case basis. So I don't see much point in venting against those developers without knowing their circumstance.

I mostly ask who's defending it for holistic purposes. Right or wrong, It would be nice to hear other perspectives on the matter if possible.

Re:I'm Not a Fan of Strlcpy(3) by bluGill on Monday July 15, 2024 @01:00PM (#40969568)
Smart is not the issue. I'm smart enough, but I'm lazy and forgetful. C makes it really accidentaly once in a while.