Let's say that we have:
char *a = malloc(sizeof(char*));
char *b = realloc(a,sizeof(char*));
Is it possible to say with confidence that it is b
not an alias with a
? The man page realloc
says that
The original ptr pointer is invalid, and any access to it is undefined (even if the redistribution was in place).
So, can I mark b
as non-smoothing a
, since we can no longer legally access a
? However, this can lead to questionable optimization when to exclude the following branch:
if (a == b)
something..
Based on my understanding, a comparison of itself a == b
would be UB, so is this technically correct optimization?
source
share