From: millert Date: Fri, 6 Oct 2023 22:31:21 +0000 (+0000) Subject: Correctly reset the goto table for a state. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=52154eb4e7fd31c059061300c34c89113e374244;p=openbsd 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 --- 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__);