Package: gawk Version: 1:3.1.7.dfsg-5 Severity: normal Tags: patch When using a non-C locale, awk does not honor a precision parameter when formatting a string. In the C locale it works fine.
$ LC_ALL=C LC_LANG=c awk 'BEGIN {printf "%.5s\n","123456789"; exit}' 12345 $ LC_ALL=en_US.UTF-8 LC_LANG=en_US.UTF-8 awk 'BEGIN {printf "%.5s\n","123456789"; exit}' 123456789 $ I have created a patch which solves the problem, as well as a new test case, which the original version fails, and the patched one doesn't. The patched version also passes all other tests (make check). I couldn't test the changes I made to test/Makefile.am, as my environment wouldn't successfully complete automake and autoreconf. As an aside, I noticed that the (or most?) non-locale tests in the gawk testsuite are verified only using the C locale. Maybe you could consider running them in a non-C locale as well ? This bug suggests that might be a good idea. Kind regards, Rogier -- System Information: Debian Release: squeeze/sid APT prefers testing APT policy: (500, 'testing') Architecture: i386 (x86_64) Kernel: Linux 2.6.32-5-amd64 (SMP w/1 CPU core) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Versions of packages gawk depends on: ii libc6 2.11.2-6 Embedded GNU C Library: Shared lib gawk recommends no packages. gawk suggests no packages. -- no debconf information ------------------------------------------------------------------------------------ diff -Nur gawk-3.1.7.dfsg/builtin.c gawk-3.1.7.dfsg-patch/builtin.c --- gawk-3.1.7.dfsg/builtin.c 2009-07-09 21:31:27.000000000 +0200 +++ gawk-3.1.7.dfsg-patch/builtin.c 2011-02-13 11:23:44.000000000 +0100 @@ -1220,7 +1220,7 @@ else if (gawk_mb_cur_max > 1 && (cs1 == 's' || cs1 == 'c')) { assert(cp == arg->stptr || cp == cpbuf); copy_count = mbc_byte_count(arg->stptr, - cs1 == 's' ? arg->stlen : 1); + cs1 == 's' ? prec : 1); } bchunk(cp, copy_count); while (fw > prec) { diff -Nur gawk-3.1.7.dfsg/test/Makefile.am gawk-3.1.7.dfsg-patch/test/Makefile.am --- gawk-3.1.7.dfsg/test/Makefile.am 2009-07-03 11:31:11.000000000 +0200 +++ gawk-3.1.7.dfsg-patch/test/Makefile.am 2011-02-13 11:25:32.000000000 +0100 @@ -359,6 +359,9 @@ mbprintf3.awk \ mbprintf3.in \ mbprintf3.ok \ + mbprintfstr.awk \ + mbprintfstr.in \ + mbprintfstr.ok \ mbstr1.awk \ mbstr1.ok \ membug1.awk \ @@ -725,7 +728,7 @@ MACHINE_TESTS = double1 double2 fmtspcl intformat LOCALE_CHARSET_TESTS = asort asorti fmttest fnarydel fnparydl lc_num1 mbfw1 \ - mbprintf1 mbprintf2 rebt8b2 sort1 sprintfc whiny + mbprintf1 mbprintf2 mbprintfstr rebt8b2 sort1 sprintfc whiny # List of the tests which should be run with --lint option: NEED_LINT = defref fmtspcl noeffect nofmtch shadow uninit2 uninit3 uninit4 uninitialized @@ -1229,6 +1232,12 @@ @echo $@ @GAWKLOCALE=en_US.UTF-8 ; export GAWKLOCALE ; \ $(AWK) -f $(srcdir)/$@.awk $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >> _$@ + @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ + +mbprintfstr:: + @echo $@ + @GAWKLOCALE=en_US.UTF-8 ; export GAWKLOCALE ; \ + $(AWK) -f $(srcdir)/$@.awk $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >> _$@ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ mbfw1:: diff -Nur gawk-3.1.7.dfsg/test/mbprintfstr.awk gawk-3.1.7.dfsg- patch/test/mbprintfstr.awk --- gawk-3.1.7.dfsg/test/mbprintfstr.awk 1970-01-01 01:00:00.000000000 +0100 +++ gawk-3.1.7.dfsg-patch/test/mbprintfstr.awk 2011-02-13 11:23:44.000000000 +0100 @@ -0,0 +1,3 @@ +$1=="wp" { printf "|%*.*s|\n",$2,$3,$4 } +$1=="w" { printf "|%*s|\n",$2,$4 } +$1=="p" { printf "|%.*s|\n",$3,$4 } diff -Nur gawk-3.1.7.dfsg/test/mbprintfstr.in gawk-3.1.7.dfsg- patch/test/mbprintfstr.in --- gawk-3.1.7.dfsg/test/mbprintfstr.in 1970-01-01 01:00:00.000000000 +0100 +++ gawk-3.1.7.dfsg-patch/test/mbprintfstr.in 2011-02-13 11:23:44.000000000 +0100 @@ -0,0 +1,9 @@ +wp 1 0 áßcđëfgḩìĵ +wp 8 5 áßcđëfgḩìĵ +wp -8 5 áßcđëfgḩìĵ +w 1 - áßcđë +w 8 - áßcđë +w -8 - áßcđë +p - 1 áßcđëfgḩìĵ +p - 5 áßcđëfgḩìĵ +p - 12 áßcđëfgḩìĵ diff -Nur gawk-3.1.7.dfsg/test/mbprintfstr.ok gawk-3.1.7.dfsg- patch/test/mbprintfstr.ok --- gawk-3.1.7.dfsg/test/mbprintfstr.ok 1970-01-01 01:00:00.000000000 +0100 +++ gawk-3.1.7.dfsg-patch/test/mbprintfstr.ok 2011-02-13 11:23:44.000000000 +0100 @@ -0,0 +1,9 @@ +| | +| áßcđë| +|áßcđë | +|áßcđë| +| áßcđë| +|áßcđë | +|á| +|áßcđë| +|áßcđëfgḩìĵ| ------------------------------------------------------------------------------------ -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org