In perl.git, the branch blead has been updated

<https://perl5.git.perl.org/perl.git/commitdiff/33e5a354e61aad64afe0e1a4f53773e8547515bf?hp=345db0f66ed0ac7b609bb6bcceaf3a48b5f8e25b>

- Log -----------------------------------------------------------------
commit 33e5a354e61aad64afe0e1a4f53773e8547515bf
Author: Karl Williamson <k...@cpan.org>
Date:   Sat Feb 24 16:32:44 2018 -0700

    locale.c: Save needed value before destroying it
    
    This moves up the copying of a needed value to before the place where it
    could get destroyed.  This only happened on some configurations under
    some circumstances, which is why it got missed.

commit 0b6697c5fb6ef91cb9b537c60b6377b8fc54acbe
Author: Karl Williamson <k...@cpan.org>
Date:   Sat Feb 24 16:22:22 2018 -0700

    locale.c: Let static fcn take a NULL argument
    
    It turns out that it will be convenient in a future commit to have this
    function handle NULL input.  That also means that every call should use
    the return value of this function.

-----------------------------------------------------------------------

Summary of changes:
 embed.fnc |  2 +-
 locale.c  | 48 +++++++++++++++++++++++++++---------------------
 proto.h   |  6 ++++--
 3 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/embed.fnc b/embed.fnc
index 45c37b600f..63a654bf50 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -2791,7 +2791,7 @@ sn        |const char*|my_nl_langinfo|const nl_item 
item|bool toggle
 #  else
 sn     |const char*|my_nl_langinfo|const int item|bool toggle
 #  endif
-in     |const char *|save_to_buffer|NN const char * string     \
+inR    |const char *|save_to_buffer|NULLOK const char * string \
                                    |NULLOK char **buf          \
                                    |NN Size_t *buf_size        \
                                    |const Size_t offset
diff --git a/locale.c b/locale.c
index 887a0ad611..2b1701fda4 100644
--- a/locale.c
+++ b/locale.c
@@ -2131,7 +2131,8 @@ Perl_setlocale(const int category, const char * locale)
 
 #endif
 
-    retval = do_setlocale_r(category, locale);
+    retval = save_to_buffer(do_setlocale_r(category, locale),
+                            &PL_setlocale_buf, &PL_setlocale_bufsize, 0);
     SAVE_ERRNO;
 
 #if defined(USE_LOCALE_NUMERIC) && defined(LC_ALL)
@@ -2152,9 +2153,6 @@ Perl_setlocale(const int category, const char * locale)
         return NULL;
     }
 
