diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -188,6 +188,8 @@ main(int argc, char *argv[]) fatalerr("cannot open \"%s\"\n", argv[1] + 1); fstat(afd, &ast); args = malloc(ast.st_size + 1); + if (args == NULL) + fatalerr("malloc()/realloc() failure in %s()\n", __func__); if ((ast.st_size = read(afd, args, ast.st_size)) < 0) fatalerr("failed to read %s\n", argv[1] + 1); args[ast.st_size] = '\0'; @@ -215,6 +217,8 @@ main(int argc, char *argv[]) if (p[-1]) nargc++; nargv = mallocarray(nargc, sizeof(char *)); + if (nargv == NULL) + fatalerr("malloc()/realloc() failure in %s()\n", __func__); nargv[0] = argv[0]; argc = 1; for (p = args; argc < nargc; p += strlen(p) + 1) @@ -277,6 +281,8 @@ main(int argc, char *argv[]) undeflist = malloc(sizeof(char *)); else undeflist = reallocarray(undeflist, numundefs, sizeof(char *)); + if (undeflist == NULL) + fatalerr("malloc()/realloc() failure in %s()\n", __func__); if (argv[0][2] == '\0') { if (argc < 2) fatalerr("Missing argument for -U\n"); @@ -382,7 +388,7 @@ main(int argc, char *argv[]) char *buf; if (argc < 2) - fatalerr("option -include is a " "missing its parameter\n"); + fatalerr("option -include is missing its parameter\n"); if (cmdinc_count >= MAXINCFILES) fatalerr("Too many -include flags.\n"); argc--; @@ -390,7 +396,7 @@ main(int argc, char *argv[]) buf = malloc(strlen(DASH_INC_PRE) + strlen(argv[0]) + strlen(DASH_INC_POST) + 1); if (!buf) - fatalerr("out of memory at " "-include string\n"); + fatalerr("out of memory at -include string\n"); cmdinc_list[2 * cmdinc_count + 0] = argv[0]; cmdinc_list[2 * cmdinc_count + 1] = buf; cmdinc_count++; @@ -532,17 +538,21 @@ getfile(const char *file) struct stat st; content = malloc(sizeof(struct filepointer)); + if (content == NULL) + fatalerr("malloc()/realloc() failure in %s()\n", __func__); content->f_name = file; if ((fd = open(file, O_RDONLY)) < 0) { warning("cannot open \"%s\"\n", file); content->f_p = content->f_base = content->f_end = malloc(1); + if (content->f_p == NULL) + fatalerr("malloc()/realloc() failure in %s()\n", __func__); *content->f_p = '\0'; return (content); } fstat(fd, &st); content->f_base = malloc(st.st_size + 1); if (content->f_base == NULL) - fatalerr("cannot allocate mem\n"); + fatalerr("malloc()/realloc() failure in %s()\n", __func__); if ((st.st_size = read(fd, content->f_base, st.st_size)) < 0) fatalerr("failed to read %s\n", file); close(fd); @@ -715,6 +725,9 @@ base_name(const char *in_file) char *p; char *file = strdup(in_file); + if (file == NULL) + fatalerr("strdup() failure in %s()\n", __func__); + for (p = file + strlen(file); p > file && *p != '.'; p--); if (*p == '.') |