Conversion of explicit multiplications:
alloc(A*B, ...) becomes allocarray(A, B, ...), and
aresize(..., A*B, ...) becomes aresizearray(..., A, B, ...)
I ordered the arguments in such a way that A is nmemb and B is size as
in the prototypes of allocarray() and aresizearray().
Index: edit.c
===================================================================
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.40
diff -u -p -r1.40 edit.c
--- edit.c 12 Mar 2015 10:20:30 -0000 1.40
+++ edit.c 23 May 2015 11:58:27 -0000
@@ -474,7 +474,7 @@ x_command_glob(int flags, const char *st
int i;
info = (struct path_order_info *)
- alloc(sizeof(struct path_order_info) * nwords, ATEMP);
+ allocarray(nwords, sizeof(struct path_order_info),
ATEMP);
for (i = 0; i < nwords; i++) {
info[i].word = words[i];
info[i].base = x_basename(words[i], (char *) 0);
Index: history.c
===================================================================
RCS file: /cvs/src/bin/ksh/history.c,v
retrieving revision 1.40
diff -u -p -r1.40 history.c
--- history.c 20 Nov 2014 15:22:39 -0000 1.40
+++ history.c 23 May 2015 11:58:27 -0000
@@ -506,7 +506,8 @@ sethistsize(int n)
cursize = n;
}
- history = (char **)aresize(history, n*sizeof(char *), APERM);
+ history = (char **)aresizearray(history, n, sizeof(char *),
+ APERM);
histsize = n;
histptr = history + cursize;
@@ -555,7 +556,7 @@ init_histvec(void)
{
if (history == (char **)NULL) {
histsize = HISTORYSIZE;
- history = (char **)alloc(histsize*sizeof (char *), APERM);
+ history = (char **)allocarray(histsize, sizeof(char *), APERM);
histptr = history - 1;
}
}
Index: lex.c
===================================================================
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.49
diff -u -p -r1.49 lex.c
--- lex.c 17 Dec 2013 16:37:06 -0000 1.49
+++ lex.c 23 May 2015 11:58:27 -0000
@@ -1621,7 +1621,7 @@ 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 = allocarray(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.55
diff -u -p -r1.55 main.c
--- main.c 9 Feb 2015 09:09:30 -0000 1.55
+++ main.c 23 May 2015 11:58:27 -0000
@@ -78,7 +78,7 @@ make_argv(int argc, char *argv[])
char **nargv = argv;
if (strcmp(argv[0], kshname) != 0) {
- nargv = alloc(sizeof(char *) * (argc + 1), &aperm);
+ nargv = allocarray(argc + 1, sizeof(char *), &aperm);
nargv[0] = (char *) kshname;
for (i = 1; i < argc; i++)
nargv[i] = argv[i];
Index: shf.c
===================================================================
RCS file: /cvs/src/bin/ksh/shf.c,v
retrieving revision 1.16
diff -u -p -r1.16 shf.c
--- shf.c 19 Apr 2013 17:36:09 -0000 1.16
+++ shf.c 23 May 2015 11:58:27 -0000
@@ -328,7 +328,7 @@ shf_emptybuf(struct shf *shf, int flags)
!(shf->flags & SHF_ALLOCB))
return EOF;
/* allocate more space for buffer */
- nbuf = (unsigned char *) aresize(shf->buf, shf->wbsize * 2,
+ nbuf = (unsigned char *) aresizearray(shf->buf, 2, shf->wbsize,
shf->areap);
shf->rp = nbuf + (shf->rp - shf->buf);
shf->wp = nbuf + (shf->wp - shf->buf);
Index: tree.c
===================================================================
RCS file: /cvs/src/bin/ksh/tree.c,v
retrieving revision 1.20
diff -u -p -r1.20 tree.c
--- tree.c 27 Jun 2012 07:17:19 -0000 1.20
+++ tree.c 23 May 2015 11:58:27 -0000
@@ -470,7 +470,7 @@ tcopy(struct op *t, Area *ap)
for (tw = t->vars; *tw++ != NULL; )
;
rw = r->vars = (char **)
- alloc((tw - t->vars + 1) * sizeof(*tw), ap);
+ allocarray(tw - t->vars + 1, sizeof(*tw), ap);
for (tw = t->vars; *tw != NULL; )
*rw++ = wdcopy(*tw++, ap);
*rw = NULL;
@@ -482,7 +482,7 @@ tcopy(struct op *t, Area *ap)
for (tw = t->args; *tw++ != NULL; )
;
rw = r->args = (char **)
- alloc((tw - t->args + 1) * sizeof(*tw), ap);
+ allocarray(tw - t->args + 1, sizeof(*tw), ap);
for (tw = t->args; *tw != NULL; )
*rw++ = wdcopy(*tw++, ap);
*rw = NULL;
@@ -632,7 +632,7 @@ iocopy(struct ioword **iow, Area *ap)
for (ior = iow; *ior++ != NULL; )
;
- ior = (struct ioword **) alloc((ior - iow + 1) * sizeof(*ior), ap);
+ ior = (struct ioword **) allocarray(ior - iow + 1, sizeof(*ior), ap);
for (i = 0; iow[i] != NULL; i++) {
struct ioword *p, *q;