diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2021-01-07 22:08:40 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2021-01-07 22:08:40 +0200 |
commit | e33ab738045b82db7b449e92c8633ef1d44bb8a7 (patch) | |
tree | 7942c2f074014a3125024d1616bfda95566cd0e6 | |
parent | 3c8d0097afa139003c55612eaa89340b70f16ee7 (diff) | |
download | egawk-e33ab738045b82db7b449e92c8633ef1d44bb8a7.tar.gz egawk-e33ab738045b82db7b449e92c8633ef1d44bb8a7.tar.bz2 egawk-e33ab738045b82db7b449e92c8633ef1d44bb8a7.zip |
Improve handling of unsupported format modifiers.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | builtin.c | 60 | ||||
-rw-r--r-- | pc/ChangeLog | 4 | ||||
-rw-r--r-- | pc/Makefile.tst | 10 | ||||
-rw-r--r-- | test/ChangeLog | 5 | ||||
-rw-r--r-- | test/Makefile.am | 7 | ||||
-rw-r--r-- | test/Makefile.in | 12 | ||||
-rw-r--r-- | test/Maketests | 5 |
8 files changed, 62 insertions, 47 deletions
@@ -1,3 +1,9 @@ +2021-01-07 Arnold D. Robbins <arnold@skeeve.com> + + * builtin.c (format_tree): Generalize handling of invalid + format modifiers. Add support for three more letters. Thanks to + Arkadiusz Drabczyk <arkadiusz@drabczyk.org> for the report. + 2020-12-26 Arnold D. Robbins <arnold@skeeve.com> * NEWS: Updated. @@ -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, have_prec, need_format; long *cur = NULL; uintmax_t uval; bool sgn; @@ -735,6 +735,11 @@ format_tree( static const char zero_string[] = "0"; static const char lchbuf[] = "0123456789abcdef"; static const char Uchbuf[] = "0123456789ABCDEF"; + static const char bad_modifiers[] = "hjlLtz"; + static bool warned[sizeof(bad_modifiers)-1]; // auto-init to zero + + bool modifier_seen[sizeof(bad_modifiers)-1]; +#define modifier_index(c) (strchr(bad_modifiers, c) - bad_modifiers) #define INITIAL_OUT_SIZE 64 emalloc(obuf, char *, INITIAL_OUT_SIZE, "format_tree"); @@ -830,7 +835,8 @@ format_tree( #endif fmt_type = MP_NONE; - lj = alt = big_flag = bigbig_flag = small_flag = false; + lj = alt = false; + memset(modifier_seen, 0, sizeof(modifier_seen)); magic_posix_flag = false; fill = sp; cp = cend; @@ -1014,57 +1020,29 @@ check_pos: #else goto retry; #endif + case 'h': + case 'j': case 'l': - if (big_flag) - break; - else { - static bool warned = false; - - if (do_lint && ! warned) { - lintwarn(_("`l' is meaningless in awk formats; ignored")); - warned = true; - } - if (do_posix) { - msg(_("fatal: `l' is not permitted in POSIX awk formats")); - goto out; - } - } - big_flag = true; - goto retry; case 'L': - if (bigbig_flag) + case 't': + case 'z': + if (modifier_seen[modifier_index(cs1)]) break; else { - static bool warned = false; + int ind = modifier_index(cs1); - if (do_lint && ! warned) { - lintwarn(_("`L' is meaningless in awk formats; ignored")); - warned = true; + if (do_lint && ! warned[ind]) { + lintwarn(_("`%c' is meaningless in awk formats; ignored"), cs1); + warned[ind] = true; } if (do_posix) { - msg(_("fatal: `L' is not permitted in POSIX awk formats")); + msg(_("fatal: `%c' is not permitted in POSIX awk formats"), cs1); goto out; } } - bigbig_flag = true; + modifier_seen[modifier_index(cs1)] = true; goto retry; - case 'h': - if (small_flag) - break; - else { - static bool warned = false; - if (do_lint && ! warned) { - lintwarn(_("`h' is meaningless in awk formats; ignored")); - warned = true; - } - if (do_posix) { - msg(_("fatal: `h' is not permitted in POSIX awk formats")); - goto out; - } - } - small_flag = true; - goto retry; case 'P': if (magic_posix_flag) break; diff --git a/pc/ChangeLog b/pc/ChangeLog index c954002e..af2d2e66 100644 --- a/pc/ChangeLog +++ b/pc/ChangeLog @@ -1,3 +1,7 @@ +2021-01-07 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.tst: Rebuilt. + 2020-12-26 Arnold D. Robbins <arnold@skeeve.com> * Makefile.tst: Rebuilt. diff --git a/pc/Makefile.tst b/pc/Makefile.tst index 890c2ff0..3a89c1c4 100644 --- a/pc/Makefile.tst +++ b/pc/Makefile.tst @@ -206,7 +206,8 @@ GAWK_EXT_TESTS = \ indirectbuiltin indirectcall indirectcall2 inf-nan-torture \ intarray iolint isarrayunset \ lint lintexp lintindex lintint lintlength lintplus lintold lintset lintwarn \ - manyfiles match1 match2 match3 mbstr1 mbstr2 mixed1 mktime muldimposix \ + manyfiles match1 match2 match3 mbstr1 mbstr2 mixed1 mktime \ + modifiers muldimposix \ nastyparm negtime next nondec nondec2 nonfatal1 nonfatal2 nonfatal3 \ nsawk1a nsawk1b nsawk1c nsawk2a nsawk2b \ nsbad nsbad_cmd nsforloop nsfuncrecurse nsindirect1 nsindirect2 nsprof1 nsprof2 \ @@ -288,7 +289,7 @@ NEED_SANDBOX = sandbox1 NEED_TRADITIONAL = litoct tradanch rscompat # Lists of tests that run a shell script -RUN_SHELL = exit fflush localenl next randtest rtlen rtlen01 +RUN_SHELL = exit fflush localenl modifiers next randtest rtlen rtlen01 # List of the tests which fail with EXIT CODE 1 FAIL_CODE1 = \ @@ -2981,6 +2982,11 @@ mktime: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +modifiers: + @echo $@ + @-$(LOCALES) AWK="$(AWKPROG)" "$(srcdir)"/$@.sh > _$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + muldimposix: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/ChangeLog b/test/ChangeLog index 7d373146..f465ab09 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2021-01-07 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (EXTRA_DIST): modifiers, new test. + * modifiers.sh, modifiers.ok: New files. + 2020-12-26 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (EXTRA_DIST): fpat9, new test. diff --git a/test/Makefile.am b/test/Makefile.am index 2b1f1416..8278a547 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -661,6 +661,8 @@ EXTRA_DIST = \ manglprm.ok \ manyfiles.awk \ manyfiles.ok \ + modifiers.sh \ + modifiers.ok \ muldimposix.awk \ muldimposix.ok \ match1.awk \ @@ -1436,7 +1438,8 @@ GAWK_EXT_TESTS = \ indirectbuiltin indirectcall indirectcall2 inf-nan-torture \ intarray iolint isarrayunset \ lint lintexp lintindex lintint lintlength lintplus lintold lintset lintwarn \ - manyfiles match1 match2 match3 mbstr1 mbstr2 mixed1 mktime muldimposix \ + manyfiles match1 match2 match3 mbstr1 mbstr2 mixed1 mktime \ + modifiers muldimposix \ nastyparm negtime next nondec nondec2 nonfatal1 nonfatal2 nonfatal3 \ nsawk1a nsawk1b nsawk1c nsawk2a nsawk2b \ nsbad nsbad_cmd nsforloop nsfuncrecurse nsindirect1 nsindirect2 nsprof1 nsprof2 \ @@ -1518,7 +1521,7 @@ NEED_SANDBOX = sandbox1 NEED_TRADITIONAL = litoct tradanch rscompat # Lists of tests that run a shell script -RUN_SHELL = exit fflush localenl next randtest rtlen rtlen01 +RUN_SHELL = exit fflush localenl modifiers next randtest rtlen rtlen01 # List of the tests which fail with EXIT CODE 1 FAIL_CODE1 = \ diff --git a/test/Makefile.in b/test/Makefile.in index b96b7d0d..8c2a8fd4 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -924,6 +924,8 @@ EXTRA_DIST = \ manglprm.ok \ manyfiles.awk \ manyfiles.ok \ + modifiers.sh \ + modifiers.ok \ muldimposix.awk \ muldimposix.ok \ match1.awk \ @@ -1699,7 +1701,8 @@ GAWK_EXT_TESTS = \ indirectbuiltin indirectcall indirectcall2 inf-nan-torture \ intarray iolint isarrayunset \ lint lintexp lintindex lintint lintlength lintplus lintold lintset lintwarn \ - manyfiles match1 match2 match3 mbstr1 mbstr2 mixed1 mktime muldimposix \ + manyfiles match1 match2 match3 mbstr1 mbstr2 mixed1 mktime \ + modifiers muldimposix \ nastyparm negtime next nondec nondec2 nonfatal1 nonfatal2 nonfatal3 \ nsawk1a nsawk1b nsawk1c nsawk2a nsawk2b \ nsbad nsbad_cmd nsforloop nsfuncrecurse nsindirect1 nsindirect2 nsprof1 nsprof2 \ @@ -1781,7 +1784,7 @@ NEED_SANDBOX = sandbox1 NEED_TRADITIONAL = litoct tradanch rscompat # Lists of tests that run a shell script -RUN_SHELL = exit fflush localenl next randtest rtlen rtlen01 +RUN_SHELL = exit fflush localenl modifiers next randtest rtlen rtlen01 # List of the tests which fail with EXIT CODE 1 FAIL_CODE1 = \ @@ -4637,6 +4640,11 @@ mktime: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +modifiers: + @echo $@ + @-$(LOCALES) AWK="$(AWKPROG)" "$(srcdir)"/$@.sh > _$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + muldimposix: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index 363a2755..4e6a705f 100644 --- a/test/Maketests +++ b/test/Maketests @@ -1719,6 +1719,11 @@ mktime: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +modifiers: + @echo $@ + @-$(LOCALES) AWK="$(AWKPROG)" "$(srcdir)"/$@.sh > _$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + muldimposix: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --posix >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ |