[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Fix handling unsupported printf modifiers with --posix and add t
From: |
Arkadiusz Drabczyk |
Subject: |
[PATCH] Fix handling unsupported printf modifiers with --posix and add tests |
Date: |
Wed, 6 Jan 2021 22:47:45 +0100 |
---
builtin.c | 55 +++++++++++++++++++++++++++++++++++++++++++++--
pc/Makefile.tst | 35 +++++++++++++++++++++++++++++-
test/Makefile.am | 16 +++++++++++++-
test/Makefile.in | 48 +++++++++++++++++++++++++++++++++++++++--
test/Maketests | 30 ++++++++++++++++++++++++++
test/printf_L.awk | 3 +++
test/printf_L.ok | 2 ++
test/printfh.awk | 3 +++
test/printfh.ok | 2 ++
test/printfj.awk | 3 +++
test/printfj.ok | 2 ++
test/printfl.awk | 3 +++
test/printfl.ok | 2 ++
test/printft.awk | 3 +++
test/printft.ok | 2 ++
test/printfz.awk | 3 +++
test/printfz.ok | 2 ++
17 files changed, 208 insertions(+), 6 deletions(-)
create mode 100644 test/printf_L.awk
create mode 100644 test/printf_L.ok
create mode 100644 test/printfh.awk
create mode 100644 test/printfh.ok
create mode 100644 test/printfj.awk
create mode 100644 test/printfj.ok
create mode 100644 test/printfl.awk
create mode 100644 test/printfl.ok
create mode 100644 test/printft.awk
create mode 100644 test/printft.ok
create mode 100644 test/printfz.awk
create mode 100644 test/printfz.ok
diff --git a/builtin.c b/builtin.c
index 55c8878e..9528fa83 100644
--- a/builtin.c
+++ b/builtin.c
@@ -693,7 +693,7 @@ format_tree(
NODE *arg;
long fw, prec, argnum;
bool used_dollar;
- bool lj, alt, big_flag, bigbig_flag, small_flag, have_prec, need_format;
+ bool lj, alt, big_flag, bigbig_flag, small_flag, size_t_flag, max_flag,
ptrdiff_t_flag, have_prec, need_format;
long *cur = NULL;
uintmax_t uval;
bool sgn;
@@ -830,7 +830,7 @@ format_tree(
#endif
fmt_type = MP_NONE;
- lj = alt = big_flag = bigbig_flag = small_flag = false;
+ lj = alt = big_flag = bigbig_flag = small_flag = size_t_flag =
max_flag = ptrdiff_t_flag = false;
magic_posix_flag = false;
fill = sp;
cp = cend;
@@ -1065,6 +1065,57 @@ check_pos:
}
small_flag = true;
goto retry;
+ case 'j':
+ if (max_flag)
+ break;
+ else {
+ static bool warned = false;
+
+ if (do_lint && ! warned) {
+ lintwarn(_("`j' is meaningless in awk
formats; ignored"));
+ warned = true;
+ }
+ if (do_posix) {
+ msg(_("fatal: `j' is not permitted in
POSIX awk formats"));
+ goto out;
+ }
+ }
+ max_flag = true;
+ goto retry;
+ case 't':
+ if (ptrdiff_t_flag)
+ break;
+ else {
+ static bool warned = false;
+
+ if (do_lint && ! warned) {
+ lintwarn(_("`t' is meaningless in awk
formats; ignored"));
+ warned = true;
+ }
+ if (do_posix) {
+ msg(_("fatal: `t' is not permitted in
POSIX awk formats"));
+ goto out;
+ }
+ }
+ ptrdiff_t_flag = true;
+ goto retry;
+ case 'z':
+ if (size_t_flag)
+ break;
+ else {
+ static bool warned = false;
+
+ if (do_lint && ! warned) {
+ lintwarn(_("`z' is meaningless in awk
formats; ignored"));
+ warned = true;
+ }
+ if (do_posix) {
+ msg(_("fatal: `z' is not permitted in
POSIX awk formats"));
+ goto out;
+ }
+ }
+ size_t_flag = true;
+ goto retry;
case 'P':
if (magic_posix_flag)
break;
diff --git a/pc/Makefile.tst b/pc/Makefile.tst
index 890c2ff0..322aed1e 100644
--- a/pc/Makefile.tst
+++ b/pc/Makefile.tst
@@ -169,6 +169,7 @@ BASIC_TESTS = \
opasnidx opasnslf \
paramasfunc1 paramasfunc2 paramdup paramres paramtyp paramuninitglobal \
parse1 parsefld parseme pcntplus posix_compare posix2008sub prdupval
prec printf0 \
+ printfh printfl printf_L printfj printft printfz \
printf1 printfchar prmarscl prmreuse prt1eval prtoeval \
rand randtest range1 range2 readbuf rebrackloc rebt8b1 rebuild redfilnm
regeq \
regexpbrack regexpbrack2 regexprange regrange reindops reparse resplit \
@@ -270,7 +271,9 @@ NEED_MPFR = mpfrbigint mpfrbigint2 mpfrcase mpfrcase2
mpfrexprange mpfrfield mpf
NEED_NONDEC = mpfrbigint2 nondec2 intarray forcenum
# List of tests that need --posix
-NEED_POSIX = escapebrace printf0 posix2008sub paramasfunc1 paramasfunc2
muldimposix posix_compare
+NEED_POSIX = escapebrace printf0 posix2008sub paramasfunc1 paramasfunc2
muldimposix posix_compare \
+ printfh printfl printf_L printfj printft printfz
+
# List of tests that need --pretty-print
NEED_PRETTY = nsprof1 nsprof2 \
@@ -2073,6 +2076,36 @@ printf0:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+printfh:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printfl:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printf_L:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printfj:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printft:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printfz:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
printf1:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$?
>>_$@
diff --git a/test/Makefile.am b/test/Makefile.am
index 2b1f1416..90cb6627 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -957,6 +957,18 @@ EXTRA_DIST = \
printfbad4.ok \
printfchar.awk \
printfchar.ok \
+ printfh.awk \
+ printfh.ok \
+ printfl.awk \
+ printfl.ok \
+ printf_L.awk \
+ printf_L.ok \
+ printfj.awk \
+ printfj.ok \
+ printft.awk \
+ printft.ok \
+ printfz.awk \
+ printfz.ok \
printfloat.awk \
printhuge.awk \
printhuge.ok \
@@ -1399,6 +1411,7 @@ BASIC_TESTS = \
opasnidx opasnslf \
paramasfunc1 paramasfunc2 paramdup paramres paramtyp paramuninitglobal \
parse1 parsefld parseme pcntplus posix_compare posix2008sub prdupval
prec printf0 \
+ printfh printfl printf_L printfj printft printfz \
printf1 printfchar prmarscl prmreuse prt1eval prtoeval \
rand randtest range1 range2 readbuf rebrackloc rebt8b1 rebuild redfilnm
regeq \
regexpbrack regexpbrack2 regexprange regrange reindops reparse resplit \
@@ -1501,7 +1514,8 @@ NEED_MPFR = mpfrbigint mpfrbigint2 mpfrcase mpfrcase2
mpfrexprange mpfrfield mpf
NEED_NONDEC = mpfrbigint2 nondec2 intarray forcenum
# List of tests that need --posix
-NEED_POSIX = escapebrace printf0 posix2008sub paramasfunc1 paramasfunc2
muldimposix posix_compare
+NEED_POSIX = escapebrace printf0 posix2008sub paramasfunc1 paramasfunc2
muldimposix posix_compare \
+ printfh printfl printf_L printfj printft printfz
# List of tests that need --pretty-print
NEED_PRETTY = nsprof1 nsprof2 \
diff --git a/test/Makefile.in b/test/Makefile.in
index b96b7d0d..6f1bca79 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -276,7 +276,6 @@ pkgextensiondir = @pkgextensiondir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
-runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
@@ -1220,6 +1219,18 @@ EXTRA_DIST = \
printfbad4.ok \
printfchar.awk \
printfchar.ok \
+ printfh.awk \
+ printfh.ok \
+ printfl.awk \
+ printfl.ok \
+ printf_L.awk \
+ printf_L.ok \
+ printfj.awk \
+ printfj.ok \
+ printft.awk \
+ printft.ok \
+ printfz.awk \
+ printfz.ok \
printfloat.awk \
printhuge.awk \
printhuge.ok \
@@ -1662,6 +1673,7 @@ BASIC_TESTS = \
opasnidx opasnslf \
paramasfunc1 paramasfunc2 paramdup paramres paramtyp paramuninitglobal \
parse1 parsefld parseme pcntplus posix_compare posix2008sub prdupval
prec printf0 \
+ printfh printfl printf_L printfj printft printfz \
printf1 printfchar prmarscl prmreuse prt1eval prtoeval \
rand randtest range1 range2 readbuf rebrackloc rebt8b1 rebuild redfilnm
regeq \
regexpbrack regexpbrack2 regexprange regrange reindops reparse resplit \
@@ -1763,7 +1775,9 @@ NEED_MPFR = mpfrbigint mpfrbigint2 mpfrcase mpfrcase2
mpfrexprange mpfrfield mpf
NEED_NONDEC = mpfrbigint2 nondec2 intarray forcenum
# List of tests that need --posix
-NEED_POSIX = escapebrace printf0 posix2008sub paramasfunc1 paramasfunc2
muldimposix posix_compare
+NEED_POSIX = escapebrace printf0 posix2008sub paramasfunc1 paramasfunc2
muldimposix posix_compare \
+ printfh printfl printf_L printfj printft printfz
+
# List of tests that need --pretty-print
NEED_PRETTY = nsprof1 nsprof2 \
@@ -3749,6 +3763,36 @@ printf0:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+printfh:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printfl:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printf_L:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printfj:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printft:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printfz:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
printf1:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$?
>>_$@
diff --git a/test/Maketests b/test/Maketests
index 363a2755..ed830b66 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -831,6 +831,36 @@ printf0:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+printfh:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printfl:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printf_L:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printfj:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printft:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
+printfz:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT
CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
printf1:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$?
>>_$@
diff --git a/test/printf_L.awk b/test/printf_L.awk
new file mode 100644
index 00000000..a3b22c13
--- /dev/null
+++ b/test/printf_L.awk
@@ -0,0 +1,3 @@
+BEGIN {
+ printf "%Lu\n", 12
+}
diff --git a/test/printf_L.ok b/test/printf_L.ok
new file mode 100644
index 00000000..b099e81c
--- /dev/null
+++ b/test/printf_L.ok
@@ -0,0 +1,2 @@
+gawk: printf_L.awk:2: fatal: `L' is not permitted in POSIX awk formats
+EXIT CODE: 2
diff --git a/test/printfh.awk b/test/printfh.awk
new file mode 100644
index 00000000..79540d14
--- /dev/null
+++ b/test/printfh.awk
@@ -0,0 +1,3 @@
+BEGIN {
+ printf "%hu\n", 12
+}
diff --git a/test/printfh.ok b/test/printfh.ok
new file mode 100644
index 00000000..947468df
--- /dev/null
+++ b/test/printfh.ok
@@ -0,0 +1,2 @@
+gawk: printfh.awk:2: fatal: `h' is not permitted in POSIX awk formats
+EXIT CODE: 2
diff --git a/test/printfj.awk b/test/printfj.awk
new file mode 100644
index 00000000..8d2b08f4
--- /dev/null
+++ b/test/printfj.awk
@@ -0,0 +1,3 @@
+BEGIN {
+ printf "%ju\n", 12
+}
diff --git a/test/printfj.ok b/test/printfj.ok
new file mode 100644
index 00000000..59d1263b
--- /dev/null
+++ b/test/printfj.ok
@@ -0,0 +1,2 @@
+gawk: printfj.awk:2: fatal: `j' is not permitted in POSIX awk formats
+EXIT CODE: 2
diff --git a/test/printfl.awk b/test/printfl.awk
new file mode 100644
index 00000000..f131366e
--- /dev/null
+++ b/test/printfl.awk
@@ -0,0 +1,3 @@
+BEGIN {
+ printf "%lu\n", 12
+}
diff --git a/test/printfl.ok b/test/printfl.ok
new file mode 100644
index 00000000..69a28faf
--- /dev/null
+++ b/test/printfl.ok
@@ -0,0 +1,2 @@
+gawk: printfl.awk:2: fatal: `l' is not permitted in POSIX awk formats
+EXIT CODE: 2
diff --git a/test/printft.awk b/test/printft.awk
new file mode 100644
index 00000000..b688abda
--- /dev/null
+++ b/test/printft.awk
@@ -0,0 +1,3 @@
+BEGIN {
+ printf "%tu\n", 12
+}
diff --git a/test/printft.ok b/test/printft.ok
new file mode 100644
index 00000000..5334af0c
--- /dev/null
+++ b/test/printft.ok
@@ -0,0 +1,2 @@
+gawk: printft.awk:2: fatal: `t' is not permitted in POSIX awk formats
+EXIT CODE: 2
diff --git a/test/printfz.awk b/test/printfz.awk
new file mode 100644
index 00000000..845021f7
--- /dev/null
+++ b/test/printfz.awk
@@ -0,0 +1,3 @@
+BEGIN {
+ printf "%zu\n", 12
+}
diff --git a/test/printfz.ok b/test/printfz.ok
new file mode 100644
index 00000000..99a180b4
--- /dev/null
+++ b/test/printfz.ok
@@ -0,0 +1,2 @@
+gawk: printfz.awk:2: fatal: `z' is not permitted in POSIX awk formats
+EXIT CODE: 2
--
2.28.0