Front page | perl.perl5.changes |
Postings from December 2005
Change 26240: sprintf %NNN$ check for large values wrapping to negative
From:
Dave Mitchell
Date:
December 1, 2005 09:15
Subject:
Change 26240: sprintf %NNN$ check for large values wrapping to negative
Message ID:
200512011711.jB1HBKXA001782@smtp3.ActiveState.com
Change 26240 by davem@davem-splatty on 2005/12/01 16:40:29
sprintf %NNN$ check for large values wrapping to negative
Affected files ...
... //depot/perl/sv.c#1028 edit
... //depot/perl/t/op/sprintf2.t#4 edit
Differences ...
==== //depot/perl/sv.c#1028 (text) ====
Index: perl/sv.c
--- perl/sv.c#1027~26239~ Thu Dec 1 07:40:11 2005
+++ perl/sv.c Thu Dec 1 08:40:29 2005
@@ -8359,9 +8359,10 @@
if (vectorize)
argsv = vecsv;
- else if (!args)
- argsv = (efix ? efix <= svmax : svix < svmax) ?
- svargs[efix ? efix-1 : svix++] : &PL_sv_undef;
+ else if (!args) {
+ I32 i = efix ? efix-1 : svix++;
+ argsv = (i >= 0 && i < svmax) ? svargs[i] : &PL_sv_undef;
+ }
switch (c = *q++) {
==== //depot/perl/t/op/sprintf2.t#4 (text) ====
Index: perl/t/op/sprintf2.t
--- perl/t/op/sprintf2.t#3~26236~ Thu Dec 1 03:52:24 2005
+++ perl/t/op/sprintf2.t Thu Dec 1 08:40:29 2005
@@ -6,7 +6,7 @@
require './test.pl';
}
-plan tests => 4;
+plan tests => 7;
is(
sprintf("%.40g ",0.01),
@@ -33,4 +33,24 @@
'Modification of a read-only value attempted at - line 1.',
{ switches => [ '-w' ] },
q(%n should not be able to modify read-only constants),
-)
+);
+
+# check %NNN$ for range bounds, especially negative 2's complement
+
+{
+ my ($warn, $bad) = (0,0);
+ local $SIG{__WARN__} = sub {
+ if ($_[0] =~ /uninitialized/) {
+ $warn++
+ }
+ else {
+ $bad++
+ }
+ };
+ my $result = sprintf join('', map("%$_\$s%" . ~$_ . '$s', 1..20)),
+ qw(a b c d);
+ is($result, "abcd", "only four valid values");
+ is($warn, 36, "expected warnings");
+ is($bad, 0, "unexpected warnings");
+}
+
End of Patch.
-
Change 26240: sprintf %NNN$ check for large values wrapping to negative
by Dave Mitchell