=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/awk/b.c,v retrieving revision 1.50 retrieving revision 1.51 diff -c -r1.50 -r1.51 *** src/usr.bin/awk/b.c 2024/01/25 16:40:51 1.50 --- src/usr.bin/awk/b.c 2024/04/25 18:33:53 1.51 *************** *** 1,4 **** ! /* $OpenBSD: b.c,v 1.50 2024/01/25 16:40:51 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved --- 1,4 ---- ! /* $OpenBSD: b.c,v 1.51 2024/04/25 18:33:53 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved *************** *** 613,623 **** size_t orig_size = f->gototab[state].allocated; // 2nd half of new mem is this size memset(p + orig_size, 0, orig_size * sizeof(gtte)); // clean it out ! f->gototab[state].allocated = new_size; // update gotottab info f->gototab[state].entries = p; } ! static int get_gototab(fa *f, int state, int ch) /* hide gototab inplementation */ { gtte key; gtte *item; --- 613,623 ---- size_t orig_size = f->gototab[state].allocated; // 2nd half of new mem is this size memset(p + orig_size, 0, orig_size * sizeof(gtte)); // clean it out ! f->gototab[state].allocated = new_size; // update gototab info f->gototab[state].entries = p; } ! static int get_gototab(fa *f, int state, int ch) /* hide gototab implementation */ { gtte key; gtte *item; *************** *** 644,650 **** return left->ch - right->ch; } ! static int set_gototab(fa *f, int state, int ch, int val) /* hide gototab inplementation */ { if (f->gototab[state].inuse == 0) { f->gototab[state].entries[0].ch = ch; --- 644,650 ---- return left->ch - right->ch; } ! static int set_gototab(fa *f, int state, int ch, int val) /* hide gototab implementation */ { if (f->gototab[state].inuse == 0) { f->gototab[state].entries[0].ch = ch; *************** *** 657,664 **** if (tab->inuse + 1 >= tab->allocated) resize_gototab(f, state); ! f->gototab[state].entries[f->gototab[state].inuse-1].ch = ch; ! f->gototab[state].entries[f->gototab[state].inuse-1].state = val; f->gototab[state].inuse++; return val; } else { --- 657,664 ---- if (tab->inuse + 1 >= tab->allocated) resize_gototab(f, state); ! f->gototab[state].entries[f->gototab[state].inuse].ch = ch; ! f->gototab[state].entries[f->gototab[state].inuse].state = val; f->gototab[state].inuse++; return val; } else { *************** *** 683,691 **** gtt *tab = & f->gototab[state]; if (tab->inuse + 1 >= tab->allocated) resize_gototab(f, state); - ++tab->inuse; f->gototab[state].entries[tab->inuse].ch = ch; f->gototab[state].entries[tab->inuse].state = val; qsort(f->gototab[state].entries, f->gototab[state].inuse, sizeof(gtte), entry_cmp); --- 683,691 ---- gtt *tab = & f->gototab[state]; if (tab->inuse + 1 >= tab->allocated) resize_gototab(f, state); f->gototab[state].entries[tab->inuse].ch = ch; f->gototab[state].entries[tab->inuse].state = val; + ++tab->inuse; qsort(f->gototab[state].entries, f->gototab[state].inuse, sizeof(gtte), entry_cmp); *************** *** 836,843 **** } - #define MAX_UTF_BYTES 4 // UTF-8 is up to 4 bytes long - /* * NAME * fnematch --- 836,841 ---- *************** *** 874,889 **** do { /* ! * Call u8_rune with at least MAX_UTF_BYTES ahead in * the buffer until EOF interferes. */ ! if (k - j < MAX_UTF_BYTES) { ! if (k + MAX_UTF_BYTES > buf + bufsize) { adjbuf(&buf, &bufsize, ! bufsize + MAX_UTF_BYTES, quantum, 0, "fnematch"); } ! for (n = MAX_UTF_BYTES ; n > 0; n--) { *k++ = (c = getc(f)) != EOF ? c : 0; if (c == EOF) { if (ferror(f)) --- 872,899 ---- do { /* ! * Call u8_rune with at least awk_mb_cur_max ahead in * the buffer until EOF interferes. */ ! if (k - j < awk_mb_cur_max) { ! if (k + awk_mb_cur_max > buf + bufsize) { ! char *obuf = buf; adjbuf(&buf, &bufsize, ! bufsize + awk_mb_cur_max, quantum, 0, "fnematch"); + + /* buf resized, maybe moved. update pointers */ + *pbufsize = bufsize; + if (obuf != buf) { + i = buf + (i - obuf); + j = buf + (j - obuf); + k = buf + (k - obuf); + *pbuf = buf; + if (patlen) + patbeg = buf + (patbeg - obuf); + } } ! for (n = awk_mb_cur_max ; n > 0; n--) { *k++ = (c = getc(f)) != EOF ? c : 0; if (c == EOF) { if (ferror(f)) *************** *** 919,928 **** j = i; s = 2; } while (1); - - /* adjbuf() may have relocated a resized buffer. Inform the world. */ - *pbuf = buf; - *pbufsize = bufsize; if (patlen) { /* --- 929,934 ----