diff options
Diffstat (limited to 'include.c')
-rw-r--r-- | include.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -173,11 +173,12 @@ included_by(struct inclist *ip, struct inclist *newfile) * If it is already on the list, don't stick it on again. */ if (ip->i_list == NULL) { - ip->i_list = malloc(sizeof(struct inclist *) * ++ip->i_listlen); - ip->i_merged = malloc(sizeof(boolean) * ip->i_listlen); + ip->i_listlen++; + ip->i_list = mallocarray(ip->i_listlen, sizeof(struct inclist *)); + ip->i_merged = mallocarray(ip->i_listlen, sizeof(boolean)); } else { - for (int i = 0; i < ip->i_listlen; i++) + for (int i = 0; i < ip->i_listlen; i++) { if (ip->i_list[i] == newfile) { i = strlen(newfile->i_file); if (!(ip->i_flags & INCLUDED_SYM) && @@ -197,9 +198,12 @@ included_by(struct inclist *ip, struct inclist *newfile) } return; } - ip->i_list = realloc(ip->i_list, - sizeof(struct inclist *) * ++ip->i_listlen); - ip->i_merged = realloc(ip->i_merged, sizeof(boolean) * ip->i_listlen); + } + ip->i_listlen++; + ip->i_list = reallocarray(ip->i_list, ip->i_listlen, + sizeof(struct inclist *)); + ip->i_merged = reallocarray(ip->i_merged, ip->i_listlen, + sizeof(boolean)); } ip->i_list[ip->i_listlen - 1] = newfile; ip->i_merged[ip->i_listlen - 1] = FALSE; |