git: 83f5846fc818 - stable/12 - Reapply r315426 by pfg:
Warner Losh
imp at FreeBSD.org
Sat Jul 10 17:12:50 UTC 2021
The branch stable/12 has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=83f5846fc8180e17baff66480473846978a3f030
commit 83f5846fc8180e17baff66480473846978a3f030
Author: Warner Losh <imp at FreeBSD.org>
AuthorDate: 2019-06-02 16:30:53 +0000
Commit: Warner Losh <imp at FreeBSD.org>
CommitDate: 2021-07-10 17:11:15 +0000
Reapply r315426 by pfg:
| MFV r315425: one-true-awk: have calloc(3) do the multiplication.
(cherry picked from commit 06d1e65393f95e0fd2d068fe118487f754e4248b)
---
contrib/one-true-awk/b.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/contrib/one-true-awk/b.c b/contrib/one-true-awk/b.c
index 24baa33d8db1..4de746fa087f 100644
--- a/contrib/one-true-awk/b.c
+++ b/contrib/one-true-awk/b.c
@@ -148,7 +148,7 @@ fa *mkdfa(const char *s, int anchor) /* does the real work of making a dfa */
f->accept = poscnt-1; /* penter has computed number of positions in re */
cfoll(f, p1); /* set up follow sets */
freetr(p1);
- if ((f->posns[0] = (int *) calloc(1, *(f->re[0].lfollow)*sizeof(int))) == NULL)
+ if ((f->posns[0] = (int *) calloc(*(f->re[0].lfollow), sizeof(int))) == NULL)
overflo("out of space in makedfa");
if ((f->posns[1] = (int *) calloc(1, sizeof(int))) == NULL)
overflo("out of space in makedfa");
@@ -172,7 +172,7 @@ int makeinit(fa *f, int anchor)
f->reset = 0;
k = *(f->re[0].lfollow);
xfree(f->posns[2]);
- if ((f->posns[2] = (int *) calloc(1, (k+1)*sizeof(int))) == NULL)
+ if ((f->posns[2] = (int *) calloc(k+1, sizeof(int))) == NULL)
overflo("out of space in makeinit");
for (i=0; i <= k; i++) {
(f->posns[2])[i] = (f->re[0].lfollow)[i];
@@ -387,7 +387,7 @@ void cfoll(fa *f, Node *v) /* enter follow set of each leaf of vertex v into lfo
setvec[i] = 0;
setcnt = 0;
follow(v); /* computes setvec and setcnt */
- if ((p = (int *) calloc(1, (setcnt+1)*sizeof(int))) == NULL)
+ if ((p = (int *) calloc(setcnt+1, sizeof(int))) == NULL)
overflo("out of space building follow set");
f->re[info(v)].lfollow = p;
*p = setcnt;
@@ -561,7 +561,7 @@ int pmatch(fa *f, const char *p0) /* longest match, for sub */
for (i = 2; i <= f->curstat; i++)
xfree(f->posns[i]);
k = *f->posns[0];
- if ((f->posns[2] = (int *) calloc(1, (k+1)*sizeof(int))) == NULL)
+ if ((f->posns[2] = (int *) calloc(k+1, sizeof(int))) == NULL)
overflo("out of space in pmatch");
for (i = 0; i <= k; i++)
(f->posns[2])[i] = (f->posns[0])[i];
@@ -618,7 +618,7 @@ int nematch(fa *f, const char *p0) /* non-empty match, for sub */
for (i = 2; i <= f->curstat; i++)
xfree(f->posns[i]);
k = *f->posns[0];
- if ((f->posns[2] = (int *) calloc(1, (k+1)*sizeof(int))) == NULL)
+ if ((f->posns[2] = (int *) calloc(k+1, sizeof(int))) == NULL)
overflo("out of state space");
for (i = 0; i <= k; i++)
(f->posns[2])[i] = (f->posns[0])[i];
@@ -1194,7 +1194,7 @@ int cgoto(fa *f, int s, int c)
for (i = 0; i < NCHARS; i++)
f->gototab[f->curstat][i] = 0;
xfree(f->posns[f->curstat]);
- if ((p = (int *) calloc(1, (setcnt+1)*sizeof(int))) == NULL)
+ if ((p = (int *) calloc(setcnt+1, sizeof(int))) == NULL)
overflo("out of space in cgoto");
f->posns[f->curstat] = p;
More information about the dev-commits-src-all
mailing list