add missing null pointer checks (#80)
The result of copying a null pointer is undefined.
This commit is contained in:
parent
d4c94500c4
commit
52e9c039c5
1 changed files with 8 additions and 4 deletions
12
toml.c
12
toml.c
|
@ -412,8 +412,10 @@ static void *expand(void *p, int sz, int newsz) {
|
||||||
if (!s)
|
if (!s)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
memcpy(s, p, sz);
|
if (p) {
|
||||||
FREE(p);
|
memcpy(s, p, sz);
|
||||||
|
FREE(p);
|
||||||
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,8 +425,10 @@ static void **expand_ptrarr(void **p, int n) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
s[n] = 0;
|
s[n] = 0;
|
||||||
memcpy(s, p, n * sizeof(void *));
|
if (p) {
|
||||||
FREE(p);
|
memcpy(s, p, n * sizeof(void *));
|
||||||
|
FREE(p);
|
||||||
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue