3 ms·
The choice of a null terminator vs len+adr is distinct from the issue of buffer overflows. A string implementation could use storage buffers sized with len+adr
by barrkel 15y ago
The choice of a null terminator vs len+adr is distinct from the issue of buffer overflows. A string implementation could use storage buffers sized with len+adr (with len as capacity) and range check them at runtime, but still use null terminators for the actual string length. This wouldn't necessarily be redundant; null termination has desirable semantics for algorithms that process text as a stream (e.g. scanners, regex) and saves having to keep track of distance to string end in a separate counter.
The deeper problem is lack of memory safety. The state of the art in static checks wasn't as advanced back then though (Pascal, in its original form, was not well received at the systems level), and dynamic checks would be considered too costly.