Why isn't argv[argc]==(char *)0 ?

Guy Harris guy at auspex.UUCP
Tue Dec 19 11:17:04 AEST 1989


>OK Guys - I am the support person for Olivetti Africa and was a little
>upset about the accusation.

You mean the accusation that

>Pim >>In X/OS, a SYSV/BSD hybrid operating system for the Olivetti LSX
>Pim >>minicomputers, a reference to argv[argc] will make your program
>Pim >>dump core.

?  Said accusation was either incorrect or poorly stated; as indicated
in my article, it could either mean "a dereference of 'argv[argc]'" will
make your program drop core" (not proved true or false by your example
program - see below - and if it's true, that's perfectly legitimate) or
"even trying to use the pointer value 'argv[argc]' will cause your
program to drop core" (proven false by your example, which is fortunate,
since if it *were* true, it *would* have been a Mutant UNIX From Hell).

>printf("Value of av[ac] = %s\n",av[ac]);

"printf" implementations often check for null pointer values passed to
"%s", and print "(null)" when a null pointer is used; if you want to see
whether dereferencing a null pointer on your machine causes a core dump
(if it does, 10,000 cheers for Olivetti; disallowing dereferencing of
null pointers will catch annoying bugs), do:

	#include <stdio.h>

	int
	main(av, ac)
		int av;
		char **ac;
	{
		if (av[ac][0] == 'z')
			(void) printf("Oh well, it lets me dereference null\n");
		return 0;
	}



More information about the Comp.unix.wizards mailing list