diff options
author | pfg <pfg@FreeBSD.org> | 2017-04-07 16:08:04 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2017-04-07 16:08:04 +0000 |
commit | feaeb09c7553a3cb3242f6be7b39a5f4b4d5a3e7 (patch) | |
tree | 9779b1eeb4a9a1f1c6fccb20ee1fb04a426efb9d /lib/libc/regex | |
parent | 7317fc9c0522c902a4a0a67b17c5c5d25d04bff9 (diff) | |
download | FreeBSD-src-feaeb09c7553a3cb3242f6be7b39a5f4b4d5a3e7.zip FreeBSD-src-feaeb09c7553a3cb3242f6be7b39a5f4b4d5a3e7.tar.gz |
MFC r315162:
libc: provide some bounds-checking through reallocarray(3).
reallocarray(3) is a non portable extension that originated in OpenBSD.
Given that it is already in FreeBSD's libc it is useful for the cases
where reallocation involves a multiplication.
Diffstat (limited to 'lib/libc/regex')
-rw-r--r-- | lib/libc/regex/regcomp.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c index b2b1255..a3968cc 100644 --- a/lib/libc/regex/regcomp.c +++ b/lib/libc/regex/regcomp.c @@ -1143,7 +1143,7 @@ allocset(struct parse *p) { cset *cs, *ncs; - ncs = realloc(p->g->sets, (p->g->ncsets + 1) * sizeof(*ncs)); + ncs = reallocarray(p->g->sets, p->g->ncsets + 1, sizeof(*ncs)); if (ncs == NULL) { SETERROR(REG_ESPACE); return (NULL); @@ -1206,7 +1206,7 @@ CHadd(struct parse *p, cset *cs, wint_t ch) if (ch < NC) cs->bmp[ch >> 3] |= 1 << (ch & 7); else { - newwides = realloc(cs->wides, (cs->nwides + 1) * + newwides = reallocarray(cs->wides, cs->nwides + 1, sizeof(*cs->wides)); if (newwides == NULL) { SETERROR(REG_ESPACE); @@ -1235,7 +1235,7 @@ CHaddrange(struct parse *p, cset *cs, wint_t min, wint_t max) CHadd(p, cs, min); if (min >= max) return; - newranges = realloc(cs->ranges, (cs->nranges + 1) * + newranges = reallocarray(cs->ranges, cs->nranges + 1, sizeof(*cs->ranges)); if (newranges == NULL) { SETERROR(REG_ESPACE); @@ -1259,7 +1259,7 @@ CHaddtype(struct parse *p, cset *cs, wctype_t wct) for (i = 0; i < NC; i++) if (iswctype(i, wct)) CHadd(p, cs, i); - newtypes = realloc(cs->types, (cs->ntypes + 1) * + newtypes = reallocarray(cs->types, cs->ntypes + 1, sizeof(*cs->types)); if (newtypes == NULL) { SETERROR(REG_ESPACE); @@ -1382,7 +1382,7 @@ enlarge(struct parse *p, sopno size) if (p->ssize >= size) return 1; - sp = (sop *)realloc(p->strip, size*sizeof(sop)); + sp = reallocarray(p->strip, size, sizeof(sop)); if (sp == NULL) { SETERROR(REG_ESPACE); return 0; @@ -1400,7 +1400,7 @@ static void stripsnug(struct parse *p, struct re_guts *g) { g->nstates = p->slen; - g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop)); + g->strip = reallocarray((char *)p->strip, p->slen, sizeof(sop)); if (g->strip == NULL) { SETERROR(REG_ESPACE); g->strip = p->strip; |