On Mon, Sep 21, 2020 at 2:40 PM Paul Winalski <paul.winalski(a)gmail.com>
wrote:
VAX/VMS was the first operating system I encountered
where 0 was not a
valid program address. As was mentioned previously, address space on
early machines was too precious to throw away a whole page of it just
to catch bad null pointer references.
I once saw a C program that depended on 0 being a valid pointer
address, and on a 0x00 byte being at memory address 0. The program
had a bunch of char* pointers that were used in a printf() call,
something like:
printf("%s%s%s%s\n", a, b, c, d);
If you didn't want, say, the third string printed, you assigned NULL
to variable c. That caused c to point to location 0, and printf()
interpreted the 0 byte as the empty string "".
It was hell getting this program to work on the VAX.
That sounds annoying, but not necessarily insurmountable? I imagine you
could wrap it in something like:
void
print4(char *a, char *b, char *c, char *d)
{
if (a == NULL) a = "";
if (b == NULL) b = "";
if (c == NULL) c = "";
if (d == NULL) d = "";
printf("%s%s%s%s\n", a, b, c, d);
}
?
I guess if it was more complex than that, like say being variadic, it'd be
really annoying because you'd have to walk the arguments and accumulate
them and assign pointers to empty strings as appropriate, or just wrap
printf and interpret the format string.
- Dan C.