Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
json2cbor: don't use the buffer variable after realloc()
There's a discussion in the C and C++ communities whether you're allowed to use the values of pointers that have been deallocated, if you don't dereference them. Some argue that it is Undefined Behaviour in spite of the numeric value stored in the variable not having changed. Instead of arguing, let's just make sure we don't use the pointers after they have become dangling. We only needed the offset of how far we've written into the buffer to restore the state and we have a function that returns exactly that. Seen while debugging #259. Drive-by keep the `buffersize` global variable unchanged until after `realloc()` has returned with success. Signed-off-by: Thiago Macieira <[email protected]>
- Loading branch information