From: Dominic Dunlop Date: Tue, 20 Jun 2006 16:02:38 +0000 (+0200) Subject: Re: [perl #39530] printf: bad formatting of hexadecimal conversion of binary string... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1387f30c3a0e2c0d15467578b3cb17d441a9efff;p=p5sagit%2Fp5-mst-13.2.git Re: [perl #39530] printf: bad formatting of hexadecimal conversion of binary string using vector flag Message-Id: p4raw-id: //depot/perl@28408 --- diff --git a/sv.c b/sv.c index 6fbcd00..a1b8003 100644 --- a/sv.c +++ b/sv.c @@ -9017,18 +9017,19 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV integer: { char *ptr = ebuf + sizeof ebuf; + bool tempalt = uv ? alt : FALSE; /* Vectors can't change alt */ + zeros = 0; + switch (base) { unsigned dig; case 16: - if (!uv) - alt = FALSE; p = (char*)((c == 'X') ? "0123456789ABCDEF" : "0123456789abcdef"); do { dig = uv & 15; *--ptr = p[dig]; } while (uv >>= 4); - if (alt) { + if (tempalt) { esignbuf[esignlen++] = '0'; esignbuf[esignlen++] = c; /* 'x' or 'X' */ } @@ -9042,13 +9043,11 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV *--ptr = '0'; break; case 2: - if (!uv) - alt = FALSE; do { dig = uv & 1; *--ptr = '0' + dig; } while (uv >>= 1); - if (alt) { + if (tempalt) { esignbuf[esignlen++] = '0'; esignbuf[esignlen++] = 'b'; } diff --git a/t/op/sprintf.t b/t/op/sprintf.t index b0f8c02..3e038d4 100755 --- a/t/op/sprintf.t +++ b/t/op/sprintf.t @@ -434,6 +434,18 @@ __END__ >%v_< >''< >%v_ INVALID< >%v#x< >''< >%v#x INVALID< >%v02x< >"foo\012"< >66.6f.6f.0a< +>%#v.8b< >"a\000b"< >0b01100001.00000000.0b01100010< +>%#v.4o< >"a\000b"< >0141.0000.0142< +>%#v.3i< >"a\000b"< >097.000.098< +>%#v.2x< >"a\000b"< >0x61.00.0x62< +>%#*v.8b< >["][", "a\000b"]< >0b01100001][00000000][0b01100010< +>%#*v.4o< >["][", "a\000b"]< >0141][0000][0142< +>%#*v.3i< >["][", "a\000b"]< >097][000][098< +>%#*v.2x< >["][", "a\000b"]< >0x61][00][0x62< +>%#v.8b< >"a\x{1e01}\000b\x{1e03}"< >0b01100001.0b1111000000001.00000000.0b01100010.0b1111000000011< +>%#v.4o< >"a\x{1e01}\000b\x{1e03}"< >0141.017001.0000.0142.017003< +>%#v.3i< >"a\x{1e01}\000b\x{1e03}"< >097.7681.000.098.7683< +>%#v.2x< >"a\x{1e01}\000b\x{1e03}"< >0x61.0x1e01.00.0x62.0x1e03< >%V-%s< >["Hello"]< >%V-Hello INVALID< >%K %d %d< >[13, 29]< >%K 13 29 INVALID< >%*.*K %d< >[13, 29, 76]< >%*.*K 13 INVALID<