After reading the answers to this SO question , I found out that pointer arithmetic is out-of-bounds undefined. Indeed, according to C99 6.5.6, paragraph 8
If both the pointer operand and the result point to elements of the same array, or one after the last element of the array, the evaluation should not lead to overflow; otherwise, the behavior is undefined.
Does this facility void the warranty? 7.20.3.2 The “free function” does not seem to mention this, simply saying that “space is freed”. Since 6.5.6 specifically mentions overflow, this seems like a problem with integer overflow that will not affect for free. Is arithmetic a pointer to an object an act of "referring to it"?
In other words, it is:
char *foo = malloc(10);
free(foo);
foo++;
Undefined? Or is another overflow used?
source
share