vis.c warning on debian
job opened this issue · comments
...
CC vis.lo
vis.c: In function 'stravis':
vis.c:252:23: warning: pointer 'buf' may be used after 'realloc' [-Wuse-after-free]
252 | *outp = buf;
| ~~~~~~^~~~~
vis.c:250:17: note: call to 'realloc' here
250 | *outp = realloc(buf, len + 1);
| ^~~~~~~~~~~~~~~~~~~~~
...
should this be fixed?
It is a false positive. The reallocarray allocates for the worst case.
Then this realloc cuts down the allocation to the actually required
size. If it does fail, then buf with the allocated size is unchanged
per the C standard and can used instead.