cJSON icon indicating copy to clipboard operation
cJSON copied to clipboard

fix bug: fuction 'ensure' get error needed size

Open huang4115 opened this issue 5 years ago • 1 comments

huang4115 avatar Jul 25 '18 09:07 huang4115

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.

bneuen avatar Aug 14 '20 17:08 bneuen