Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/regex reduce casts
details: https://anonhg.NetBSD.org/src/rev/af720f2aacf6
branches: trunk
changeset: 959780:af720f2aacf6
user: christos <christos%NetBSD.org@localhost>
date: Wed Feb 24 18:13:21 2021 +0000
description:
reduce casts
diffstat:
lib/libc/regex/engine.c | 61 ++++++++++++++++++++----------------
lib/libc/regex/regcomp.c | 81 ++++++++++++++++++++++++-----------------------
lib/libc/regex/regex2.h | 64 ++++++++++++++++++------------------
lib/libc/regex/regexec.c | 6 +--
lib/libc/regex/regfree.c | 10 ++--
5 files changed, 114 insertions(+), 108 deletions(-)
diffs (truncated from 674 to 300 lines):
diff -r 535f70aa15ee -r af720f2aacf6 lib/libc/regex/engine.c
--- a/lib/libc/regex/engine.c Wed Feb 24 17:35:39 2021 +0000
+++ b/lib/libc/regex/engine.c Wed Feb 24 18:13:21 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: engine.c,v 1.26 2021/02/24 09:10:12 wiz Exp $ */
+/* $NetBSD: engine.c,v 1.27 2021/02/24 18:13:21 christos Exp $ */
/*-
* SPDX-License-Identifier: BSD-3-Clause
@@ -41,7 +41,7 @@
#ifdef __FBSDID
__FBSDID("$FreeBSD: head/lib/libc/regex/engine.c 368358 2020-12-05 03:16:05Z kevans $");
#endif
-__RCSID("$NetBSD: engine.c,v 1.26 2021/02/24 09:10:12 wiz Exp $");
+__RCSID("$NetBSD: engine.c,v 1.27 2021/02/24 18:13:21 christos Exp $");
#include <stdbool.h>
@@ -210,7 +210,7 @@
const char *stop;
/* Boyer-Moore algorithms variables */
const char *pp;
- int cj, mj;
+ size_t cj, mj;
const char *mustfirst;
const char *mustlast;
size_t *matchjump;
@@ -325,7 +325,7 @@
break;
assert(m->coldp < m->endp);
m->coldp += XMBRTOWC(NULL, m->coldp,
- m->endp - m->coldp, &m->mbs, 0);
+ (size_t)(m->endp - m->coldp), &m->mbs, 0);
}
if (nmatch == 1 && !g->backrefs)
break; /* no further info needed */
@@ -385,7 +385,7 @@
NOTE("false alarm");
/* recycle starting later */
start = m->coldp + XMBRTOWC(NULL, m->coldp,
- stop - m->coldp, &m->mbs, 0);
+ (size_t)(stop - m->coldp), &m->mbs, 0);
assert(start <= stop);
}
@@ -412,7 +412,7 @@
m->pmatch = NULL;
}
if (m->lastpos != NULL) {
- free((char *)m->lastpos);
+ free(__UNCONST(m->lastpos));
m->lastpos = NULL;
}
STATETEARDOWN(m);
@@ -461,7 +461,7 @@
es += OPND(m->g->strip[es]);
break;
case OCH_:
- while (OP(m->g->strip[es]) != (sop)O_CH)
+ while (OP(m->g->strip[es]) != O_CH)
es += OPND(m->g->strip[es]);
break;
}
@@ -473,7 +473,8 @@
assert(nope);
break;
case OCHAR:
- sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0);
+ sp += XMBRTOWC(NULL, sp, (size_t)(stop - start),
+ &m->mbs, 0);
break;
case OBOL:
case OEOL:
@@ -486,7 +487,8 @@
break;
case OANY:
case OANYOF:
- sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0);
+ sp += XMBRTOWC(NULL, sp, (size_t)(stop - start),
+ &m->mbs, 0);
break;
case OBACK_:
case O_BACK:
@@ -579,7 +581,7 @@
assert(OP(m->g->strip[esub]) == OOR2);
ssub = esub + 1;
esub += OPND(m->g->strip[esub]);
- if (OP(m->g->strip[esub]) == (sop)OOR2)
+ if (OP(m->g->strip[esub]) == OOR2)
esub--;
else
assert(OP(m->g->strip[esub]) == O_CH);
@@ -669,14 +671,16 @@
case OCHAR:
if (sp == stop)
return(NULL);
- sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
+ sp += XMBRTOWC(&wc, sp, (size_t)(stop - sp),
+ &m->mbs, BADCHAR);
if (wc != (wint_t)OPND(s))
return(NULL);
break;
case OANY:
if (sp == stop)
return(NULL);
- sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
+ sp += XMBRTOWC(&wc, sp, (size_t)(stop - sp),
+ &m->mbs, BADCHAR);
if (wc == BADCHAR)
return (NULL);
break;
@@ -684,7 +688,8 @@
if (sp == stop)
return (NULL);
cs = &m->g->sets[OPND(s)];
- sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
+ sp += XMBRTOWC(&wc, sp, (size_t)(stop - sp),
+ &m->mbs, BADCHAR);
if (wc == BADCHAR || !CHIN(cs, wc))
return(NULL);
break;
@@ -751,7 +756,7 @@
do {
assert(OP(s) == OOR2);
ss += OPND(s);
- } while (OP(s = m->g->strip[ss]) != (sop)O_CH);
+ } while (OP(s = m->g->strip[ss]) != O_CH);
/* note that the ss++ gets us past the O_CH */
break;
default: /* have to make a choice */
@@ -784,7 +789,7 @@
ssp = m->offp + m->pmatch[i].rm_so;
if (memcmp(sp, ssp, len) != 0)
return(NULL);
- while (m->g->strip[ss] != (sop)SOP(O_BACK, i))
+ while (m->g->strip[ss] != SOP(O_BACK, i))
ss++;
return(backref(m, sp+len, stop, ss+1, stopst, lev, rec));
case OQUEST_: /* to null or not */
@@ -816,13 +821,13 @@
if (dp != NULL)
return(dp);
/* that one missed, try next one */
- if (OP(m->g->strip[esub]) == (sop)O_CH)
+ if (OP(m->g->strip[esub]) == O_CH)
return(NULL); /* there is none */
esub++;
- assert(OP(m->g->strip[esub]) == (sop)OOR2);
+ assert(OP(m->g->strip[esub]) == OOR2);
ssub = esub + 1;
esub += OPND(m->g->strip[esub]);
- if (OP(m->g->strip[esub]) == (sop)OOR2)
+ if (OP(m->g->strip[esub]) == OOR2)
esub--;
else
assert(OP(m->g->strip[esub]) == O_CH);
@@ -877,9 +882,9 @@
wint_t c;
wint_t lastc; /* previous c */
wint_t flagch;
- int i, sflags;
+ int sflags;
const char *matchp; /* last p at which a match ended */
- size_t clen;
+ size_t i, clen;
_DIAGASSERT(m != NULL);
_DIAGASSERT(start != NULL);
@@ -912,7 +917,8 @@
c = OUT;
clen = 0;
} else
- clen = XMBRTOWC(&c, p, m->endp - p, &m->mbs, BADCHAR);
+ clen = XMBRTOWC(&c, p, (size_t)(m->endp - p),
+ &m->mbs, BADCHAR);
if (fast && EQ(st, fresh))
matchp = p;
@@ -1000,7 +1006,8 @@
assert(matchp != NULL);
m->coldp = matchp;
if (ISSET(st, stopst))
- return (p + XMBRTOWC(NULL, p, stop - p, &m->mbs, 0));
+ return (p + XMBRTOWC(NULL, p, (size_t)(stop - p),
+ &m->mbs, 0));
else
return (NULL);
} else
@@ -1121,22 +1128,22 @@
break;
case OCH_: /* mark the first two branches */
FWD(aft, aft, 1);
- assert(OP(g->strip[pc+OPND(s)]) == (sop)OOR2);
+ assert(OP(g->strip[pc+OPND(s)]) == OOR2);
FWD(aft, aft, OPND(s));
break;
case OOR1: /* done a branch, find the O_CH */
if (ISSTATEIN(aft, here)) {
for (look = 1;
- OP(s = g->strip[pc+look]) != (sop)O_CH;
+ OP(s = g->strip[pc+look]) != O_CH;
look += OPND(s))
- assert(OP(s) == (sop)OOR2);
+ assert(OP(s) == OOR2);
FWD(aft, aft, look + 1);
}
break;
case OOR2: /* propagate OCH_'s marking */
FWD(aft, aft, 1);
- if (OP(g->strip[pc+OPND(s)]) != (sop)O_CH) {
- assert(OP(g->strip[pc+OPND(s)]) == (sop)OOR2);
+ if (OP(g->strip[pc+OPND(s)]) != O_CH) {
+ assert(OP(g->strip[pc+OPND(s)]) == OOR2);
FWD(aft, aft, OPND(s));
}
break;
diff -r 535f70aa15ee -r af720f2aacf6 lib/libc/regex/regcomp.c
--- a/lib/libc/regex/regcomp.c Wed Feb 24 17:35:39 2021 +0000
+++ b/lib/libc/regex/regcomp.c Wed Feb 24 18:13:21 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: regcomp.c,v 1.39 2021/02/23 22:14:59 christos Exp $ */
+/* $NetBSD: regcomp.c,v 1.40 2021/02/24 18:13:21 christos Exp $ */
/*-
* SPDX-License-Identifier: BSD-3-Clause
@@ -47,7 +47,7 @@
static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94";
__FBSDID("$FreeBSD: head/lib/libc/regex/regcomp.c 368359 2020-12-05 03:18:48Z kevans $");
#endif
-__RCSID("$NetBSD: regcomp.c,v 1.39 2021/02/23 22:14:59 christos Exp $");
+__RCSID("$NetBSD: regcomp.c,v 1.40 2021/02/24 18:13:21 christos Exp $");
#define _OPENBSD_SOURCE
#define REGEX_GNU_EXTENSIONS
@@ -208,8 +208,8 @@
#define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e))
#define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e))
#define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e))
-#define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd))
-#define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
+#define EMIT(op, sopnd) doemit(p, (op), (sopnd))
+#define INSERT(op, pos) doinsert(p, (op), HERE()-(pos)+1, pos)
#define AHEAD(pos) dofwd(p, pos, HERE()-(pos))
#define ASTERN(sop, pos) EMIT(sop, HERE()-pos)
#define HERE() (p->slen)
@@ -264,18 +264,18 @@
* generically (who are we to stop people from using ~715MB+
* patterns?).
*/
- maxlen = ((size_t)-1 >> 1) / sizeof(sop) * 2 / 3;
+ maxlen = ((size_t)-1 >> 1) / sizeof(*p->strip) * 2 / 3;
if (len >= maxlen) {
- free((char *)g);
+ free(g);
return(REG_ESPACE);
}
- p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */
+ p->ssize = (sopno)(len / 2 * 3 + 1); /* ugh */
assert(p->ssize >= len);
p->strip = calloc(p->ssize, sizeof(*p->strip));
p->slen = 0;
if (p->strip == NULL) {
- free((char *)g);
+ free(g);
return(REG_ESPACE);
}
@@ -401,7 +401,7 @@
int count;
int count2;
#ifdef REGEX_GNU_EXTENSIONS
- int i;
+ size_t i;
int handled;
#endif
sopno subno;
@@ -421,7 +421,7 @@
case '(':
(void)REQUIRE(MORE(), REG_EPAREN);
p->g->nsub++;
- subno = p->g->nsub;
+ subno = (sopno)p->g->nsub;
if (subno < NPAREN)
p->pbegin[subno] = HERE();
EMIT(OLPAREN, subno);
@@ -727,7 +727,7 @@
p_bre_pre_parse(struct parse *p, struct branchc *bc)
{
- (void) bc;
+ (void)bc;
/*
* Does not move cleanly into expression parser because of
* ordinary interpration of * at the beginning position of
@@ -823,7 +823,7 @@
int count2;
sopno pos;
bool handled;
- int i;
Home |
Main Index |
Thread Index |
Old Index