summaryrefslogtreecommitdiff
path: root/include.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-12-06 18:45:03 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-01-01 14:50:25 -0800
commitffe60c0f58ae4b385ad733fad4455efaebdd1342 (patch)
tree74df96937360c26b8d2e148dcab23a861a2e6e52 /include.c
parent37371f1cdcf351e29bf542e6b2fc269b29a4fba2 (diff)
Make malloc error checking/reporting more consistent
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'include.c')
-rw-r--r--include.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/include.c b/include.c
index b3a17ab..f07fb70 100644
--- a/include.c
+++ b/include.c
@@ -54,7 +54,10 @@ issymbolic(const char *dir, const char *component)
if (strcmp(*pp, buf) == 0)
return (TRUE);
if (lstat(buf, &st) == 0 && (st.st_mode & S_IFMT) == S_IFLNK) {
- *pp++ = strdup(buf);
+ char *p = strdup(buf);
+ if (p == NULL)
+ fatalerr("strdup() failure in %s()\n", __func__);
+ *pp++ = p;
if (pp >= &notdotdot[MAXDIRS])
fatalerr("out of .. dirs, increase MAXDIRS\n");
return (TRUE);
@@ -151,11 +154,16 @@ newinclude(const char *newfile, const char *incstring)
if (inclistp == inclist + MAXFILES - 1)
fatalerr("out of space: increase MAXFILES\n");
ip->i_file = strdup(newfile);
+ if (ip->i_file == NULL)
+ fatalerr("strdup() failure in %s()\n", __func__);
if (incstring == NULL)
ip->i_incstring = ip->i_file;
- else
+ else {
ip->i_incstring = strdup(incstring);
+ if (ip->i_incstring == NULL)
+ fatalerr("strdup() failure in %s()\n", __func__);
+ }
inclistnext = inclistp;
return (ip);
@@ -205,6 +213,9 @@ included_by(struct inclist *ip, struct inclist *newfile)
ip->i_merged = reallocarray(ip->i_merged, ip->i_listlen,
sizeof(boolean));
}
+ if ((ip->i_list == NULL) || (ip->i_merged == NULL))
+ fatalerr("malloc()/realloc() failure in %s()\n", __func__);
+
ip->i_list[ip->i_listlen - 1] = newfile;
ip->i_merged[ip->i_listlen - 1] = FALSE;
}