From eda88b6dbdc5ca6a51d54f58740f0210e618beb7 Mon Sep 17 00:00:00 2001 From: Jarkko Hietaniemi Date: Thu, 9 Sep 1999 07:50:07 +0000 Subject: [PATCH] %#b in particular and %B in general were kaputt. p4raw-id: //depot/cfgperl@4111 --- sv.c | 7 +++++-- t/op/sprintf.t | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/sv.c b/sv.c index 956f3b9..f6a793c 100644 --- a/sv.c +++ b/sv.c @@ -4959,6 +4959,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV base = 10; goto uns_integer; + case 'B': case 'b': base = 2; goto uns_integer; @@ -5033,8 +5034,10 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV dig = uv & 1; *--eptr = '0' + dig; } while (uv >>= 1); - if (alt && *eptr != '0') - *--eptr = '0'; + if (alt) { + esignbuf[esignlen++] = '0'; + esignbuf[esignlen++] = c; /* 'b' or 'B' */ + } break; default: /* it had better be ten or less */ do { diff --git a/t/op/sprintf.t b/t/op/sprintf.t index ef5b94c..582dfb4 100755 --- a/t/op/sprintf.t +++ b/t/op/sprintf.t @@ -14,8 +14,8 @@ $SIG{__WARN__} = sub { }; $w = 0; -$x = sprintf("%3s %-4s%%foo %.0d%5d %#x%c%3.1f %b","hi",123,0,456,0,ord('A'),3.0999,11); -if ($x eq ' hi 123 %foo 456 0A3.1 1011' && $w == 0) { +$x = sprintf("%3s %-4s%%foo %.0d%5d %#x%c%3.1f %b %x %X %#b %#B %#x %#X","hi",123,0,456,0,ord('A'),3.0999,11,171,171,11,11,171,171); +if ($x eq ' hi 123 %foo 456 0A3.1 1011 ab AB 0b1011 0B1011 0xab 0XAB' && $w == 0) { print "ok 1\n"; } else { print "not ok 1 '$x'\n"; -- 2.7.4