diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2020-12-31 17:16:39 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2020-12-31 17:16:39 +0000 |
commit | b10035f61b548db943d1edb4fb9e1ad1759db578 (patch) | |
tree | a9e7bb8415a5ebe93626e8b1d189512d06daccce | |
parent | 08e1617d1cf2aff7f855a43ea628ac0f10f172ee (diff) |
Strings in struct parse can be const, they are never modified.
Also, the temporary array in nonnewline() can be made static const.
From miod@, OK tb@
-rw-r--r-- | lib/libc/regex/regcomp.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c index d7f06dd8bed..06b3a8c57f2 100644 --- a/lib/libc/regex/regcomp.c +++ b/lib/libc/regex/regcomp.c @@ -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 @@ -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) */ @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; |