reduce casts

This commit is contained in:
christos 2021-02-24 18:13:21 +00:00
parent 25f0c675e7
commit 2cf99de680
5 changed files with 114 additions and 108 deletions

View File

@ -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 @@ matcher(struct re_guts *g,
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 @@ matcher(struct re_guts *g,
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 @@ matcher(struct re_guts *g,
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 @@ done:
m->pmatch = NULL;
}
if (m->lastpos != NULL) {
free((char *)m->lastpos);
free(__UNCONST(m->lastpos));
m->lastpos = NULL;
}
STATETEARDOWN(m);
@ -461,7 +461,7 @@ dissect(
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 @@ dissect(
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 @@ dissect(
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 @@ dissect(
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 @@ backref(
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 @@ backref(
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 @@ backref(
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 @@ backref(
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 @@ backref(
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 @@ walk(struct match *m, const char *start, const char *stop, sopno startst,
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 @@ walk(struct match *m, const char *start, const char *stop, sopno startst,
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 @@ walk(struct match *m, const char *start, const char *stop, sopno startst,
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 @@ step(struct re_guts *g,
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;

View File

@ -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 @@ static char nuls[10]; /* place to point scanner in event of error */
#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 @@ regcomp_internal(regex_t * __restrict preg,
* 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 @@ p_ere_exp(struct parse *p, struct branchc *bc)
int count;
int count2;
#ifdef REGEX_GNU_EXTENSIONS
int i;
size_t i;
int handled;
#endif
sopno subno;
@ -421,7 +421,7 @@ p_ere_exp(struct parse *p, struct branchc *bc)
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 @@ static void
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 @@ p_simp_re(struct parse *p, struct branchc *bc)
int count2;
sopno pos;
bool handled;
int i;
size_t i;
wint_t wc;
sopno subno;
# define BACKSL (1<<CHAR_BIT)
@ -887,7 +887,7 @@ p_simp_re(struct parse *p, struct branchc *bc)
break;
case BACKSL|'(':
p->g->nsub++;
subno = p->g->nsub;
subno = (sopno)p->g->nsub;
if (subno < NPAREN)
p->pbegin[subno] = HERE();
EMIT(OLPAREN, subno);
@ -1053,7 +1053,7 @@ p_bracket(struct parse *p)
ordinary(p, ch);
freeset(p, cs);
} else
EMIT(OANYOF, (int)(cs - p->g->sets));
EMIT(OANYOF, (size_t)(cs - p->g->sets));
}
static int
@ -1189,7 +1189,7 @@ p_b_pseudoclass(struct parse *p, char c) {
return(0);
}
EMIT(OANYOF, (int)(cs - p->g->sets));
EMIT(OANYOF, (size_t)(cs - p->g->sets));
return(1);
}
#endif
@ -1416,8 +1416,8 @@ ordinary(struct parse *p, wint_t ch)
if ((p->g->cflags&REG_ICASE) && iswalpha(ch) && othercase(ch) != ch)
bothcases(p, ch);
else if ((ch & OPDMASK) == ch)
EMIT(OCHAR, ch);
else if ((wint_t)(ch & OPDMASK) == ch)
EMIT(OCHAR, (size_t)ch);
else {
/*
* Kludge: character is too big to fit into an OCHAR operand.
@ -1426,7 +1426,7 @@ ordinary(struct parse *p, wint_t ch)
if ((cs = allocset(p)) == NULL)
return;
CHadd(p, cs, ch);
EMIT(OANYOF, (int)(cs - p->g->sets));
EMIT(OANYOF, (size_t)(cs - p->g->sets));
}
}
@ -1543,7 +1543,7 @@ wgetnext(struct parse *p)
size_t n;
memset(&mbs, 0, sizeof(mbs));
n = mbrtowc(&wc, p->next, p->end - p->next, &mbs);
n = mbrtowc(&wc, p->next, (size_t)(p->end - p->next), &mbs);
if (n == (size_t)-1 || n == (size_t)-2) {
SETERROR(REG_ILLSEQ);
return (0);
@ -1652,7 +1652,7 @@ CHadd(struct parse *p, cset *cs, wint_t ch)
assert(ch >= 0);
if (ch < NC)
cs->bmp[ch >> 3] |= 1 << (ch & 7);
cs->bmp[(unsigned)ch >> 3] |= 1 << (ch & 7);
else {
newwides = reallocarray(cs->wides, cs->nwides + 1,
sizeof(*cs->wides));
@ -1665,9 +1665,9 @@ CHadd(struct parse *p, cset *cs, wint_t ch)
}
if (cs->icase) {
if ((nch = towlower(ch)) < NC)
cs->bmp[nch >> 3] |= 1 << (nch & 7);
cs->bmp[(unsigned)nch >> 3] |= 1 << (nch & 7);
if ((nch = towupper(ch)) < NC)
cs->bmp[nch >> 3] |= 1 << (nch & 7);
cs->bmp[(unsigned)nch >> 3] |= 1 << (nch & 7);
}
}
@ -1742,8 +1742,8 @@ dupl(struct parse *p,
return(ret);
if (!enlarge(p, p->ssize + len)) /* this many unexpected additions */
return(ret);
(void) memcpy((char *)(p->strip + p->slen),
(char *)(p->strip + start), (size_t)len*sizeof(sop));
(void) memcpy(p->strip + p->slen,
p->strip + start, len * sizeof(*p->strip));
p->slen += len;
return(ret);
}
@ -1774,7 +1774,7 @@ doemit(struct parse *p, sop op, size_t opnd)
return;
/* finally, it's all reduced to the easy case */
p->strip[p->slen++] = SOP(op, opnd);
p->strip[p->slen++] = (sopno)SOP(op, opnd);
}
/*
@ -1810,8 +1810,8 @@ doinsert(struct parse *p, sop op, size_t opnd, sopno pos)
}
}
memmove((char *)&p->strip[pos+1], (char *)&p->strip[pos],
(HERE()-pos-1)*sizeof(sop));
memmove(&p->strip[pos+1], &p->strip[pos],
(HERE()-pos-1)*sizeof(*p->strip));
p->strip[pos] = s;
}
@ -1847,7 +1847,7 @@ enlarge(struct parse *p, sopno size)
if (p->ssize >= size)
return 1;
sp = reallocarray(p->strip, size, sizeof(sop));
sp = reallocarray(p->strip, size, sizeof(*p->strip));
if (sp == NULL) {
SETERROR(REG_ESPACE);
return 0;
@ -1869,7 +1869,7 @@ stripsnug(struct parse *p, struct re_guts *g)
_DIAGASSERT(g != NULL);
g->nstates = p->slen;
g->strip = reallocarray((char *)p->strip, p->slen, sizeof(sop));
g->strip = reallocarray(p->strip, p->slen, sizeof(*p->strip));
if (g->strip == NULL) {
SETERROR(REG_ESPACE);
g->strip = p->strip;
@ -1931,10 +1931,10 @@ findmust(struct parse *p, struct re_guts *g)
memset(&mbs, 0, sizeof(mbs));
newstart = scan - 1;
}
clen = wcrtomb(buf, OPND(s), &mbs);
clen = wcrtomb(buf, (int)OPND(s), &mbs);
if (clen == (size_t)-1)
goto toohard;
newlen += clen;
newlen += (sopno)clen;
break;
case OPLUS_: /* things that don't break one */
case OLPAREN:
@ -1948,12 +1948,12 @@ findmust(struct parse *p, struct re_guts *g)
scan += OPND(s);
s = *scan;
/* assert() interferes w debug printouts */
if (OP(s) != (sop)O_QUEST &&
OP(s) != (sop)O_CH && OP(s) != (sop)OOR2) {
if (OP(s) != O_QUEST &&
OP(s) != O_CH && OP(s) != OOR2) {
g->iflags |= BAD;
return;
}
} while (OP(s) != (sop)O_QUEST && OP(s) != (sop)O_CH);
} while (OP(s) != O_QUEST && OP(s) != O_CH);
/* FALLTHROUGH */
case OBOW: /* things that break a sequence */
case OEOW:
@ -2015,7 +2015,7 @@ findmust(struct parse *p, struct re_guts *g)
offset++;
newlen = 0;
break;
toohard:
toohard:/*FALLTHROUGH*/
default:
/* Anything here makes it impossible or too hard
* to calculate the offset -- so we give up;
@ -2054,7 +2054,7 @@ findmust(struct parse *p, struct re_guts *g)
while (cp < g->must + g->mlen) {
while (OP(s = *scan++) != OCHAR)
continue;
clen = wcrtomb(cp, OPND(s), &mbs);
clen = wcrtomb(cp, (int)OPND(s), &mbs);
assert(clen != (size_t)-1);
cp += clen;
}
@ -2085,7 +2085,7 @@ altoffset(sop *scan, int offset)
largest = 0;
try = 0;
s = *scan++;
while (OP(s) != (sop)O_QUEST && OP(s) != (sop)O_CH) {
while (OP(s) != O_QUEST && OP(s) != O_CH) {
switch (OP(s)) {
case OOR1:
if (try > largest)
@ -2101,10 +2101,10 @@ altoffset(sop *scan, int offset)
do {
scan += OPND(s);
s = *scan;
if (OP(s) != (sop)O_QUEST &&
OP(s) != (sop)O_CH && OP(s) != (sop)OOR2)
if (OP(s) != O_QUEST &&
OP(s) != O_CH && OP(s) != OOR2)
return -1;
} while (OP(s) != (sop)O_QUEST && OP(s) != (sop)O_CH);
} while (OP(s) != O_QUEST && OP(s) != O_CH);
/* We must skip to the next position, or we'll
* leave altoffset() too early.
*/
@ -2114,6 +2114,7 @@ altoffset(sop *scan, int offset)
case OCHAR:
case OANY:
try++;
/*FALLTHROUGH*/
case OBOW:
case OEOW:
case OWBND:

View File

@ -1,4 +1,4 @@
/* $NetBSD: regex2.h,v 1.14 2021/02/23 22:14:59 christos Exp $ */
/* $NetBSD: regex2.h,v 1.15 2021/02/24 18:13:21 christos Exp $ */
/*-
* SPDX-License-Identifier: BSD-3-Clause
@ -76,40 +76,40 @@
* In state representations, an operator's bit is on to signify a state
* immediately *preceding* "execution" of that operator.
*/
typedef unsigned long sop; /* strip operator */
typedef unsigned long sopno;
#define OPRMASK 0xf8000000L
#define OPDMASK 0x07ffffffL
#define OPSHIFT ((unsigned)27)
typedef uint32_t sop; /* strip operator */
typedef uint32_t sopno;
#define OPRMASK 0xf8000000U
#define OPDMASK 0x07ffffffU
#define OPSHIFT (27U)
#define OP(n) ((n)&OPRMASK)
#define OPND(n) ((n)&OPDMASK)
#define SOP(op, opnd) ((op)|(opnd))
/* operators meaning operand */
/* (back, fwd are offsets) */
#define OEND (1L<<OPSHIFT) /* endmarker - */
#define OCHAR (2L<<OPSHIFT) /* character wide character */
#define OBOL (3L<<OPSHIFT) /* left anchor - */
#define OEOL (4L<<OPSHIFT) /* right anchor - */
#define OANY (5L<<OPSHIFT) /* . - */
#define OANYOF (6L<<OPSHIFT) /* [...] set number */
#define OBACK_ (7L<<OPSHIFT) /* begin \d paren number */
#define O_BACK (8L<<OPSHIFT) /* end \d paren number */
#define OPLUS_ (9L<<OPSHIFT) /* + prefix fwd to suffix */
#define O_PLUS (10L<<OPSHIFT) /* + suffix back to prefix */
#define OQUEST_ (11L<<OPSHIFT) /* ? prefix fwd to suffix */
#define O_QUEST (12L<<OPSHIFT) /* ? suffix back to prefix */
#define OLPAREN (13L<<OPSHIFT) /* ( fwd to ) */
#define ORPAREN (14L<<OPSHIFT) /* ) back to ( */
#define OCH_ (15L<<OPSHIFT) /* begin choice fwd to OOR2 */
#define OOR1 (16L<<OPSHIFT) /* | pt. 1 back to OOR1 or OCH_ */
#define OOR2 (17L<<OPSHIFT) /* | pt. 2 fwd to OOR2 or O_CH */
#define O_CH (18L<<OPSHIFT) /* end choice back to OOR1 */
#define OBOW (19L<<OPSHIFT) /* begin word - */
#define OEOW (20L<<OPSHIFT) /* end word - */
#define OBOS (21L<<OPSHIFT) /* begin subj. - */
#define OEOS (22L<<OPSHIFT) /* end subj. - */
#define OWBND (23L<<OPSHIFT) /* word bound - */
#define ONWBND (24L<<OPSHIFT) /* not bound - */
#define OEND (1U<<OPSHIFT) /* endmarker - */
#define OCHAR (2U<<OPSHIFT) /* character wide character */
#define OBOL (3U<<OPSHIFT) /* left anchor - */
#define OEOL (4U<<OPSHIFT) /* right anchor - */
#define OANY (5U<<OPSHIFT) /* . - */
#define OANYOF (6U<<OPSHIFT) /* [...] set number */
#define OBACK_ (7U<<OPSHIFT) /* begin \d paren number */
#define O_BACK (8U<<OPSHIFT) /* end \d paren number */
#define OPLUS_ (9U<<OPSHIFT) /* + prefix fwd to suffix */
#define O_PLUS (10U<<OPSHIFT) /* + suffix back to prefix */
#define OQUEST_ (11U<<OPSHIFT) /* ? prefix fwd to suffix */
#define O_QUEST (12U<<OPSHIFT) /* ? suffix back to prefix */
#define OLPAREN (13U<<OPSHIFT) /* ( fwd to ) */
#define ORPAREN (14U<<OPSHIFT) /* ) back to ( */
#define OCH_ (15U<<OPSHIFT) /* begin choice fwd to OOR2 */
#define OOR1 (16U<<OPSHIFT) /* | pt. 1 back to OOR1 or OCH_ */
#define OOR2 (17U<<OPSHIFT) /* | pt. 2 fwd to OOR2 or O_CH */
#define O_CH (18U<<OPSHIFT) /* end choice back to OOR1 */
#define OBOW (19U<<OPSHIFT) /* begin word - */
#define OEOW (20U<<OPSHIFT) /* end word - */
#define OBOS (21U<<OPSHIFT) /* begin subj. - */
#define OEOS (22U<<OPSHIFT) /* end subj. - */
#define OWBND (23U<<OPSHIFT) /* word bound - */
#define ONWBND (24U<<OPSHIFT) /* not bound - */
/*
* Structures for [] character-set representation.
@ -137,7 +137,7 @@ CHIN1(cset *cs, wint_t ch)
assert(ch >= 0);
if (ch < NC)
return (((cs->bmp[ch >> 3] & (1 << (ch & 7))) != 0) ^
return (((cs->bmp[(unsigned)ch >> 3] & (1 << (ch & 7))) != 0) ^
cs->invert);
for (i = 0; i < cs->nwides; i++) {
if (cs->icase) {
@ -162,7 +162,7 @@ CHIN(cset *cs, wint_t ch)
assert(ch >= 0);
if (ch < NC)
return (((cs->bmp[ch >> 3] & (1 << (ch & 7))) != 0) ^
return (((cs->bmp[(unsigned)ch >> 3] & (1 << (ch & 7))) != 0) ^
cs->invert);
else if (cs->icase)
return (CHIN1(cs, ch) || CHIN1(cs, towlower(ch)) ||

View File

@ -1,4 +1,4 @@
/* $NetBSD: regexec.c,v 1.23 2021/02/23 22:14:59 christos Exp $ */
/* $NetBSD: regexec.c,v 1.24 2021/02/24 18:13:21 christos Exp $ */
/*-
* SPDX-License-Identifier: BSD-3-Clause
@ -42,7 +42,7 @@
static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
__FBSDID("$FreeBSD: head/lib/libc/regex/regexec.c 326025 2017-11-20 19:49:47Z pfg $");
#endif
__RCSID("$NetBSD: regexec.c,v 1.23 2021/02/23 22:14:59 christos Exp $");
__RCSID("$NetBSD: regexec.c,v 1.24 2021/02/24 18:13:21 christos Exp $");
/*
* the outer shell of regexec()
@ -70,8 +70,6 @@ __weak_alias(regexec,_regexec)
#include "utils.h"
#include "regex2.h"
static int nope __unused = 0; /* for use in asserts; shuts lint up */
static __inline size_t
xmbrtowc(wint_t *wi, const char *s, size_t n, mbstate_t *mbs, wint_t dummy)
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: regfree.c,v 1.16 2021/02/23 22:14:59 christos Exp $ */
/* $NetBSD: regfree.c,v 1.17 2021/02/24 18:13:21 christos Exp $ */
/*-
* SPDX-License-Identifier: BSD-3-Clause
@ -42,7 +42,7 @@
static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94";
__FBSDID("$FreeBSD: head/lib/libc/regex/regfree.c 326025 2017-11-20 19:49:47Z pfg $");
#endif
__RCSID("$NetBSD: regfree.c,v 1.16 2021/02/23 22:14:59 christos Exp $");
__RCSID("$NetBSD: regfree.c,v 1.17 2021/02/24 18:13:21 christos Exp $");
#include "namespace.h"
#include <sys/types.h>
@ -83,14 +83,14 @@ regfree(regex_t *preg)
g->magic = 0; /* mark it invalid */
if (g->strip != NULL)
free((char *)g->strip);
free(g->strip);
if (g->sets != NULL) {
for (i = 0; i < g->ncsets; i++) {
free(g->sets[i].ranges);
free(g->sets[i].wides);
free(g->sets[i].types);
}
free((char *)g->sets);
free(g->sets);
}
if (g->must != NULL)
free(g->must);
@ -98,5 +98,5 @@ regfree(regex_t *preg)
free(&g->charjump[CHAR_MIN]);
if (g->matchjump != NULL)
free(g->matchjump);
free((char *)g);
free(g);
}