Skip to content

Commit b1f9800

Browse files
committed
Add a safety check for unportable realloc()
1 parent a343336 commit b1f9800

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

faclib/config.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,12 @@ int AddConfigToList(cfac_t *cfac, int k, CONFIG *cfg) {
17811781

17821782
cfg->nnrs = m;
17831783
if (m < cfg->n_shells) {
1784-
cfg->nrs = realloc(cfg->nrs, sizeof(int)*m);
1784+
if (m > 0) {
1785+
cfg->nrs = realloc(cfg->nrs, sizeof(int)*m);
1786+
} else {
1787+
free(cfg->nrs);
1788+
cfg->nrs = NULL;
1789+
}
17851790
}
17861791

17871792
/* Make sure that all configs are unique */

0 commit comments

Comments
 (0)