use reallocarray. ok guenther
authortedu <tedu@openbsd.org>
Wed, 7 May 2014 14:56:57 +0000 (14:56 +0000)
committertedu <tedu@openbsd.org>
Wed, 7 May 2014 14:56:57 +0000 (14:56 +0000)
bin/pax/options.c
bin/pax/tables.c

index ae73f2f..85649da 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: options.c,v 1.84 2014/02/06 20:51:55 guenther Exp $   */
+/*     $OpenBSD: options.c,v 1.85 2014/05/07 14:56:57 tedu Exp $       */
 /*     $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $  */
 
 /*-
@@ -779,11 +779,9 @@ tar_options(int argc, char **argv)
                                size_t n = nincfiles + 3;
                                struct incfile *p;
 
-                               p = realloc(incfiles,
-                                   sizeof(*incfiles) * n);
+                               p = reallocarray(incfiles, n,
+                                   sizeof(*incfiles));
                                if (p == NULL) {
-                                       free(incfiles);
-                                       incfiles = NULL;
                                        paxwarn(0, "Unable to allocate space "
                                            "for option list");
                                        exit(1);
index 017abc5..5fc78e4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tables.c,v 1.30 2014/01/08 06:43:34 deraadt Exp $     */
+/*     $OpenBSD: tables.c,v 1.31 2014/05/07 14:56:57 tedu Exp $        */
 /*     $NetBSD: tables.c,v 1.4 1995/03/21 09:07:45 cgd Exp $   */
 
 /*-
@@ -1131,7 +1131,7 @@ add_dir(char *name, struct stat *psb, int frc_mode)
                name = rp;
        }
        if (dircnt == dirsize) {
-               dblk = realloc(dirp, 2 * dirsize * sizeof(DIRDATA));
+               dblk = reallocarray(dirp, dirsize, 2 * sizeof(DIRDATA));
                if (dblk == NULL) {
                        paxwarn(1, "Unable to store mode and times for created"
                            " directory: %s", name);