-    save_to_buffer(retval, &PL_setlocale_buf, &PL_setlocale_bufsize, 0);
-    retval = PL_setlocale_buf;
-
     /* If locale == NULL, we are just querying the state */
     if (locale == NULL) {
         return retval;
@@ -2228,10 +2226,16 @@ S_save_to_buffer(const char * string, char **buf, 
Size_t *buf_size, const Size_t
     /* Copy the NUL-terminated 'string' to 'buf' + 'offset'.  'buf' has size 
'buf_size',
      * growing it if necessary */
 
-    const Size_t string_size = strlen(string) + offset + 1;
+    Size_t string_size;
 
     PERL_ARGS_ASSERT_SAVE_TO_BUFFER;
 
+    if (! string) {
+        return NULL;
+    }
+
+    string_size = strlen(string) + offset + 1;
+
     if (*buf_size == 0) {
         Newx(*buf, string_size, char);
         *buf_size = string_size;
@@ -2420,6 +2424,7 @@ S_my_nl_langinfo(const int item, bool toggle)
 #endif
 {
     dTHX;
+    const char * retval;
 
     /* We only need to toggle into the underlying LC_NUMERIC locale for these
      * two items, and only if not already there */
@@ -2453,8 +2458,8 @@ S_my_nl_langinfo(const int item, bool toggle)
         /* Copy to a per-thread buffer, which is also one that won't be
          * destroyed by a subsequent setlocale(), such as the
          * RESTORE_LC_NUMERIC may do just below. */
-        save_to_buffer(nl_langinfo(item),
-                       &PL_langinfo_buf, &PL_langinfo_bufsize, 0);
+        retval = save_to_buffer(nl_langinfo(item),
+                                &PL_langinfo_buf, &PL_langinfo_bufsize, 0);
 
         LOCALE_UNLOCK;
 
@@ -2486,8 +2491,8 @@ S_my_nl_langinfo(const int item, bool toggle)
 
         /* We have to save it to a buffer, because the freelocale() just below
          * can invalidate the internal one */
-        save_to_buffer(nl_langinfo_l(item, cur),
-                       &PL_langinfo_buf, &PL_langinfo_bufsize, 0);
+        retval = save_to_buffer(nl_langinfo_l(item, cur),
+                                &PL_langinfo_buf, &PL_langinfo_bufsize, 0);
 
         if (do_free) {
             freelocale(cur);
@@ -2496,7 +2501,7 @@ S_my_nl_langinfo(const int item, bool toggle)
 
 #  endif
 
-    if (strEQ(PL_langinfo_buf, "")) {
+    if (strEQ(retval, "")) {
         if (item == PERL_YESSTR) {
             return "yes";
         }
@@ -2505,7 +2510,7 @@ S_my_nl_langinfo(const int item, bool toggle)
         }
     }
 
-    return PL_langinfo_buf;
+    return retval;
 
 #else   /* Below, emulate nl_langinfo as best we can */
 
@@ -2570,19 +2575,19 @@ S_my_nl_langinfo(const int item, bool toggle)
                 }
 
                 /* Leave the first spot empty to be filled in below */
-                save_to_buffer(lc->currency_symbol, &PL_langinfo_buf,
-                               &PL_langinfo_bufsize, 1);
+                retval = save_to_buffer(lc->currency_symbol, &PL_langinfo_buf,
+                                        &PL_langinfo_bufsize, 1);
                 if (lc->mon_decimal_point && strEQ(lc->mon_decimal_point, ""))
                 { /*  khw couldn't figure out how the localedef specifications
                       would show that the $ should replace the radix; this is
                       just a guess as to how it might work.*/
-                    *PL_langinfo_buf = '.';
+                    retval = ".";
                 }
                 else if (lc->p_cs_precedes) {
-                    *PL_langinfo_buf = '-';
+                    retval = "-";
                 }
                 else {
-                    *PL_langinfo_buf = '+';
+                    retval = "+";
                 }
 
                 LOCALE_UNLOCK;
@@ -2611,8 +2616,8 @@ S_my_nl_langinfo(const int item, bool toggle)
                     }
                 }
 
-                save_to_buffer(temp, &PL_langinfo_buf,
-                               &PL_langinfo_bufsize, 0);
+                retval = save_to_buffer(temp, &PL_langinfo_buf,
+                                        &PL_langinfo_bufsize, 0);
 
                 LOCALE_UNLOCK;
 
@@ -2851,10 +2856,11 @@ S_my_nl_langinfo(const int item, bool toggle)
                 if (return_format) {
                     if (strEQ(PL_langinfo_buf, format)) {
                         *PL_langinfo_buf = '\0';
+                        retval = PL_langinfo_buf;
                     }
                     else {
-                        save_to_buffer(format, &PL_langinfo_buf,
-                                        &PL_langinfo_bufsize, 0);
+                        retval = save_to_buffer(format, &PL_langinfo_buf,
+                                                &PL_langinfo_bufsize, 0);
                     }
                 }
 
@@ -2865,7 +2871,7 @@ S_my_nl_langinfo(const int item, bool toggle)
         }
     }
 
-    return PL_langinfo_buf;
+    return retval;
 
 #endif
 
diff --git a/proto.h b/proto.h
index c858fd3a0a..34da7987fa 100644
--- a/proto.h
+++ b/proto.h
@@ -4707,10 +4707,12 @@ PERL_CALLCONV SV*       Perl_hfree_next_entry(pTHX_ HV 
*hv, STRLEN *indexp);
 STATIC const char*     S_category_name(const int category);
 STATIC void    S_restore_switched_locale(pTHX_ const int category, const char 
* const original_locale);
 #ifndef PERL_NO_INLINE_FUNCTIONS
-PERL_STATIC_INLINE const char *        S_save_to_buffer(const char * string, 
char **buf, Size_t *buf_size, const Size_t offset);
+PERL_STATIC_INLINE const char *        S_save_to_buffer(const char * string, 
char **buf, Size_t *buf_size, const Size_t offset)
+                       __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_SAVE_TO_BUFFER        \
-       assert(string); assert(buf_size)
+       assert(buf_size)
 #endif
+
 STATIC const char*     S_switch_category_locale_to_template(pTHX_ const int 
switch_category, const int template_category, const char * template_locale);
 #  if defined(USE_LOCALE)
 STATIC void    S_new_collate(pTHX_ const char* newcoll);

-- 
Perl5 Master Repository

Reply via email to