K
Keith Thompson
For a null pointer because of some crazy exec path possibly there is :
ignore it.
A null pointer will generally provoke an error sooner or later. An
assertion is useful for making it happen sooner: several times I've
immediately been able to work out what the error is from an assertion
message, while a segmentation fault some time later would have
required substantial debugging.[/QUOTE]
And it doesn't *always* provoke an error.
For example, in at least one implementation (gcc with glibc), this
program:
#include <stdio.h>
int main(void)
{
char *nullptr = NULL;
printf("nullptr = %s\n", nullptr);
return 0;
}
prints
nullptr = (null)
Apparently the glibc implementation of printf's "%s" format
"helpfully" recognizes null pointers and prints "(null)" rather than
crashing. I've seen "(null)" appear in the output of production
programs because of this, an error that probably would have been
caught if the code had crashed.
Undefined behavior is undefined behavior; it doesn't mean "the program
will crash".