fix bugs in processing %v-*d and similar format specs (from
Gurusamy Sarathy [Wed, 12 Jul 2000 21:33:46 +0000 (21:33 +0000)]
Avi Finkel <avi@finkel.org>)

p4raw-id: //depot/perl@6385

sv.c
t/op/sprintf.t

diff --git a/sv.c b/sv.c
index 6ee91be..5f5d281 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -5963,17 +5963,6 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
            case 'v':
                vectorize = TRUE;
                q++;
-               if (args)
-                   vecsv = va_arg(*args, SV*);
-               else if (svix < svmax)
-                   vecsv = svargs[svix++];
-               else {
-                   vecstr = (U8*)"";
-                   veclen = 0;
-                   continue;
-               }
-               vecstr = (U8*)SvPVx(vecsv,veclen);
-               utf = DO_UTF8(vecsv);
                continue;
 
            default:
@@ -6024,6 +6013,23 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
            has_precis = TRUE;
        }
 
+       if (vectorize) {
+           if (args) {
+               vecsv = va_arg(*args, SV*);
+               vecstr = (U8*)SvPVx(vecsv,veclen);
+               utf = DO_UTF8(vecsv);
+           }
+           else if (svix < svmax) {
+               vecsv = svargs[svix++];
+               vecstr = (U8*)SvPVx(vecsv,veclen);
+               utf = DO_UTF8(vecsv);
+           }
+           else {
+               vecstr = (U8*)"";
+               veclen = 0;
+           }
+       }
+
        /* SIZE */
 
        switch (*q) {
index b57eed9..2b0ecae 100755 (executable)
@@ -158,6 +158,13 @@ __END__
 >%v4.3d<    >"\01\02\03"< > 001. 002. 003<
 >%v04.3d<   >"\01\02\03"< >0001.0002.0003<
 >%*v02d<    >['-', "\0\7\13"]< >00-07-11<
+>%v.*d<     >[3, "\01\02\03"]< >001.002.003<
+>%v0*d<     >[3, "\01\02\03"]< >001.002.003<
+>%v-*d<     >[3, "\01\02\03"]< >1  .2  .3  <
+>%v+-*d<    >[3, "\01\02\03"]< >+1 .2  .3  <
+>%v*.*d<    >[4, 3, "\01\02\03"]< > 001. 002. 003<
+>%v0*.*d<   >[4, 3, "\01\02\03"]< >0001.0002.0003<
+>%*v0*d<    >['-', 2, "\0\7\13"]< >00-07-11<
 >%e<        >1234.875<    >1.234875e+03<
 >%e<        >0.000012345< >1.234500e-05<
 >%e<        >1234567E96<  >1.234567e+102<