-/* $OpenBSD: b.c,v 1.45 2023/10/30 17:52:54 millert Exp $ */
+/* $OpenBSD: b.c,v 1.46 2023/11/15 18:48:13 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
j = i++;
do {
r = getrune(f);
- if ((++j + r.len) >= k) {
- if (k >= bufsize)
- if (!adjbuf(&buf, &bufsize, bufsize+1, quantum, 0, "fnematch"))
- FATAL("stream '%.30s...' too long", buf);
+ if (r.len == 0) {
+ r.len = 1; // store NUL byte for EOF
+ }
+ j += r.len;
+ if (j >= bufsize) {
+ if (!adjbuf(&buf, &bufsize, j+1, quantum, 0, "fnematch"))
+ FATAL("stream '%.30s...' too long", buf);
}
memcpy(buf + k, r.bytes, r.len);
- j += r.len - 1; // incremented next time around the loop
k += r.len;
if ((ns = get_gototab(pfa, s, r.rune)) != 0)