add missing null pointer checks (#80)

The result of copying a null pointer is undefined.
This commit is contained in:
Vlad-Ștefan Harbuz 2023-05-29 20:36:32 +01:00 committed by GitHub
parent d4c94500c4
commit 52e9c039c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

12
toml.c
View File

@ -412,8 +412,10 @@ static void *expand(void *p, int sz, int newsz) {
if (!s)
return 0;
memcpy(s, p, sz);
FREE(p);
if (p) {
memcpy(s, p, sz);
FREE(p);
}
return s;
}
@ -423,8 +425,10 @@ static void **expand_ptrarr(void **p, int n) {
return 0;
s[n] = 0;
memcpy(s, p, n * sizeof(void *));
FREE(p);
if (p) {
memcpy(s, p, n * sizeof(void *));
FREE(p);
}
return s;
}