This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_sv_vcatpvfn_flags: simplify some wrap checks
authorDavid Mitchell <davem@iabyn.com>
Wed, 31 May 2017 11:35:34 +0000 (12:35 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 7 Jun 2017 08:11:08 +0000 (09:11 +0100)
Skip doing some overflow checks when we know it can't overflow.

sv.c

diff --git a/sv.c b/sv.c
index af97ad8..52f8ab5 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -12931,8 +12931,13 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
 
                 if (i > 0) {
                     digits = BIT_DIGITS(i);
-                    if (float_need >= ((STRLEN)~0) - digits)
-                        croak_memory_wrap();
+                    /* this can't overflow. 'digits' will only be a few
+                     * thousand even for the largest floating-point types.
+                     * And up until now float_need is just some small
+                     * constants plus radix_len, which can't be in
+                     * overflow territory unless the radix SV is consuming
+                     * over 1/2 the address space */
+                    assert(float_need < ((STRLEN)~0) - digits);
                     float_need += digits;
                 }
             }
@@ -12964,8 +12969,8 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
 #else
                         NVSIZE * 2; /* 2 hexdigits for each byte */
 #endif
-                    if (float_need >= ((STRLEN)~0) - digits)
-                        croak_memory_wrap();
+                    /* see "this can't overflow" comment above */
+                    assert(float_need < ((STRLEN)~0) - digits);
                     float_need += digits;
                 }
            }