From 1b3984634f0ac427443b30fccf58d8140e07af96 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 4 Aug 2020 10:02:26 +0300 Subject: [PATCH] Fix Issue #92; see FIXES. --- FIXES | 5 +++++ main.c | 2 +- run.c | 16 +++++++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/FIXES b/FIXES index b18e74f..5358354 100644 --- a/FIXES +++ b/FIXES @@ -25,6 +25,11 @@ THIS SOFTWARE. This file lists all bug fixes, changes, etc., made since the AWK book was sent to the printers in August, 1987. +August 4, 2020: + In run.c, use non-restartable multibyte routines to attain + portability to DJGPP. Should fix Issue 92. Thanks to Albert Wik + for the report and to Todd Miller for the suggested fix. + July 30, 2020: Merge PRs 88-91 which fix small bugs. Thanks to Todd Miller and Tim van der Molen for the fixes. diff --git a/main.c b/main.c index bcdec89..5bdf679 100644 --- a/main.c +++ b/main.c @@ -22,7 +22,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ****************************************************************/ -const char *version = "version 20200730"; +const char *version = "version 20200804"; #define DEBUG #include diff --git a/run.c b/run.c index 1fef8cd..ae17756 100644 --- a/run.c +++ b/run.c @@ -1521,7 +1521,6 @@ static char *nawk_convert(const char *s, int (*fun_c)(int), char *pbuf = NULL; const char *ps = NULL; size_t n = 0; - mbstate_t mbs, mbs2; wchar_t wc; size_t sz = MB_CUR_MAX; @@ -1536,17 +1535,24 @@ static char *nawk_convert(const char *s, int (*fun_c)(int), /* upper/lower character may be shorter/longer */ buf = tostringN(s, strlen(s) * sz + 1); - memset(&mbs, 0, sizeof(mbs)); - memset(&mbs2, 0, sizeof(mbs2)); + (void) mbtowc(NULL, NULL, 0); /* reset internal state */ + /* + * Reset internal state here too. + * Assign result to avoid a compiler warning. (Casting to void + * doesn't work.) + * Increment said variable to avoid a different warning. + */ + int unused = wctomb(NULL, L'\0'); + unused++; ps = s; pbuf = buf; - while (n = mbrtowc(&wc, ps, sz, &mbs), + while (n = mbtowc(&wc, ps, sz), n > 0 && n != (size_t)-1 && n != (size_t)-2) { ps += n; - n = wcrtomb(pbuf, fun_wc(wc), &mbs2); + n = wctomb(pbuf, fun_wc(wc)); if (n == (size_t)-1) FATAL("illegal wide character %s", s);