Mettle

M0111Borrowed pointer invalidated by realloc

Reported by the compiler as an error or warning.

mettle explain M0111

A pointer into a heap buffer is used after the buffer was passed to realloc. realloc may move the allocation, leaving every old interior pointer dangling - even when the call "usually" grows in place.

Fix: recompute interior pointers from the (new) base pointer after every realloc.

Related