4 ms·
you are calling realloc and assigning the value directly before checking the return value. realloc can fail and return NULL and you'll overwrite the previous po
by halayli 14y ago
you are calling realloc and assigning the value directly before checking the return value. realloc can fail and return NULL and you'll overwrite the previous pointer which will cause a memory leak.
I don't see why you duplicated strndup in parson_strndup.
https://github.com/kgabis/parson/blob/master/parson.c#L129 https://github.com/kgabis/parson/blob/master/parson.c#L129
parson_strdup can return NULL and this statement will fail silently.
- thomaslee 14y agostrndup is part of the "standard", but not present on some platforms unfortunately. :( I can't think of a modern C runtime that doesn't offer strdup, though. The realloc check is good advice -- take heed, OP. :)
- halayli 14y agoTrue, strndup is relatively new (~7 years) to POSIX standard.
- kgabis 14y agoRealloc, strdup and strndup errors are handled as of now :) (https://github.com/kgabis/parson/commit/ee9be98974b3fdac0be1cc370bec948613e725d7 https://github.com/kgabis/parson/commit/ee9be98974b3fdac0be1...) And yes, I've written my own strndup because it's "relatively new".