summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2023-09-13 18:07:17 -0700
committerArnold D. Robbins <arnold@skeeve.com>2023-09-13 18:07:17 -0700
commit017a941d413df307c3c31ddb0262ff70fdc4e88c (patch)
treec64f1e9660ee9692590eca0f8333cb3d70d62680
parent25ef11f8405b2026da1b593a0619cca5af699c88 (diff)
parenta72e18316329e8e3a3b50f95f29e207b394d79f6 (diff)
downloadgawk-017a941d413df307c3c31ddb0262ff70fdc4e88c.tar.gz
Merge branch 'gawk-5.2-stable'
-rw-r--r--ChangeLog9
-rw-r--r--builtin.c18
-rw-r--r--pc/ChangeLog4
-rw-r--r--pc/Makefile.tst12
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am8
-rw-r--r--test/Makefile.in14
-rw-r--r--test/Maketests6
-rw-r--r--test/gsubnulli18n.awk5
-rw-r--r--test/gsubnulli18n.ok1
10 files changed, 74 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index bfee4b8..f7c83e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-09-13 Arnold D. Robbins <arnold@skeeve.com>
+
+ Fix handling of zero length matching in multibyte locales
+ with sub/gsub. Thanks again to Ed Morton for the report.
+
+ * builtin.c (do_sub): When the match is empty and we copy in
+ the subsequent character, check gawk_mb_cur_max to know whether
+ to copy one byte or multiple bytes.
+
2023-09-11 Arnold D. Robbins <arnold@skeeve.com>
* field.c (do_split): Fix some whitespace.
diff --git a/builtin.c b/builtin.c
index 2bc0aaa..88663eb 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2962,6 +2962,8 @@ do_match(int nargs)
*
* 7/2011: Reverted backslash handling to what it used to be. It was in
* gawk for too long. Should have known better.
+ *
+ * 9/2023: Update for matches of null strings around multibyte characters.
*/
/*
@@ -3264,8 +3266,20 @@ do_sub(int nargs, unsigned int flags)
empty:
/* catch the case of gsub(//, "blah", whatever), i.e. empty regexp */
if (matchstart == matchend && matchend < text + textlen) {
- *bp++ = *matchend;
- matchend++;
+ // copy in regular text
+ if (gawk_mb_cur_max == 1) {
+ *bp++ = *matchend;
+ matchend++;
+ } else {
+ mbstate_t mbs;
+ size_t i, j;
+
+ memset(& mbs, 0, sizeof(mbs));
+ j = mbrlen(matchend, (target->stptr + target->stlen) - matchend, & mbs);
+ // FIXME: Error checking on the value of `j' would be a good idea....
+ for (i = 0; i < j; i++)
+ *bp++ = *matchend++;
+ }
}
textlen = text + textlen - matchend;
text = matchend;
diff --git a/pc/ChangeLog b/pc/ChangeLog
index 4e9904d..8e62133 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,3 +1,7 @@
+2023-09-13 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.tst: Regenerated.
+
2023-09-01 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.tst: Regenerated.
diff --git a/pc/Makefile.tst b/pc/Makefile.tst
index 79fa1a6..e89ce36 100644
--- a/pc/Makefile.tst
+++ b/pc/Makefile.tst
@@ -159,7 +159,8 @@ BASIC_TESTS = \
fnaryscl fnasgnm fnmisc fordel forref forsimp fsbs fscaret fsnul1 \
fsrs fsspcoln fstabplus funsemnl funsmnam funstack getline \
getline2 getline3 getline4 getline5 getlnbuf getlnfa getnr2tb \
- getnr2tm gsubasgn gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \
+ getnr2tm gsubasgn gsubnulli18n \
+ gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \
gsubtst6 gsubtst7 gsubtst8 hex hex2 hsprint inpref inputred intest \
intprec iobug1 leaddig leadnl litoct longsub longwrds manglprm \
math membug1 memleak messages minusstr mmap8k nasty nasty2 negexp \
@@ -314,7 +315,8 @@ NEED_LOCALE_C = \
clos1way gsubtst6 range2
NEED_LOCALE_EN = \
- backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 ignrcas2 lc_num1 \
+ backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 \
+ gsubnulli18n ignrcas2 lc_num1 \
mbfw1 mbprintf1 mbprintf3 mbprintf4 mbstr1 mbstr2 \
mtchi18n2 posix_compare \
printhuge reint2 rri1 subamp subi18n wideidx wideidx2 \
@@ -1796,6 +1798,12 @@ gsubasgn:
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+gsubnulli18n:
+ @echo $@
+ @-[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=ENU_USA.1252; export GAWKLOCALE; \
+ AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
gsubtest:
@echo $@
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/ChangeLog b/test/ChangeLog
index 6fcd5f6..2e9b0d4 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2023-09-13 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (EXTRA_DIST): New test, gsubnulli18n.
+ * gsubnulli18n.awk, gsubnulli18n.ok: New files.
+
2023-09-05 Arnold D. Robbins <arnold@skeeve.com>
* mtchi18n2.awk: Change to use \u in the regexp instead of
diff --git a/test/Makefile.am b/test/Makefile.am
index 4876ce5..7c7f9ae 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -545,6 +545,8 @@ EXTRA_DIST = \
gsubasgn.ok \
gsubind.awk \
gsubind.ok \
+ gsubnulli18n.awk \
+ gsubnulli18n.ok \
gsubtest.awk \
gsubtest.ok \
gsubtst2.awk \
@@ -1498,7 +1500,8 @@ BASIC_TESTS = \
fnaryscl fnasgnm fnmisc fordel forref forsimp fsbs fscaret fsnul1 \
fsrs fsspcoln fstabplus funsemnl funsmnam funstack getline \
getline2 getline3 getline4 getline5 getlnbuf getlnfa getnr2tb \
- getnr2tm gsubasgn gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \
+ getnr2tm gsubasgn gsubnulli18n \
+ gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \
gsubtst6 gsubtst7 gsubtst8 hex hex2 hsprint inpref inputred intest \
intprec iobug1 leaddig leadnl litoct longsub longwrds manglprm \
math membug1 memleak messages minusstr mmap8k nasty nasty2 negexp \
@@ -1652,7 +1655,8 @@ NEED_LOCALE_C = \
clos1way gsubtst6 range2
NEED_LOCALE_EN = \
- backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 ignrcas2 lc_num1 \
+ backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 \
+ gsubnulli18n ignrcas2 lc_num1 \
mbfw1 mbprintf1 mbprintf3 mbprintf4 mbstr1 mbstr2 \
mtchi18n2 posix_compare \
printhuge reint2 rri1 subamp subi18n wideidx wideidx2 \
diff --git a/test/Makefile.in b/test/Makefile.in
index ed83c6e..9fafbe1 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -809,6 +809,8 @@ EXTRA_DIST = \
gsubasgn.ok \
gsubind.awk \
gsubind.ok \
+ gsubnulli18n.awk \
+ gsubnulli18n.ok \
gsubtest.awk \
gsubtest.ok \
gsubtst2.awk \
@@ -1762,7 +1764,8 @@ BASIC_TESTS = \
fnaryscl fnasgnm fnmisc fordel forref forsimp fsbs fscaret fsnul1 \
fsrs fsspcoln fstabplus funsemnl funsmnam funstack getline \
getline2 getline3 getline4 getline5 getlnbuf getlnfa getnr2tb \
- getnr2tm gsubasgn gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \
+ getnr2tm gsubasgn gsubnulli18n \
+ gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 \
gsubtst6 gsubtst7 gsubtst8 hex hex2 hsprint inpref inputred intest \
intprec iobug1 leaddig leadnl litoct longsub longwrds manglprm \
math membug1 memleak messages minusstr mmap8k nasty nasty2 negexp \
@@ -1917,7 +1920,8 @@ NEED_LOCALE_C = \
clos1way gsubtst6 range2
NEED_LOCALE_EN = \
- backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 ignrcas2 lc_num1 \
+ backbigs1 backsmalls1 backsmalls2 commas concat4 dfamb1 \
+ gsubnulli18n ignrcas2 lc_num1 \
mbfw1 mbprintf1 mbprintf3 mbprintf4 mbstr1 mbstr2 \
mtchi18n2 posix_compare \
printhuge reint2 rri1 subamp subi18n wideidx wideidx2 \
@@ -3587,6 +3591,12 @@ gsubasgn:
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+gsubnulli18n:
+ @echo $@
+ @-[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=en_US.UTF-8; export GAWKLOCALE; \
+ AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
gsubtest:
@echo $@
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 84d1881..f6f9e91 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -482,6 +482,12 @@ gsubasgn:
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+gsubnulli18n:
+ @echo $@
+ @-[ -z "$$GAWKLOCALE" ] && GAWKLOCALE=en_US.UTF-8; export GAWKLOCALE; \
+ AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
gsubtest:
@echo $@
@-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/gsubnulli18n.awk b/test/gsubnulli18n.awk
new file mode 100644
index 0000000..874586e
--- /dev/null
+++ b/test/gsubnulli18n.awk
@@ -0,0 +1,5 @@
+BEGIN {
+ str = "אבג"
+ n = gsub(//, "x", str)
+ print n, str
+}
diff --git a/test/gsubnulli18n.ok b/test/gsubnulli18n.ok
new file mode 100644
index 0000000..7099c3f
--- /dev/null
+++ b/test/gsubnulli18n.ok
@@ -0,0 +1 @@
+4 xאxבxגx