3 ms·
What I mean is that, when you say: > Unfortunately, some people are not sane, and have decided that it's equally valid for realloc(p, 0) to return NULL meaning
by antirez 11y ago
What I mean is that, when you say:
> Unfortunately, some people are not sane, and have decided that it's equally valid for realloc(p, 0) to return NULL meaning-failure and not free p.
What you want is the following semantics:
char *my_old_vector = ... ; /* We created / allocated in some way. */
add_important_stuff_to(my_old_vector);
char *new_vector = realloc(my_old_vector,size+100);
if (new_vector == NULL) {
/* I still have the old vector and can recover. */
}