diff options
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | def.h | 5 | ||||
-rw-r--r-- | include.c | 16 | ||||
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | parse.c | 9 |
5 files changed, 26 insertions, 14 deletions
diff --git a/configure.ac b/configure.ac index 0ecfd7f..6cf0e3a 100644 --- a/configure.ac +++ b/configure.ac @@ -7,6 +7,10 @@ AC_INIT([makedepend], [1.0.8], [https://gitlab.freedesktop.org/xorg/util/makedepend/-/issues]) AC_CONFIG_SRCDIR([Makefile.am]) AC_CONFIG_HEADERS([makedepend-config.h]) +# Set common system defines for POSIX extensions, such as _GNU_SOURCE +# Must be called before any macros that run the compiler (like AC_PROG_LIBTOOL) +# to avoid autoconf errors. +AC_USE_SYSTEM_EXTENSIONS # Initialize Automake AM_INIT_AUTOMAKE([foreign dist-xz]) @@ -21,7 +25,7 @@ XORG_DEFAULT_OPTIONS XORG_WITH_LINT dnl Checks for functions -AC_CHECK_FUNCS([rename fchmod]) +AC_CHECK_FUNCS([rename fchmod reallocarray]) dnl Use 64-bit file operations on 32-bit systems that support them AC_SYS_LARGEFILE @@ -38,6 +38,11 @@ in this Software without prior written authorization from The Open Group. #include <fcntl.h> #include <sys/stat.h> +#ifndef HAVE_REALLOCARRAY +#define reallocarray(ptr, num, size) realloc(ptr, (num) * (size)) +#endif +#define mallocarray(num, size) reallocarray(NULL, num, size) + #define MAXDEFINES 512 #define MAXFILES 2048 #define MAXINCFILES 128 /* "-include" files */ @@ -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; @@ -214,7 +214,7 @@ main(int argc, char *argv[]) } if (p[-1]) nargc++; - nargv = malloc(nargc * sizeof(char *)); + nargv = mallocarray(nargc, sizeof(char *)); nargv[0] = argv[0]; argc = 1; for (p = args; argc < nargc; p += strlen(p) + 1) @@ -276,7 +276,7 @@ main(int argc, char *argv[]) if (numundefs == 1) undeflist = malloc(sizeof(char *)); else - undeflist = realloc(undeflist, numundefs * sizeof(char *)); + undeflist = reallocarray(undeflist, numundefs, sizeof(char *)); if (argv[0][2] == '\0') { if (argc < 2) fatalerr("Missing argument for -U\n"); @@ -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; } |