From: Jarkko Hietaniemi Date: Sat, 10 Jul 1999 12:23:21 +0000 (+0000) Subject: Change t/pragma/warn oct()/hex() overflow tests to use %Config X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=651978e76e838ccd7ba8590fab59df5320c0a952;p=p5sagit%2Fp5-mst-13.2.git Change t/pragma/warn oct()/hex() overflow tests to use %Config to adapt to the underlying platform (the binary, 0b1..., test was broken in 64-bit platforms). Also change "hex" in the warning messages to "hexadecimal" to match "binary" and "octal". p4raw-id: //depot/cfgperl@3662 --- diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 4e23040..9b3ebb1 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -1453,7 +1453,7 @@ Interpretation of the binary number stopped before the offending digit. (W) You may have tried to use an 8 or 9 in a octal number. Interpretation of the octal number stopped before the 8 or 9. -=item Illegal hex digit %s ignored +=item Illegal hexadecimal digit %s ignored (W) You may have tried to use a character other than 0 - 9 or A - F in a hexadecimal number. Interpretation of the hexadecimal number stopped @@ -1500,8 +1500,8 @@ known value, using trustworthy data. See L. =item Integer overflow in %s number -(S) The literal hex, octal or binary number you have specified is -too big for your architecture. On a 32-bit architecture the largest +(S) The literal hexadecimal, octal or binary number you have specified +is too big for your architecture. On a 32-bit architecture the largest literal hex, octal or binary number representable without overflow is 0xFFFFFFFF, 037777777777, or 0b11111111111111111111111111111111 respectively. Note that Perl transparently promotes decimal literals diff --git a/t/pragma/warn/util b/t/pragma/warn/util index bd29f7b..ea3aed5 100644 --- a/t/pragma/warn/util +++ b/t/pragma/warn/util @@ -31,7 +31,7 @@ use warning 'unsafe' ; no warning 'unsafe' ; *a = hex "0xv9" ; EXPECT -Illegal hex digit 'v' ignored at - line 3. +Illegal hexadecimal digit 'v' ignored at - line 3. ######## # util.c use warning 'unsafe' ; @@ -42,41 +42,56 @@ EXPECT Illegal binary digit '9' ignored at - line 3. ######## # util.c +BEGIN { require Config ; import Config } $^W =1 ; +sub make_bin { "1" x $_[0] } +$n = make_bin(8 * $Config{longsize} ) ; +$o = make_bin(8 * $Config{longsize} + 1) ; { use warning 'unsafe' ; - my $a = oct "0b111111111111111111111111111111111" ; + my $a = oct "0b$n" ; + my $b = oct "0b$o" ; no warning 'unsafe' ; - $a = oct "0b111111111111111111111111111111111" ; + $b = oct "0b$o" ; } -my $a = oct "0b111111111111111111111111111111111" ; +my $b = oct "0b$o" ; EXPECT -Integer overflow in binary number at - line 5. -Integer overflow in binary number at - line 9. +Integer overflow in binary number at - line 10. +Integer overflow in binary number at - line 14. ######## # util.c +BEGIN { require Config ; import Config } $^W =1 ; +sub make_oct { ("","1","3")[$_[0]%3] . "7" x int($_[0]/3) } +$n = make_oct(8 * $Config{longsize} ); +$o = make_oct(8 * $Config{longsize} + 1); { use warning 'unsafe' ; - my $a = oct "777777777777777777777777777777777777" ; + my $a = oct "$n" ; + my $b = oct "$o" ; no warning 'unsafe' ; - $a = oct "777777777777777777777777777777777777" ; + $b = oct "$o" ; } -my $a = oct "777777777777777777777777777777777777" ; +my $b = oct "$o" ; EXPECT -Integer overflow in octal number at - line 5. -Integer overflow in octal number at - line 9. +Integer overflow in octal number at - line 10. +Integer overflow in octal number at - line 14. ######## # util.c +BEGIN { require Config ; import Config } $^W =1 ; +sub make_hex { ("","1","3","7")[$_[0]%4] . "f" x int($_[0]/4) } +$n = make_hex(8 * $Config{longsize} ) ; +$o = make_hex(8 * $Config{longsize} + 1) ; { use warning 'unsafe' ; - my $a = hex "ffffffffffffffffffffffffffffffff" ; + my $a = hex "$n" ; + my $b = hex "$o" ; no warning 'unsafe' ; - $a = hex "ffffffffffffffffffffffffffffffff" ; + $b = hex "$o" ; } -my $a = hex "ffffffffffffffffffffffffffffffff" ; +my $b = hex "$o" ; EXPECT -Integer overflow in hex number at - line 5. -Integer overflow in hex number at - line 9. +Integer overflow in hexadecimal number at - line 10. +Integer overflow in hexadecimal number at - line 14. diff --git a/util.c b/util.c index 64580f6..d5ac5a2 100644 --- a/util.c +++ b/util.c @@ -2815,7 +2815,7 @@ Perl_scan_hex(pTHX_ char *start, I32 len, I32 *retlen) dTHR; --s; if (ckWARN(WARN_UNSAFE)) - Perl_warner(aTHX_ WARN_UNSAFE,"Illegal hex digit '%c' ignored", *s); + Perl_warner(aTHX_ WARN_UNSAFE,"Illegal hexadecimal digit '%c' ignored", *s); break; } } @@ -2823,7 +2823,7 @@ Perl_scan_hex(pTHX_ char *start, I32 len, I32 *retlen) if (!overflowed && (n >> 4) != retval) { dTHR; if (ckWARN_d(WARN_UNSAFE)) - Perl_warner(aTHX_ WARN_UNSAFE, "Integer overflow in hex number"); + Perl_warner(aTHX_ WARN_UNSAFE, "Integer overflow in hexadecimal number"); overflowed = TRUE; } retval = n | ((tmp - PL_hexdigit) & 15);