Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Apr 2017 21:51:29 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r317346 - head/lib/libc/regex
Message-ID:  <201704232151.v3NLpTK0002095@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Sun Apr 23 21:51:29 2017
New Revision: 317346
URL: https://svnweb.freebsd.org/changeset/base/317346

Log:
  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

Modified:
  head/lib/libc/regex/cname.h
  head/lib/libc/regex/regcomp.c
  head/lib/libc/regex/regerror.c
  head/lib/libc/regex/regex2.h
  head/lib/libc/regex/regexec.c
  head/lib/libc/regex/regfree.c

Modified: head/lib/libc/regex/cname.h
==============================================================================
--- head/lib/libc/regex/cname.h	Sun Apr 23 21:51:28 2017	(r317345)
+++ head/lib/libc/regex/cname.h	Sun Apr 23 21:51:29 2017	(r317346)
@@ -36,7 +36,7 @@
 
 /* character-name table */
 static struct cname {
-	char *name;
+	const char *name;
 	char code;
 } cnames[] = {
 	{"NUL",			'\0'},

Modified: head/lib/libc/regex/regcomp.c
==============================================================================
--- head/lib/libc/regex/regcomp.c	Sun Apr 23 21:51:28 2017	(r317345)
+++ head/lib/libc/regex/regcomp.c	Sun Apr 23 21:51:29 2017	(r317346)
@@ -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: head/lib/libc/regex/regerror.c
==============================================================================
--- head/lib/libc/regex/regerror.c	Sun Apr 23 21:51:28 2017	(r317345)
+++ head/lib/libc/regex/regerror.c	Sun Apr 23 21:51:29 2017	(r317346)
@@ -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: head/lib/libc/regex/regex2.h
==============================================================================
--- head/lib/libc/regex/regex2.h	Sun Apr 23 21:51:28 2017	(r317345)
+++ head/lib/libc/regex/regex2.h	Sun Apr 23 21:51:29 2017	(r317346)
@@ -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: head/lib/libc/regex/regexec.c
==============================================================================
--- head/lib/libc/regex/regexec.c	Sun Apr 23 21:51:28 2017	(r317345)
+++ head/lib/libc/regex/regexec.c	Sun Apr 23 21:51:29 2017	(r317346)
@@ -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));
 }

Modified: head/lib/libc/regex/regfree.c
==============================================================================
--- head/lib/libc/regex/regfree.c	Sun Apr 23 21:51:28 2017	(r317345)
+++ head/lib/libc/regex/regfree.c	Sun Apr 23 21:51:29 2017	(r317346)
@@ -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 */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201704232151.v3NLpTK0002095>