[clug] [OT] Null-terminated strings: expensive mistake or not

Hugh Fisher hugh.fisher at anu.edu.au
Wed Aug 3 21:12:52 MDT 2011


steve jenkin wrote:
> A friend sent me this link making a case that null-terminated strings
> were "The Most Expensive One-byte Mistake".
...
> 
> There are a bunch of C and other coders on the list.
> Thought you might have interesting opinions on this.
> 

Blame for buffer overruns can be pushed back to IBM and their
decision with the 360 to go for a common address space  with
code and data intermingled rather than segmented and typed
memory like the Burroughs 5/6XXX series. On a B6700 a string
would just wipe out your local variables and then crash with
the equivalent of SEGV instead of overwriting the return
address.

Don't know how it compares with null terminated strings, but
IBM also made a one byte mistake with the 360. Pointers were
32 bit, but the hardware only used 24 bits for addressing.
IBM forgot to check the upper 8 bits, so programmers stuffed
useful flags into pointers. When mainframe memory finally
started going above 16M in the 1980s (IIRC), said programs
started crashing.

And just to prove the "those who ignore history are doomed
to repeat it" thing, Motorola made exactly the same mistake
with the 68000, causing Apple/Sun/etc much grief in the
1990s.

	cheers,
	Hugh


More information about the linux mailing list