aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2021-01-09 22:24:07 +0200
committerArnold D. Robbins <arnold@skeeve.com>2021-01-09 22:24:07 +0200
commit3aa6709272d6c74300b70d8371b135289a8d8c9d (patch)
treea1c901c1859db9c7933994f0a37b56f33a6d684e
parent5b3ac78d72621697e717765d2d634d7fc271f3c9 (diff)
downloadegawk-3aa6709272d6c74300b70d8371b135289a8d8c9d.tar.gz
egawk-3aa6709272d6c74300b70d8371b135289a8d8c9d.tar.bz2
egawk-3aa6709272d6c74300b70d8371b135289a8d8c9d.zip
Fix conversion of 018 to decimal. Add a test.
-rw-r--r--ChangeLog11
-rw-r--r--builtin.c6
-rw-r--r--mpfr.c4
-rw-r--r--pc/ChangeLog4
-rw-r--r--pc/Makefile.tst6
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am3
-rw-r--r--test/Makefile.in8
-rw-r--r--test/Maketests5
-rw-r--r--test/octdec.awk1
-rw-r--r--test/octdec.ok2
11 files changed, 51 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 60fe7772..6801c201 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2021-01-09 Arnold D. Robbins <arnold@skeeve.com>
+
+ Fix problems turning something like 018 into decimal.
+ Thanks to Arkadiusz Drabczyk <arkadiusz@drabczyk.org> and to
+ Jean-Philippe Guérard <jean-philippe.guerard@xn--tigreray-i1a.org>
+ for the reports.
+
+ * builtin.c (nondec2awknum): Use a copy of len, in case we detect
+ 8 or 9 and have to restart as decimal.
+ * mpfr.c (mpg_strtoui): For 8 or 9, set base to 10.
+
2021-01-08 Arnold D. Robbins <arnold@skeeve.com>
General tightening up use of const and types. Thanks to
diff --git a/builtin.c b/builtin.c
index fc5dc31e..e28c35ef 100644
--- a/builtin.c
+++ b/builtin.c
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 1986, 1988, 1989, 1991-2020,
+ * Copyright (C) 1986, 1988, 1989, 1991-2021,
* the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
@@ -3684,7 +3684,9 @@ nondec2awknum(char *str, size_t len, char **endptr)
if (endptr)
*endptr = str;
} else if (len >= 1 && *str == '0') {
- for (; len > 0; len--) {
+ int l;
+ // preserve len in case we go to decimal
+ for (l = len; l > 0; l--) {
if (! isdigit((unsigned char) *str)) {
if (endptr)
*endptr = str;
diff --git a/mpfr.c b/mpfr.c
index cf53bbdd..cabc3910 100644
--- a/mpfr.c
+++ b/mpfr.c
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 2012, 2013, 2015, 2017, 2018, 2019,
+ * Copyright (C) 2012, 2013, 2015, 2017, 2018, 2019, 2021
* the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
@@ -176,7 +176,7 @@ mpg_strtoui(mpz_ptr zi, char *str, size_t len, char **end, int base)
case '8':
case '9':
if (base == 8)
- goto done;
+ base = 10;
break;
case 'a':
case 'b':
diff --git a/pc/ChangeLog b/pc/ChangeLog
index 22870c9d..bdf1149c 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,3 +1,7 @@
+2021-01-09 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.tst: Rebuilt.
+
2021-01-08 Arnold D. Robbins <arnold@skeeve.com>
* gawkmisc.pc (quote): Make const char *.
diff --git a/pc/Makefile.tst b/pc/Makefile.tst
index 5dbfb658..24e92863 100644
--- a/pc/Makefile.tst
+++ b/pc/Makefile.tst
@@ -211,6 +211,7 @@ GAWK_EXT_TESTS = \
nastyparm negtime next nondec nondec2 nonfatal1 nonfatal2 nonfatal3 \
nsawk1a nsawk1b nsawk1c nsawk2a nsawk2b \
nsbad nsbad_cmd nsforloop nsfuncrecurse nsindirect1 nsindirect2 nsprof1 nsprof2 \
+ octdec \
patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge \
procinfs profile0 profile1 profile2 profile3 profile4 profile5 profile6 \
profile7 profile8 profile9 profile10 profile11 profile12 profile13 \
@@ -3064,6 +3065,11 @@ nsprof2:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+octdec:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
patsplit:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/ChangeLog b/test/ChangeLog
index 456af38a..9cd3edb3 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2021-01-09 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (EXTRA_DIST): octdec, new test.
+ * octdec.awk, octdec.ok: New files.
+
2021-01-07 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (EXTRA_DIST): modifiers, new test.
diff --git a/test/Makefile.am b/test/Makefile.am
index 09efe0eb..ce28345f 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -865,6 +865,8 @@ EXTRA_DIST = \
numsubstr.awk \
numsubstr.in \
numsubstr.ok \
+ octdec.awk \
+ octdec.ok \
octsub.awk \
octsub.ok \
ofmt.awk \
@@ -1446,6 +1448,7 @@ GAWK_EXT_TESTS = \
nastyparm negtime next nondec nondec2 nonfatal1 nonfatal2 nonfatal3 \
nsawk1a nsawk1b nsawk1c nsawk2a nsawk2b \
nsbad nsbad_cmd nsforloop nsfuncrecurse nsindirect1 nsindirect2 nsprof1 nsprof2 \
+ octdec \
patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge \
procinfs profile0 profile1 profile2 profile3 profile4 profile5 profile6 \
profile7 profile8 profile9 profile10 profile11 profile12 profile13 \
diff --git a/test/Makefile.in b/test/Makefile.in
index 54d4a114..337a48fc 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -1128,6 +1128,8 @@ EXTRA_DIST = \
numsubstr.awk \
numsubstr.in \
numsubstr.ok \
+ octdec.awk \
+ octdec.ok \
octsub.awk \
octsub.ok \
ofmt.awk \
@@ -1709,6 +1711,7 @@ GAWK_EXT_TESTS = \
nastyparm negtime next nondec nondec2 nonfatal1 nonfatal2 nonfatal3 \
nsawk1a nsawk1b nsawk1c nsawk2a nsawk2b \
nsbad nsbad_cmd nsforloop nsfuncrecurse nsindirect1 nsindirect2 nsprof1 nsprof2 \
+ octdec \
patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge \
procinfs profile0 profile1 profile2 profile3 profile4 profile5 profile6 \
profile7 profile8 profile9 profile10 profile11 profile12 profile13 \
@@ -4723,6 +4726,11 @@ nsprof2:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+octdec:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
patsplit:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 87b141b4..20ed4a7f 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1799,6 +1799,11 @@ nsprof2:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+octdec:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
patsplit:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/octdec.awk b/test/octdec.awk
new file mode 100644
index 00000000..cc14ddab
--- /dev/null
+++ b/test/octdec.awk
@@ -0,0 +1 @@
+BEGIN { print 021, 018; print 00021, 00018 }
diff --git a/test/octdec.ok b/test/octdec.ok
new file mode 100644
index 00000000..226c02ce
--- /dev/null
+++ b/test/octdec.ok
@@ -0,0 +1,2 @@
+17 18
+17 18