json-tutorial icon indicating copy to clipboard operation
json-tutorial copied to clipboard

lept_set_string(): memcpy exists potential undefined behavior

Open imdouyu opened this issue 4 years ago • 0 comments

When s == NULL and len == 0, we try copy s to v->u.s.s that is undefined behavior.

The behavior is undefined if either dest or src is an invalid or null pointer.

https://github.com/miloyip/json-tutorial/blob/65c078b2bb270bfc9af50497cd1844bcff5c8214/tutorial03/leptjson.c#L183-L191 We can solve this by add if (s != NULL) before memcpy.

imdouyu avatar Oct 15 '21 04:10 imdouyu