Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
memcpy(dst, src, size) is a Undefined behavior if src is nullptr, even if size is 0. (https://en.cppreference.com/w/c/string/byte/memcpy)
I ran into a case where the input Stack parameter for the scanner serialize call has the has NULL content, 0 size and 0 capacity. And that caused runtime crash when build with UBSAN.
I thought about checking src being nullptr instead of size being 0. But I think if we ever get an input where src is nullptr but size > 0, that's bug somewhere else and we should crash program to surface that. Nullptr + zero size sounds relatively legit to actually hit this function, we just shouldn't try to do memcpy with such empty src. Thus i went with checking the size, not the src ptr. Let me know if people prefer other way. Thanks.