cJSON
cJSON copied to clipboard
fix bug: fuction 'ensure' get error needed size
Yes, I agree. It looks like the null-terminator is being "double-counted": once in the call to ensure() and again in ensure(). I also agree with this fix, as it means ensure() is mostly viewing the buffer as a raw buffer instead of as a string, and the calls to ensure() account for the null terminator if needed.
Note that there is still a place in ensure() where the old buffer is being copied to the new buffer, where it does a p->offset + 1
for the memcpy(). This should always be safe in its use-case, but does violate the raw buffer vs string view a little.