--- gawk-3.1.5/builtin.c.orig 2006-12-17 23:51:38 +0000 +++ gawk-3.1.5/builtin.c 2006-12-17 23:56:58 +0000 @@ -2020,7 +2020,7 @@ do_match(NODE *tree) rlength = REEND(rp, t1->stptr) - RESTART(rp, t1->stptr); /* byte length */ #ifdef MBS_SUPPORT - if (gawk_mb_cur_max > 1) { + if (rlength > 0 && gawk_mb_cur_max > 1) { t1 = str2wstr(t1, & wc_indices); rlength = wc_indices[rstart + rlength - 1] - wc_indices[rstart] + 1; rstart = wc_indices[rstart]; @@ -2046,7 +2046,7 @@ do_match(NODE *tree) subpat_start = s; subpat_len = len = SUBPATEND(rp, t1->stptr, ii) - s; #ifdef MBS_SUPPORT - if (gawk_mb_cur_max > 1) { + if (len > 0 && gawk_mb_cur_max > 1) { subpat_start = wc_indices[s]; subpat_len = wc_indices[s + len - 1] - subpat_start + 1; }