With help from Theo Buehler. ok?

Index: c_sh.c
===================================================================
RCS file: /cvs/src/bin/ksh/c_sh.c,v
retrieving revision 1.53
diff -u -p -r1.53 c_sh.c
--- c_sh.c      21 Oct 2015 15:20:37 -0000      1.53
+++ c_sh.c      29 Oct 2015 18:15:25 -0000
@@ -617,7 +617,7 @@ c_set(char **wp)
                while (*++wp != NULL)
                        *wp = str_save(*wp, &l->area);
                l->argc = wp - owp - 1;
-               l->argv = alloc(sizeofN(char *, l->argc+2), &l->area);
+               l->argv = areallocarray(NULL, l->argc+2, sizeof(char *), 
&l->area);
                for (wp = l->argv; (*wp++ = *owp++) != NULL; )
                        ;
        }
Index: edit.c
===================================================================
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.49
diff -u -p -r1.49 edit.c
--- edit.c      21 Oct 2015 14:31:28 -0000      1.49
+++ edit.c      29 Oct 2015 18:15:25 -0000
@@ -475,7 +475,8 @@ x_command_glob(int flags, const char *st
                int path_order = 0;
                int i;
 
-               info = alloc(sizeof(struct path_order_info) * nwords, ATEMP);
+               info = areallocarray(NULL, nwords,
+                   sizeof(struct path_order_info), ATEMP);
 
                for (i = 0; i < nwords; i++) {
                        info[i].word = words[i];
Index: exec.c
===================================================================
RCS file: /cvs/src/bin/ksh/exec.c,v
retrieving revision 1.61
diff -u -p -r1.61 exec.c
--- exec.c      19 Oct 2015 14:42:16 -0000      1.61
+++ exec.c      29 Oct 2015 18:15:25 -0000
@@ -96,9 +96,9 @@ execute(struct op *volatile t,
        flags &= ~XTIME;
 
        if (t->ioact != NULL || t->type == TPIPE || t->type == TCOPROC) {
-               e->savefd = alloc(sizeofN(short, NUFILE), ATEMP);
+               e->savefd = areallocarray(NULL, NUFILE, sizeof(short), ATEMP);
                /* initialize to not redirected */
-               memset(e->savefd, 0, sizeofN(short, NUFILE));
+               memset(e->savefd, 0, NUFILE * sizeof(short));
        }
 
        /* do redirection, to be restored in quitenv() */
Index: expand.h
===================================================================
RCS file: /cvs/src/bin/ksh/expand.h,v
retrieving revision 1.8
diff -u -p -r1.8 expand.h
--- expand.h    17 Sep 2015 14:21:33 -0000      1.8
+++ expand.h    29 Oct 2015 18:15:25 -0000
@@ -82,7 +82,7 @@ typedef struct XPtrV {
 
 #define        XPinit(x, n) do { \
                        void **vp__; \
-                       vp__ = alloc(sizeofN(void*, n), ATEMP); \
+                       vp__ = areallocarray(NULL, n, sizeof(void *), ATEMP); \
                        (x).cur = (x).beg = vp__; \
                        (x).end = vp__ + n; \
                } while (0)
@@ -90,8 +90,8 @@ typedef struct XPtrV {
 #define        XPput(x, p) do { \
                        if ((x).cur >= (x).end) { \
                                int n = XPsize(x); \
-                               (x).beg = (void**) aresize((void*) (x).beg, \
-                                                  sizeofN(void*, n*2), ATEMP); 
\
+                               (x).beg = (void**) areallocarray((void 
*)(x).beg, \
+                                                  n*2, sizeof(void *), ATEMP); 
\
                                (x).cur = (x).beg + n; \
                                (x).end = (x).cur + n; \
                        } \
@@ -101,7 +101,7 @@ typedef struct XPtrV {
 #define        XPptrv(x)       ((x).beg)
 #define        XPsize(x)       ((x).cur - (x).beg)
 
-#define        XPclose(x)      (void**) aresize((void*)(x).beg, \
-                                        sizeofN(void*, XPsize(x)), ATEMP)
+#define        XPclose(x)      (void**) areallocarray((void *)(x).beg, \
+                                        XPsize(x), sizeof(void *), ATEMP)
 
 #define        XPfree(x)       afree((x).beg, ATEMP)
Index: history.c
===================================================================
RCS file: /cvs/src/bin/ksh/history.c,v
retrieving revision 1.51
diff -u -p -r1.51 history.c
--- history.c   21 Oct 2015 15:47:41 -0000      1.51
+++ history.c   29 Oct 2015 18:15:25 -0000
@@ -556,7 +556,7 @@ init_histvec(void)
 {
        if (history == NULL) {
                histsize = HISTORYSIZE;
-               history = alloc(histsize*sizeof (char *), APERM);
+               history = areallocarray(NULL, histsize, sizeof(char *), APERM);
                histptr = history - 1;
        }
 }
Index: lex.c
===================================================================
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.61
diff -u -p -r1.61 lex.c
--- lex.c       19 Oct 2015 14:42:16 -0000      1.61
+++ lex.c       29 Oct 2015 18:15:26 -0000
@@ -1657,7 +1657,8 @@ getsc_bn(void)
 static Lex_state *
 push_state_(State_info *si, Lex_state *old_end)
 {
-       Lex_state       *new = alloc(sizeof(Lex_state) * STATE_BSIZE, ATEMP);
+       Lex_state *new = areallocarray(NULL, STATE_BSIZE,
+           sizeof(Lex_state), ATEMP);
 
        new[0].ls_info.base = old_end;
        si->base = &new[0];
Index: main.c
===================================================================
RCS file: /cvs/src/bin/ksh/main.c,v
retrieving revision 1.71
diff -u -p -r1.71 main.c
--- main.c      22 Oct 2015 15:37:04 -0000      1.71
+++ main.c      29 Oct 2015 18:15:26 -0000
@@ -125,7 +125,7 @@ make_argv(int argc, char *argv[])
        char **nargv = argv;
 
        if (strcmp(argv[0], kshname) != 0) {
-               nargv = alloc(sizeof(char *) * (argc + 1), &aperm);
+               nargv = areallocarray(NULL, argc + 1, sizeof(char *), &aperm);
                nargv[0] = (char *) kshname;
                for (i = 1; i < argc; i++)
                        nargv[i] = argv[i];
Index: sh.h
===================================================================
RCS file: /cvs/src/bin/ksh/sh.h,v
retrieving revision 1.50
diff -u -p -r1.50 sh.h
--- sh.h        23 Oct 2015 01:33:36 -0000      1.50
+++ sh.h        29 Oct 2015 18:15:26 -0000
@@ -27,7 +27,6 @@
 /* end of common headers */
 
 #define        NELEM(a) (sizeof(a) / sizeof((a)[0]))
-#define        sizeofN(type, n) (sizeof(type) * (n))
 #define        BIT(i)  (1<<(i))        /* define bit in flag */
 
 #define        NUFILE  32              /* Number of user-accessible files */
@@ -390,6 +389,7 @@ extern      int     x_cols; /* tty columns */
 Area * ainit(Area *);
 void   afreeall(Area *);
 void * alloc(size_t, Area *);
+void * areallocarray(void *, size_t, size_t, Area *);
 void * aresize(void *, size_t, Area *);
 void   afree(void *, Area *);
 /* c_ksh.c */
Index: syn.c
===================================================================
RCS file: /cvs/src/bin/ksh/syn.c,v
retrieving revision 1.36
diff -u -p -r1.36 syn.c
--- syn.c       19 Oct 2015 14:42:16 -0000      1.36
+++ syn.c       29 Oct 2015 18:15:26 -0000
@@ -197,8 +197,8 @@ get_command(int cf)
        XPtrV args, vars;
        struct nesting_state old_nesting;
 
-       iops = alloc(sizeofN(struct ioword *, NUFILE+1),
-           ATEMP);
+       iops = areallocarray(NULL, NUFILE + 1,
+           sizeof(struct ioword *), ATEMP);
        XPinit(args, 16);
        XPinit(vars, 16);
 
@@ -389,8 +389,8 @@ get_command(int cf)
                t->ioact = NULL;
        } else {
                iops[iopn++] = NULL;
-               iops = (struct ioword **) aresize((void*) iops,
-                   sizeofN(struct ioword *, iopn), ATEMP);
+               iops = (struct ioword **) areallocarray((void *)iops,
+                   iopn, sizeof(struct ioword *), ATEMP);
                t->ioact = iops;
        }
 
@@ -565,8 +565,8 @@ function_body(char *name,
                 * be used as input), we pretend there is a colon here.
                 */
                t->left = newtp(TCOM);
-               t->left->args = alloc(sizeof(char *) * 2, ATEMP);
-               t->left->args[0] = alloc(sizeof(char) * 3, ATEMP);
+               t->left->args = areallocarray(NULL, 2, sizeof(char *), ATEMP);
+               t->left->args[0] = alloc(3, ATEMP);
                t->left->args[0][0] = CHAR;
                t->left->args[0][1] = ':';
                t->left->args[0][2] = EOS;
Index: table.c
===================================================================
RCS file: /cvs/src/bin/ksh/table.c,v
retrieving revision 1.22
diff -u -p -r1.22 table.c
--- table.c     19 Oct 2015 14:43:46 -0000      1.22
+++ table.c     29 Oct 2015 18:15:26 -0000
@@ -57,7 +57,7 @@ texpand(struct table *tp, int nsize)
        struct tbl **ntblp, **otblp = tp->tbls;
        int osize = tp->size;
 
-       ntblp = alloc(sizeofN(struct tbl *, nsize), tp->areap);
+       ntblp = areallocarray(NULL, nsize, sizeof(struct tbl *), tp->areap);
        for (i = 0; i < nsize; i++)
                ntblp[i] = NULL;
        tp->size = nsize;
@@ -187,7 +187,8 @@ ktsort(struct table *tp)
        int i;
        struct tbl **p, **sp, **dp;
 
-       p = alloc(sizeofN(struct tbl *, tp->size+1), ATEMP);
+       p = areallocarray(NULL, tp->size + 1,
+           sizeof(struct tbl *), ATEMP);
        sp = tp->tbls;          /* source */
        dp = p;                 /* dest */
        for (i = 0; i < tp->size; i++)
Index: tree.c
===================================================================
RCS file: /cvs/src/bin/ksh/tree.c,v
retrieving revision 1.26
diff -u -p -r1.26 tree.c
--- tree.c      19 Oct 2015 14:42:16 -0000      1.26
+++ tree.c      29 Oct 2015 18:15:26 -0000
@@ -465,7 +465,8 @@ tcopy(struct op *t, Area *ap)
        else {
                for (tw = t->vars; *tw++ != NULL; )
                        ;
-               rw = r->vars = alloc((tw - t->vars + 1) * sizeof(*tw), ap);
+               rw = r->vars = areallocarray(NULL, tw - t->vars + 1,
+                   sizeof(*tw), ap);
                for (tw = t->vars; *tw != NULL; )
                        *rw++ = wdcopy(*tw++, ap);
                *rw = NULL;
@@ -476,7 +477,8 @@ tcopy(struct op *t, Area *ap)
        else {
                for (tw = t->args; *tw++ != NULL; )
                        ;
-               rw = r->args = alloc((tw - t->args + 1) * sizeof(*tw), ap);
+               rw = r->args = areallocarray(NULL, tw - t->args + 1,
+                   sizeof(*tw), ap);
                for (tw = t->args; *tw != NULL; )
                        *rw++ = wdcopy(*tw++, ap);
                *rw = NULL;
@@ -626,7 +628,7 @@ iocopy(struct ioword **iow, Area *ap)
 
        for (ior = iow; *ior++ != NULL; )
                ;
-       ior = alloc((ior - iow + 1) * sizeof(*ior), ap);
+       ior = areallocarray(NULL, ior - iow + 1, sizeof(*ior), ap);
 
        for (i = 0; iow[i] != NULL; i++) {
                struct ioword *p, *q;

Reply via email to