diff options
author | pfg <pfg@FreeBSD.org> | 2017-05-07 01:31:42 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2017-05-07 01:31:42 +0000 |
commit | 7a027d3bd08849589328b2a085d33dea2874465a (patch) | |
tree | 4057c07ffd45d6fea0e1912c8f19500125498605 /lib/libc/regex | |
parent | cca5af1b9cc197e4953c52bd73cf0d77e87c7484 (diff) | |
download | FreeBSD-src-7a027d3bd08849589328b2a085d33dea2874465a.zip FreeBSD-src-7a027d3bd08849589328b2a085d33dea2874465a.tar.gz |
MFC r317346:
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
Diffstat (limited to 'lib/libc/regex')
-rw-r--r-- | lib/libc/regex/cname.h | 2 | ||||
-rw-r--r-- | lib/libc/regex/regcomp.c | 23 | ||||
-rw-r--r-- | lib/libc/regex/regerror.c | 10 | ||||
-rw-r--r-- | lib/libc/regex/regex2.h | 12 | ||||
-rw-r--r-- | lib/libc/regex/regexec.c | 6 | ||||
-rw-r--r-- | lib/libc/regex/regfree.c | 2 |
6 files changed, 27 insertions, 28 deletions
diff --git a/lib/libc/regex/cname.h b/lib/libc/regex/cname.h index 7087bcb..d404af0 100644 --- a/lib/libc/regex/cname.h +++ b/lib/libc/regex/cname.h @@ -36,7 +36,7 @@ /* character-name table */ static struct cname { - char *name; + const char *name; char code; } cnames[] = { {"NUL", '\0'}, diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c index a3968cc..dfb02c6 100644 --- a/lib/libc/regex/regcomp.c +++ b/lib/libc/regex/regcomp.c @@ -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; diff --git a/lib/libc/regex/regerror.c b/lib/libc/regex/regerror.c index b9b773c..508c7d5 100644 --- a/lib/libc/regex/regerror.c +++ b/lib/libc/regex/regerror.c @@ -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; diff --git a/lib/libc/regex/regex2.h b/lib/libc/regex/regex2.h index 7aa717e..813bbd3 100644 --- a/lib/libc/regex/regex2.h +++ b/lib/libc/regex/regex2.h @@ -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 */ diff --git a/lib/libc/regex/regexec.c b/lib/libc/regex/regexec.c index 1cf87b8..f4cf8b7 100644 --- a/lib/libc/regex/regexec.c +++ b/lib/libc/regex/regexec.c @@ -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®_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)); } diff --git a/lib/libc/regex/regfree.c b/lib/libc/regex/regfree.c index c979bec..3d301d8 100644 --- a/lib/libc/regex/regfree.c +++ b/lib/libc/regex/regfree.c @@ -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 */ |