X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/e9bc6d6b34afc0063cc5181b59f77eeb81b1182d..36f453d19563f9476d4310b8310ce4080209b04f:/vutil.c diff --git a/vutil.c b/vutil.c index a66d6ef..341eb9b 100644 --- a/vutil.c +++ b/vutil.c @@ -8,6 +8,8 @@ #define VERSION_MAX 0x7FFFFFFF /* +=for apidoc_section Versioning + =for apidoc prescan_version Validate that a given string can be parsed as a version object, but doesn't @@ -533,7 +535,7 @@ Perl_new_version(pTHX_ SV *ver) under = ninstr(raw, raw+len, underscore, underscore + 1); if (under) { Move(under + 1, under, raw + len - under - 1, char); - SvCUR(rv)--; + SvCUR_set(rv, SvCUR(rv) - 1); *SvEND(rv) = '\0'; } /* this is for consistency with the pure Perl class */ @@ -620,7 +622,7 @@ VER_NV: #endif #ifdef USE_LOCALE_NUMERIC - { + { /* This may or may not be called from code that has switched * locales without letting perl know, therefore we have to find it * from first principals. See [perl #121930]. */ @@ -638,6 +640,8 @@ VER_NV: if ( strNE(locale_name_on_entry, "C") && strNE(locale_name_on_entry, "POSIX")) { + /* the setlocale() call might free or overwrite the name */ + locale_name_on_entry = savepv(locale_name_on_entry); setlocale(LC_NUMERIC, "C"); } else { /* This value indicates to the restore code that we didn't @@ -661,13 +665,15 @@ VER_NV: if ( strNE(locale_name_on_entry, "C") && strNE(locale_name_on_entry, "POSIX")) { + /* the setlocale() call might free or overwrite the name */ + locale_name_on_entry = savepv(locale_name_on_entry); setlocale(LC_NUMERIC, "C"); } else { /* This value indicates to the restore code that we didn't change the locale */ locale_name_on_entry = NULL; - } - } + } + } else if (locale_obj_on_entry == PL_underlying_numeric_obj) { /* Here, the locale appears to have been changed to use the * program's underlying locale. Just use our mechanisms to @@ -692,15 +698,15 @@ VER_NV: #endif - if (sv) { - Perl_sv_catpvf(aTHX_ sv, "%.9" NVff, SvNVX(ver)); - len = SvCUR(sv); - buf = SvPVX(sv); - } - else { + if (sv) { + Perl_sv_setpvf(aTHX_ sv, "%.9" NVff, SvNVX(ver)); + len = SvCUR(sv); + buf = SvPVX(sv); + } + else { len = my_snprintf(tbuf, sizeof(tbuf), "%.9" NVff, SvNVX(ver)); - buf = tbuf; - } + buf = tbuf; + } #ifdef USE_LOCALE_NUMERIC @@ -710,6 +716,7 @@ VER_NV: if (locale_name_on_entry) { setlocale(LC_NUMERIC, locale_name_on_entry); + Safefree(locale_name_on_entry); } LC_NUMERIC_UNLOCK; /* End critical section */ @@ -718,6 +725,7 @@ VER_NV: if (locale_name_on_entry) { setlocale(LC_NUMERIC, locale_name_on_entry); + Safefree(locale_name_on_entry); LC_NUMERIC_UNLOCK; } else if (locale_obj_on_entry == PL_underlying_numeric_obj) { @@ -725,7 +733,7 @@ VER_NV: } else if (locale_obj_on_entry != PL_C_locale_obj) { uselocale(locale_obj_on_entry); - } + } # endif @@ -753,7 +761,6 @@ VER_PV: version = savepvn(SvPV(ver,len), SvCUR(ver)); SAVEFREEPV(version); #ifndef SvVOK -# if PERL_VERSION > 5 /* This will only be executed for 5.6.0 - 5.8.0 inclusive */ if ( len >= 3 && !instr(version,".") && !instr(version,"_")) { /* may be a v-string */ @@ -786,7 +793,6 @@ VER_PV: } } } -# endif #endif } #if PERL_VERSION_LT(5,17,2)