Fix Issue #92; see FIXES.

This commit is contained in:
Arnold D. Robbins 2020-08-04 10:02:26 +03:00
parent 9b80a7c137
commit 1b3984634f
3 changed files with 17 additions and 6 deletions

5
FIXES
View File

@ -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.

2
main.c
View File

@ -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 <stdio.h>

16
run.c
View File

@ -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);