diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-12-06 17:42:04 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-01-01 14:34:57 -0800 |
commit | 40bcc8c3303a858c786f1d6d04ae5bbdec6b04ff (patch) | |
tree | 1d6ad569496120004426e60a8c6d40b7584700d6 /parse.c | |
parent | 47f2e64d865568d4f00cb97e42ad5cfc47e9c161 (diff) |
Use reallocarray() on systems that provide it
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -318,13 +318,12 @@ define2(const char *name, const char *val, struct inclist *file) /* Make space if it's needed */ if (file->i_defs == NULL) { - file->i_defs = malloc(sizeof(struct symtab *) * SYMTABINC); + file->i_defs = mallocarray(SYMTABINC, sizeof(struct symtab *)); file->i_ndefs = 0; } else if (!(file->i_ndefs % SYMTABINC)) - file->i_defs = realloc(file->i_defs, - sizeof(struct symtab *) * (file->i_ndefs + - SYMTABINC)); + file->i_defs = reallocarray(file->i_defs, (file->i_ndefs + SYMTABINC), + sizeof(struct symtab *)); if (file->i_defs == NULL) fatalerr("malloc()/realloc() failure in insert_defn()\n"); @@ -474,7 +473,7 @@ merge2defines(struct inclist *file1, struct inclist *file2) if (deflen > 0) { /* make sure deflen % SYMTABINC == 0 is still true */ deflen += (SYMTABINC - deflen % SYMTABINC) % SYMTABINC; - i_defs = malloc(deflen * sizeof(struct symtab *)); + i_defs = mallocarray(deflen, sizeof(struct symtab *)); if (i_defs == NULL) return 0; } |