regex: unsign and constify some variables.

Taking some hints from the regex variant in nvi(1) and higher-level
compiler warnings, update some types in our regex(3) implementation.

Joint work with:	Kyle Evans
MFC after:		2 weeks
This commit is contained in:
Pedro F. Giffuni 2017-04-23 21:51:29 +00:00
parent 6406db24cb
commit 8d0f9a9364
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=317346
6 changed files with 27 additions and 28 deletions

View File

@ -36,7 +36,7 @@
/* character-name table */
static struct cname {
char *name;
const char *name;
char code;
} cnames[] = {
{"NUL", '\0'},

View File

@ -66,8 +66,8 @@ __FBSDID("$FreeBSD$");
* other clumsinesses
*/
struct parse {
char *next; /* next character in RE */
char *end; /* end of string (-> NUL normally) */
const char *next; /* next character in RE */
const char *end; /* end of string (-> NUL normally) */
int error; /* has an error been seen? */
sop *strip; /* malloced strip */
sopno ssize; /* malloced strip size (allocated) */
@ -207,7 +207,7 @@ regcomp(regex_t * __restrict preg,
return(REG_INVARG);
len = preg->re_endp - pattern;
} else
len = strlen((char *)pattern);
len = strlen(pattern);
/* do the mallocs early so failure handling is easy */
g = (struct re_guts *)malloc(sizeof(struct re_guts));
@ -239,7 +239,7 @@ regcomp(regex_t * __restrict preg,
/* set things up */
p->g = g;
p->next = (char *)pattern; /* convenience; we do not modify it */
p->next = pattern; /* convenience; we do not modify it */
p->end = p->next + len;
p->error = 0;
p->ncsalloc = 0;
@ -840,7 +840,7 @@ p_b_term(struct parse *p, cset *cs)
static void
p_b_cclass(struct parse *p, cset *cs)
{
char *sp = p->next;
const char *sp = p->next;
size_t len;
wctype_t wct;
char clname[16];
@ -903,12 +903,11 @@ static wint_t /* value of collating element */
p_b_coll_elem(struct parse *p,
wint_t endc) /* name ended by endc,']' */
{
char *sp = p->next;
const char *sp = p->next;
struct cname *cp;
int len;
mbstate_t mbs;
wchar_t wc;
size_t clen;
size_t clen, len;
while (MORE() && !SEETWO(endc, ']'))
NEXT();
@ -955,8 +954,8 @@ othercase(wint_t ch)
static void
bothcases(struct parse *p, wint_t ch)
{
char *oldnext = p->next;
char *oldend = p->end;
const char *oldnext = p->next;
const char *oldend = p->end;
char bracket[3 + MB_LEN_MAX];
size_t n;
mbstate_t mbs;
@ -1009,8 +1008,8 @@ ordinary(struct parse *p, wint_t ch)
static void
nonnewline(struct parse *p)
{
char *oldnext = p->next;
char *oldend = p->end;
const char *oldnext = p->next;
const char *oldend = p->end;
char bracket[4];
p->next = bracket;

View File

@ -54,7 +54,7 @@ extern "C" {
#endif
/* === regerror.c === */
static char *regatoi(const regex_t *preg, char *localbuf);
static const char *regatoi(const regex_t *preg, char *localbuf);
#ifdef __cplusplus
}
@ -83,8 +83,8 @@ static char *regatoi(const regex_t *preg, char *localbuf);
*/
static struct rerr {
int code;
char *name;
char *explain;
const char *name;
const char *explain;
} rerrs[] = {
{REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match"},
{REG_BADPAT, "REG_BADPAT", "invalid regular expression"},
@ -120,7 +120,7 @@ regerror(int errcode,
struct rerr *r;
size_t len;
int target = errcode &~ REG_ITOA;
char *s;
const char *s;
char convbuf[50];
if (errcode == REG_ATOI)
@ -158,7 +158,7 @@ regerror(int errcode,
- regatoi - internal routine to implement REG_ATOI
== static char *regatoi(const regex_t *preg, char *localbuf);
*/
static char *
static const char *
regatoi(const regex_t *preg, char *localbuf)
{
struct rerr *r;

View File

@ -73,7 +73,7 @@
* immediately *preceding* "execution" of that operator.
*/
typedef unsigned long sop; /* strip operator */
typedef long sopno;
typedef unsigned long sopno;
#define OPRMASK 0xf8000000L
#define OPDMASK 0x07ffffffL
#define OPSHIFT ((unsigned)27)
@ -113,11 +113,11 @@ typedef struct {
typedef struct {
unsigned char bmp[NC / 8];
wctype_t *types;
int ntypes;
unsigned int ntypes;
wint_t *wides;
int nwides;
unsigned int nwides;
crange *ranges;
int nranges;
unsigned int nranges;
int invert;
int icase;
} cset;
@ -125,7 +125,7 @@ typedef struct {
static int
CHIN1(cset *cs, wint_t ch)
{
int i;
unsigned int i;
assert(ch >= 0);
if (ch < NC)
@ -165,7 +165,7 @@ struct re_guts {
int magic;
# define MAGIC2 ((('R'^0200)<<8)|'E')
sop *strip; /* malloced area for strip */
int ncsets; /* number of csets in use */
unsigned int ncsets; /* number of csets in use */
cset *sets; /* -> cset [ncsets] */
int cflags; /* copy of regcomp() cflags argument */
sopno nstates; /* = number of sops */

View File

@ -225,9 +225,9 @@ regexec(const regex_t * __restrict preg,
eflags = GOODFLAGS(eflags);
if (MB_CUR_MAX > 1)
return(mmatcher(g, (char *)string, nmatch, pmatch, eflags));
return(mmatcher(g, string, nmatch, pmatch, eflags));
else if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags&REG_LARGE))
return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
return(smatcher(g, string, nmatch, pmatch, eflags));
else
return(lmatcher(g, (char *)string, nmatch, pmatch, eflags));
return(lmatcher(g, string, nmatch, pmatch, eflags));
}

View File

@ -58,7 +58,7 @@ void
regfree(regex_t *preg)
{
struct re_guts *g;
int i;
unsigned int i;
if (preg->re_magic != MAGIC1) /* oops */
return; /* nice to complain, but hard */