News for hackers. Stuff that matters.
Re:Efficient string copying and concatenation in C by RhysU on Thursday September 12, 2019 @06:01PM (#20956936)
What is length of an invalid string? What is the length of the concatenation of two invalid strings?

There are sensible answers. But they are weird.

Re:Efficient string copying and concatenation in C by codehero on Thursday September 12, 2019 @08:00PM (#20957756)
Is it more sensible to cat 2 strings, but cut off the second one, then pass off the result as valid?

I would say let an INVALID string be length 0. Then accept that catting a valid and invalid string would result in a shorter length.

Which one do you think is safer?

Re:Efficient string copying and concatenation in C by RhysU on Friday September 13, 2019 @05:28PM (#20966794)
I would expect an invalid string to have an invalid length. For integer-valued lengths you'd have to use a negative number to differentiate from a valid, empty string. But then the sum of the invalid-string lengths differs from the length of the concatenated invalid strings. Which is wonky.
Re:Efficient string copying and concatenation in C by codehero on Saturday September 14, 2019 @05:11AM (#20969703)
Safe string manipulation never exceeds the bounds of the buffer. So negative values are dangerous, as all as any additions that would exceed the maximum size.

Negative lengths are not compatible with unsigned representation.

A system implementing invalid string values must choose a text encoding such as UTF-8 that supports the concept of an invalid character. Null termination is too flexible. As such is simple length prepending.