Post by Scott LurndalHow would you validate any of the parameters to memcpy? Particularly
considering that from a hardware point of view, zero is a legal virtual
address.
If you read my whole post, note that I exactly said that. You can't in
the general case, but you could just for a null pointer. Whether that
would be useful is also questionable, which I also said.
As to zero (null pointers) being valid, even for memcpy(), it's a bit
confusing. Whereas 0 can be a "valid" address on some targets at a very
low level, according to the standard (at least C99):
"If a null pointer constant is converted to a pointer type, the
resulting pointer, called a null pointer, is guaranteed to compare
unequal to a pointer to any object or function."
So by that definition, a null pointer can't point to any valid object.
And whatever happens with non-valid objects, is, you guessed...
undefined behavior. What it all means is that the whole spirit of C (at
least for a large chunk of the standard) doesn't really make any
parameter invalid per se. It just states "undefined behavior" for some
parameter values, and the cases in which some values are illegal are
very few.
A corollary here is that you can perfectly pass pointers to non-valid
objects to memcpy(). But: this triggers undefined behavior. We're
running in circles. ;)
I'll have to admit that parameters triggering undefined behavior are not
necessarily "invalid" per se by the standard. This kind of makes sense,
but it is certainly confusing for many people.
Anyway, as I said in previous posts, this is really a non-issue: if you
need a specific behavior for undefined behavior cases, just implement
functions on top (or in replacement of) the existing ones. I'm fine with
this.
One wrong approach though IMO would be *assuming* any specific behavior
for undefined behavior cases.