# New Ticket Created by Jürgen Bömmels # Please include the string: [perl #18139] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=18139 >
Found yet another bug in sprintf: The code insists on prepending at least one byte "%02d", 25 => 025 Attached patch fixes this and supplies a test -- attachment 1 ------------------------------------------------------ url: http://rt.perl.org/rt2/attach/40710/32812/ee5c7a/sprintf.diff
Index: spf_render.c =================================================================== RCS file: /cvs/public/parrot/spf_render.c,v retrieving revision 1.4 diff -u -r1.4 spf_render.c --- spf_render.c 27 Oct 2002 11:57:14 -0000 1.4 +++ spf_render.c 28 Oct 2002 22:19:28 -0000 @@ -121,7 +121,7 @@ } } - if (info->flags & FLAG_WIDTH) { + if ((info->flags & FLAG_WIDTH) && info->width > len) { STRING *fill; if (info->flags & FLAG_ZERO) { @@ -131,8 +131,7 @@ fill = cstr2pstr(" "); } - if (info->width > len) - string_repeat(interpreter, fill, info->width - len, &fill); + string_repeat(interpreter, fill, info->width - len, &fill); if (info->flags & FLAG_MINUS) { /* left-align */ string_append(interpreter, str, fill, 0); Index: t/src/sprintf.t =================================================================== RCS file: /cvs/public/parrot/t/src/sprintf.t,v retrieving revision 1.8 diff -u -r1.8 sprintf.t --- t/src/sprintf.t 28 Oct 2002 07:50:32 -0000 1.8 +++ t/src/sprintf.t 28 Oct 2002 22:19:28 -0000 @@ -95,6 +95,9 @@ S = Parrot_sprintf_c(interpreter, "== %05d\n", ival); printf("%05d %s", (int) ival, string_to_cstring(interpreter, S)); + S = Parrot_sprintf_c(interpreter, "== %2d\n", ival); + printf("%2d %s", (int) ival, + string_to_cstring(interpreter, S)); ival = -1; S = Parrot_sprintf_c(interpreter, "== %#x\n", ival); @@ -129,6 +132,7 @@ 25 == 25 25 == 25 | 00025 == 00025 +25 == 25 0xffffffff == 0xffffffff -0000001 == -0000001 That's all, folks!