In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/e1c30f0c87de26774c1fbe11ab7536e439285070?hp=7a0be72ee91841d7e4109296e11dc081097afbfe>

- Log -----------------------------------------------------------------
commit e1c30f0c87de26774c1fbe11ab7536e439285070
Author: Karl Williamson <[email protected]>
Date:   Wed Jul 13 22:06:30 2016 -0600

    PATCH: [perl #128628] divide by 0 in locale.c
    
    It turned out to be possible to divide by 0 in Win32 when trying to find
    the strxfrm() of an empty string.  On other platforms, the result of
    this is consistent with other strings, but on Windows, it is longer than
    expected, and the code was trying to adapt to this, dividing by the
    input length without checking its validity.  This commit just skips the
    adapting on a 0-length input.
-----------------------------------------------------------------------

Summary of changes:
 lib/locale.t | 6 ++++++
 locale.c     | 7 ++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/locale.t b/lib/locale.t
index 9afa9a4..7917ea8 100644
--- a/lib/locale.t
+++ b/lib/locale.t
@@ -1765,6 +1765,12 @@ foreach my $Locale (@Locale) {
 
         ++$locales_test_number;
         $test_names{$locales_test_number}
+                            = 'Verify that empty strings collate';
+        $ok = "" le "";
+        report_result($Locale, $locales_test_number, $ok);
+
+        ++$locales_test_number;
+        $test_names{$locales_test_number}
             = "Skip in non-UTF-8 locales; otherwise verify that UTF8ness "
             . "doesn't matter with collation";
         if (! $is_utf8_locale) {
diff --git a/locale.c b/locale.c
index 141def9..cc3adac 100644
--- a/locale.c
+++ b/locale.c
@@ -1779,7 +1779,12 @@ Perl__mem_collxfrm(pTHX_ const char *input_string,
                 STRLEN needed = *xlen + 1;   /* +1 For trailing NUL */
                 STRLEN computed_guess = PL_collxfrm_base
                                       + (PL_collxfrm_mult * length_in_chars);
-                const STRLEN new_m = needed / length_in_chars;
+
+                /* On zero-length input, just keep current slope instead of
+                 * dividing by 0 */
+                const STRLEN new_m = (length_in_chars != 0)
+                                     ? needed / length_in_chars
+                                     : PL_collxfrm_mult;
 
                 DEBUG_Lv(PerlIO_printf(Perl_debug_log,
                     "%s: %d: initial size of %"UVuf" bytes for a length "

--
Perl5 Master Repository

Reply via email to