aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-07-10 15:40:23 -0700
committerArnold D. Robbins <arnold@skeeve.com>2014-07-10 15:40:23 -0700
commit9a5b89ce4cf173a7e23d9b196a2d7dee9ec2d2f0 (patch)
tree1120c348785a755116fb9eb74d127442fc26ed97
parentbd29e4330190f4ce26dc1f734229357b6f248a1a (diff)
downloadegawk-9a5b89ce4cf173a7e23d9b196a2d7dee9ec2d2f0.tar.gz
egawk-9a5b89ce4cf173a7e23d9b196a2d7dee9ec2d2f0.tar.bz2
egawk-9a5b89ce4cf173a7e23d9b196a2d7dee9ec2d2f0.zip
Bug fix when sprintf %c on huge values in multibyte locales.
-rw-r--r--ChangeLog4
-rw-r--r--builtin.c2
-rw-r--r--test/ChangeLog6
-rw-r--r--test/Makefile.am4
-rw-r--r--test/Makefile.in9
-rw-r--r--test/Maketests5
-rw-r--r--test/printhuge.awk3
-rw-r--r--test/printhuge.ok1
8 files changed, 31 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 3d8affd7..e54aafea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,10 @@
with smarter checking.
(nextc): Call it as appropriate.
+ * builtin.c (format_tree): Add check for bad returns from mbrlen
+ to avoid trying to malloc (size_t) -1 bytes. Thanks to
+ mail.green.fox@gmail.com for the bug report.
+
2014-07-03 Arnold D. Robbins <arnold@skeeve.com>
* awkgram.y (nextc): Add bool check_for_bad parameter to check
diff --git a/builtin.c b/builtin.c
index fa03222b..7523d6c9 100644
--- a/builtin.c
+++ b/builtin.c
@@ -1112,7 +1112,7 @@ out0:
memset(& state, 0, sizeof(state));
count = mbrlen(cp, arg->stlen, & state);
- if (count > 0) {
+ if (count != (size_t) -1 && count != (size_t) -2 && count > 0) {
prec = count;
/* may need to increase fw so that padding happens, see pr_tail code */
if (fw > 0)
diff --git a/test/ChangeLog b/test/ChangeLog
index 5674ec67..80b6a578 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,9 @@
+2014-07-10 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (printhuge): New test.
+ * printhuge.awk, printhuge.ok: New files.
+ Test from mail.green.fox@gmail.com.
+
2014-06-19 Michael Forney <forney@google.com>
* Makefile.am (poundbang): Fix relative path of AWKPROG.
diff --git a/test/Makefile.am b/test/Makefile.am
index 904553b8..7c63b1cf 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -682,6 +682,8 @@ EXTRA_DIST = \
printfbad3.awk \
printfbad3.ok \
printfloat.awk \
+ printhuge.awk \
+ printhuge.ok \
printlang.awk \
prmarscl.awk \
prmarscl.ok \
@@ -1006,7 +1008,7 @@ GAWK_EXT_TESTS = \
lint lintold lintwarn \
manyfiles match1 match2 match3 mbstr1 \
nastyparm next nondec nondec2 \
- patsplit posix printfbad1 printfbad2 printfbad3 procinfs \
+ patsplit posix printfbad1 printfbad2 printfbad3 printhuge procinfs \
profile1 profile2 profile3 profile4 profile5 pty1 \
rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \
rsstart2 rsstart3 rstest6 shadow sortfor sortu split_after_fpat \
diff --git a/test/Makefile.in b/test/Makefile.in
index 15c95345..22aeab82 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -928,6 +928,8 @@ EXTRA_DIST = \
printfbad3.awk \
printfbad3.ok \
printfloat.awk \
+ printhuge.awk \
+ printhuge.ok \
printlang.awk \
prmarscl.awk \
prmarscl.ok \
@@ -1251,7 +1253,7 @@ GAWK_EXT_TESTS = \
lint lintold lintwarn \
manyfiles match1 match2 match3 mbstr1 \
nastyparm next nondec nondec2 \
- patsplit posix printfbad1 printfbad2 printfbad3 procinfs \
+ patsplit posix printfbad1 printfbad2 printfbad3 printhuge procinfs \
profile1 profile2 profile3 profile4 profile5 pty1 \
rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \
rsstart2 rsstart3 rstest6 shadow sortfor sortu split_after_fpat \
@@ -3506,6 +3508,11 @@ printfbad3:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+printhuge:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
procinfs:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 0841ae77..f062ec57 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1142,6 +1142,11 @@ printfbad3:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+printhuge:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
procinfs:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/printhuge.awk b/test/printhuge.awk
new file mode 100644
index 00000000..4d4fb7d4
--- /dev/null
+++ b/test/printhuge.awk
@@ -0,0 +1,3 @@
+BEGIN {
+ printf("%c", sprintf("%c", (0xffffff00+255)))
+}
diff --git a/test/printhuge.ok b/test/printhuge.ok
new file mode 100644
index 00000000..ce542efa
--- /dev/null
+++ b/test/printhuge.ok
@@ -0,0 +1 @@
+ÿ \ No newline at end of file