aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/regex
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2017-04-23 21:51:29 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2017-04-23 21:51:29 +0000
commit8d0f9a93640f0a522ac6fb844b2d37fa9cad1a25 (patch)
tree2519ceb25cf30780f5e0a3abde1af2620ea5943b /lib/libc/regex
parent6406db24cb8a274cd70b26105b3bb7f9547de65b (diff)
downloadsrc-8d0f9a93640f0a522ac6fb844b2d37fa9cad1a25.tar.gz
src-8d0f9a93640f0a522ac6fb844b2d37fa9cad1a25.zip
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
Notes
Notes: svn path=/head/; revision=317346
Diffstat (limited to 'lib/libc/regex')
-rw-r--r--lib/libc/regex/cname.h2
-rw-r--r--lib/libc/regex/regcomp.c23
-rw-r--r--lib/libc/regex/regerror.c10
-rw-r--r--lib/libc/regex/regex2.h12
-rw-r--r--lib/libc/regex/regexec.c6
-rw-r--r--lib/libc/regex/regfree.c2
6 files changed, 27 insertions, 28 deletions
diff --git a/lib/libc/regex/cname.h b/lib/libc/regex/cname.h
index ba7dd8cb9644..28452c93fe7f 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 95764717bdaf..216cfa2b8c1e 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 253f0b1fb713..8496ba78002a 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 bec1b160cae9..e9e63810cfa8 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 0edfe43dbaba..46b07758eab3 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&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));
}
diff --git a/lib/libc/regex/regfree.c b/lib/libc/regex/regfree.c
index 8a23750ac1cd..296819adfba7 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 */