Skip to content

Commit

Permalink
Strings in struct parse can be const, they are never modified.
Browse files Browse the repository at this point in the history
Also, the temporary array in nonnewline() can be made static const.
From miod@, OK tb@
  • Loading branch information
millert committed Dec 31, 2020
1 parent 75e9e6e commit b817630
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions lib/libc/regex/regcomp.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: regcomp.c,v 1.38 2020/12/30 08:59:17 tb Exp $ */
/* $OpenBSD: regcomp.c,v 1.39 2020/12/31 17:16:38 millert Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
* Copyright (c) 1992, 1993, 1994
Expand Down Expand Up @@ -53,8 +53,8 @@
* 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) */
Expand Down Expand Up @@ -179,7 +179,7 @@ regcomp(regex_t *preg, const char *pattern, int cflags)

/* set things up */
p->g = g;
p->next = (char *)pattern; /* convenience; we do not modify it */
p->next = pattern;
p->end = p->next + len;
p->error = 0;
p->ncsalloc = 0;
Expand Down Expand Up @@ -754,7 +754,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;
const struct cclass *cp;
size_t len;
const char *u;
Expand Down Expand Up @@ -816,7 +816,7 @@ static char /* value of collating element */
p_b_coll_elem(struct parse *p,
int endc) /* name ended by endc,']' */
{
char *sp = p->next;
const char *sp = p->next;
const struct cname *cp;
size_t len;

Expand Down Expand Up @@ -860,8 +860,8 @@ othercase(int ch)
static void
bothcases(struct parse *p, int ch)
{
char *oldnext = p->next;
char *oldend = p->end;
const char *oldnext = p->next;
const char *oldend = p->end;
char bracket[3];

ch = (uch)ch;
Expand Down Expand Up @@ -921,16 +921,12 @@ backslash(struct parse *p, int ch)
static void
nonnewline(struct parse *p)
{
char *oldnext = p->next;
char *oldend = p->end;
char bracket[4];
const char *oldnext = p->next;
const char *oldend = p->end;
static const char bracket[4] = { '^', '\n', ']', '\0' };

p->next = bracket;
p->end = bracket+3;
bracket[0] = '^';
bracket[1] = '\n';
bracket[2] = ']';
bracket[3] = '\0';
p_bracket(p);
assert(p->next == bracket+3);
p->next = oldnext;
Expand Down

0 comments on commit b817630

Please sign in to comment.