svn commit: r317894 - stable/11/lib/libc/regex
Pedro F. Giffuni
pfg at FreeBSD.org
Sun May 7 01:31:44 UTC 2017
Author: pfg
Date: Sun May 7 01:31:42 2017
New Revision: 317894
URL: https://svnweb.freebsd.org/changeset/base/317894
Log:
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
Modified:
stable/11/lib/libc/regex/cname.h
stable/11/lib/libc/regex/regcomp.c
stable/11/lib/libc/regex/regerror.c
stable/11/lib/libc/regex/regex2.h
stable/11/lib/libc/regex/regexec.c
stable/11/lib/libc/regex/regfree.c
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/lib/libc/regex/cname.h
==============================================================================
--- stable/11/lib/libc/regex/cname.h Sun May 7 01:28:52 2017 (r317893)
+++ stable/11/lib/libc/regex/cname.h Sun May 7 01:31:42 2017 (r317894)
@@ -36,7 +36,7 @@
/* character-name table */
static struct cname {
- char *name;
+ const char *name;
char code;
} cnames[] = {
{"NUL", '\0'},
Modified: stable/11/lib/libc/regex/regcomp.c
==============================================================================
--- stable/11/lib/libc/regex/regcomp.c Sun May 7 01:28:52 2017 (r317893)
+++ stable/11/lib/libc/regex/regcomp.c Sun May 7 01:31:42 2017 (r317894)
@@ -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 el
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;
Modified: stable/11/lib/libc/regex/regerror.c
==============================================================================
--- stable/11/lib/libc/regex/regerror.c Sun May 7 01:28:52 2017 (r317893)
+++ stable/11/lib/libc/regex/regerror.c Sun May 7 01:31:42 2017 (r317894)
@@ -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
*/
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;
Modified: stable/11/lib/libc/regex/regex2.h
==============================================================================
--- stable/11/lib/libc/regex/regex2.h Sun May 7 01:28:52 2017 (r317893)
+++ stable/11/lib/libc/regex/regex2.h Sun May 7 01:31:42 2017 (r317894)
@@ -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 */
Modified: stable/11/lib/libc/regex/regexec.c
==============================================================================
--- stable/11/lib/libc/regex/regexec.c Sun May 7 01:28:52 2017 (r317893)
+++ stable/11/lib/libc/regex/regexec.c Sun May 7 01:31:42 2017 (r317894)
@@ -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));
}
Modified: stable/11/lib/libc/regex/regfree.c
==============================================================================
--- stable/11/lib/libc/regex/regfree.c Sun May 7 01:28:52 2017 (r317893)
+++ stable/11/lib/libc/regex/regfree.c Sun May 7 01:31:42 2017 (r317894)
@@ -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 */
More information about the svn-src-stable-11
mailing list