summaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-12-06 17:42:04 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-01-01 14:34:57 -0800
commit40bcc8c3303a858c786f1d6d04ae5bbdec6b04ff (patch)
tree1d6ad569496120004426e60a8c6d40b7584700d6 /parse.c
parent47f2e64d865568d4f00cb97e42ad5cfc47e9c161 (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.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/parse.c b/parse.c
index f3f569c..9727508 100644
--- a/parse.c
+++ b/parse.c
@@ -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;
}