Live data from Hacker News

Linux eliminates the strncpy API after six years of work, 360 patches

phoronix.com

131–140 of 340 posts

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#131

the zero terminated string is I think is computing's biggest mistake. Pascal style strings were much safer.

Zero terminated strings were the basis for an awful lot of useful software. Calling them the biggest mistake in computing is a bit OTT. I haven’t programmed anything Pascal related for 30+ years but I dimly remember thinking at the time that I wished the string system wasn’t so hard to use.

Lead was the basis for an awful lot of useful gasoline. Doesn't mean it was the only solution or the best one.

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#133

the zero terminated string is I think is computing's biggest mistake. Pascal style strings were much safer.

compared to Von Newman versus Harvard architecture for LLMs? I think that's a far bigger mistake.

Neumann, and .. what? In what way?

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#134

the zero terminated string is I think is computing's biggest mistake. Pascal style strings were much safer.

> Pascal style strings were much safer. The limitations were brutal. Initially you could only have 255 bytes in a string. The length of a string and the size of the allocation are now separate and you may need to think about that unused memory in your design. The problem now doubles with the introduction of UTF-8. Your string size is in bytes and you need to track characters separately. If you want to create an array…

> You can erase your length information from the type. This was an intentional decision.

Well yes, but given the number of security issues the argument is that it was in retrospect the wrong decision.

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#135

the zero terminated string is I think is computing's biggest mistake. Pascal style strings were much safer.

Clang and GCC both let you use Pascal strings in C if you would like (with `\p`). But Pascal strings aren't that useful today because the maximum length is too short.

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#136

A reminder that we've had strlcpy [1] for ~ 30 years but it was never accepted into the Linux world because of typical petty open source bullshit. This is why we can't have nice things. [1] https://man.openbsd.org/strlcpy

The Linux kernel had strlcpy over 20 years ago. It was removed in favor of str s cpy because the latter was judged a better interface. Here's a 2022 article: https://lwn.net/Articles/905777/

Returning an error is better but you're using ssize_t which is a tradeoff.

The race conditions appear to be a result of the Linux kernel implementation but UNIX style syscalls introduce these races by default. It is not an inherent flaw of the API or even the implementation Linux was using.

The only useable C string API has always been memcpy anyways.

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#137
post #121
post #115

Earlier quoted context omitted.

Sorry, I didn't feel like this thread needed to be dragged out any longer since it's going in circles at this point and expanded my comment, but I didn't realize you had already replied.

Well - not really a circle. I keep saying the same thing over and over and you keep throwing arguments at it, unsuccessfully.

I don’t think it’s the arguments that are unsuccessful.

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#138

the zero terminated string is I think is computing's biggest mistake. Pascal style strings were much safer.

Clang and GCC both let you use Pascal strings in C if you would like (with `\p`). But Pascal strings aren't that useful today because the maximum length is too short.

Why would a pascal string be any shorter than a C string?

A C string is one pointer reaching all of memory, a Pascal string is two pointers reaching all of memory

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#139

the zero terminated string is I think is computing's biggest mistake. Pascal style strings were much safer.

Zero terminated strings were the basis for an awful lot of useful software. Calling them the biggest mistake in computing is a bit OTT. I haven’t programmed anything Pascal related for 30+ years but I dimly remember thinking at the time that I wished the string system wasn’t so hard to use.

A more accurate re-phrased version of the original is that they are the biggest mistake in the C language.

* https://news.ycombinator.com/item?id=48614913

* https://news.ycombinator.com/item?id=24454369

* https://news.ycombinator.com/item?id=1014533

Re: Linux eliminates the strncpy API after six years of work, 360 patches

#140
I have in the past made fun of the Linux kernel devs, supposedly some of the best C developers in the world, for not knowing how to make stringbuffer and stringview types, but to be fair to them we didn't have the consensus we have today on the topic.

You know who did have the right idea though? Dennis Ritchie, who proposed a fat pointer type for C all the way back in 1990. Would have made for a perfect addition to C99. Imagine how different the world might have been had the committee added that in.

We had a second chance with the release of the "C's greatest mistake" blog article from Walter Bright in 2007, essentially pushing for the same idea as Ritchie (slices/stringviews) but explained with much clearer language.

Alas, didn't make it to C11.

We're now in C23, still nothing. But we did get _Generic and VLAs! Party hard.

Post reply on HN