summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2023-10-06 22:31:22 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2023-10-06 22:31:22 +0000
commite3510d9e78bd1757ad738b1be46a425acaa3fa85 (patch)
tree8cc60a750f35f9d97e6f2adf80c5f4fb16cade1b /usr.bin
parent4f23941f93e1a285b3349c696e870e95c77fda97 (diff)
Correctly reset the goto table for a state.
We cannot use set_gototab() to reset all the entries for a state, it will leave existing entries as-is. Add a new reset_gototab() function that zeroes the table entries for the specified state. There is no need to reset the goto table immediately after resize_state(), it is already initialized via calloc(). Fixes https://github.com/onetrueawk/awk/issues/199
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/awk/b.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/usr.bin/awk/b.c b/usr.bin/awk/b.c
index 2370c661f6d..67061379975 100644
--- a/usr.bin/awk/b.c
+++ b/usr.bin/awk/b.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: b.c,v 1.43 2023/10/06 22:29:24 millert Exp $ */
+/* $OpenBSD: b.c,v 1.44 2023/10/06 22:31:21 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -116,6 +116,7 @@ extern int u8_nextlen(const char *s);
static int get_gototab(fa*, int, int);
static int set_gototab(fa*, int, int, int);
+static void reset_gototab(fa*, int);
extern int u8_rune(int *, const uschar *);
static int *
@@ -276,8 +277,7 @@ int makeinit(fa *f, bool anchor)
}
if ((f->posns[2])[1] == f->accept)
f->out[2] = 1;
- for (i = 0; i < NCHARS; i++)
- set_gototab(f, 2, 0, 0); /* f->gototab[2][i] = 0; */
+ reset_gototab(f, 2);
f->curstat = cgoto(f, 2, HAT);
if (anchor) {
*f->posns[2] = k-1; /* leave out position 0 */
@@ -613,6 +613,11 @@ static int get_gototab(fa *f, int state, int ch) /* hide gototab inplementation
return 0;
}
+static void reset_gototab(fa *f, int state) /* hide gototab inplementation */
+{
+ memset(f->gototab[state], 0, f->gototab_len * sizeof(**f->gototab));
+}
+
static int set_gototab(fa *f, int state, int ch, int val) /* hide gototab inplementation */
{
int i;
@@ -1492,8 +1497,6 @@ int cgoto(fa *f, int s, int c)
/* add tmpset to current set of states */
++(f->curstat);
resize_state(f, f->curstat);
- for (i = 0; i < NCHARS; i++)
- set_gototab(f, f->curstat, 0, 0);
xfree(f->posns[f->curstat]);
p = intalloc(setcnt + 1, __func__);