This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
assert legality of bitshifts in scan_num()
authorZefram <zefram@fysh.org>
Wed, 6 Dec 2017 01:10:31 +0000 (01:10 +0000)
committerZefram <zefram@fysh.org>
Wed, 6 Dec 2017 01:10:31 +0000 (01:10 +0000)
[perl #131894] found some negative-exponent shifting going on here.
Make the illegality more accessible by asserting.

toke.c

diff --git a/toke.c b/toke.c
index 70e7de0..0b3e2aa 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -10997,6 +10997,7 @@ Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
                  digit:
                    just_zero = FALSE;
                    if (!overflowed) {
+                       assert(shift >= 0);
                        x = u << shift; /* make room for the digit */
 
                         total_bits += shift;
@@ -11086,6 +11087,7 @@ Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
                                 if (significant_bits < NV_MANT_DIG) {
                                     /* We are in the long "run" of xdigits,
                                      * accumulate the full four bits. */
+                                   assert(shift >= 0);
                                     hexfp_uquad <<= shift;
                                     hexfp_uquad |= b;
                                     hexfp_frac_bits += shift;
@@ -11098,7 +11100,9 @@ Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
                                       significant_bits - NV_MANT_DIG;
                                     if (tail <= 0)
                                        tail += shift;
+                                   assert(tail >= 0);
                                     hexfp_uquad <<= tail;
+                                   assert((shift - tail) >= 0);
                                     hexfp_uquad |= b >> (shift - tail);
                                     hexfp_frac_bits += tail;