Skip to content

Commit 1b3df0e

Browse files
author
Father Chrysostomos
committed
Preserve 64-bit array offsets in uninit warnings
This was brought up in ticket #128189. The main change is that Perl_varname now takes a SSize_t parameter instead of I32. I changed various other uses of I32 at the same time in case some code really does have an array with more than 2**31 entries (or whatever the exact number is).
1 parent 9d0d763 commit 1b3df0e

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

embed.fnc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,7 @@ poM |void |sv_kill_backrefs |NN SV *const sv|NULLOK AV *const av
24402440
#if defined(PERL_IN_SV_C) || defined (PERL_IN_OP_C)
24412441
pR |SV * |varname |NULLOK const GV *const gv|const char gvtype \
24422442
|PADOFFSET targ|NULLOK const SV *const keyname \
2443-
|I32 aindex|int subscript_type
2443+
|SSize_t aindex|int subscript_type
24442444
#endif
24452445

24462446
pX |void |sv_del_backref |NN SV *const tsv|NN SV *const sv
@@ -2801,7 +2801,7 @@ p |SV* |magic_scalarpack|NN HV *hv|NN MAGIC *mg
28012801
#if defined(PERL_IN_SV_C)
28022802
s |SV * |find_hash_subscript|NULLOK const HV *const hv \
28032803
|NN const SV *const val
2804-
s |I32 |find_array_subscript|NULLOK const AV *const av \
2804+
s |SSize_t|find_array_subscript|NULLOK const AV *const av \
28052805
|NN const SV *const val
28062806
sMd |SV* |find_uninit_var|NULLOK const OP *const obase \
28072807
|NULLOK const SV *const uninit_sv|bool match \

proto.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5355,7 +5355,7 @@ STATIC I32 S_expect_number(pTHX_ char **const pattern)
53555355
#define PERL_ARGS_ASSERT_EXPECT_NUMBER \
53565356
assert(pattern)
53575357

5358-
STATIC I32 S_find_array_subscript(pTHX_ const AV *const av, const SV *const val);
5358+
STATIC SSize_t S_find_array_subscript(pTHX_ const AV *const av, const SV *const val);
53595359
#define PERL_ARGS_ASSERT_FIND_ARRAY_SUBSCRIPT \
53605360
assert(val)
53615361
STATIC SV * S_find_hash_subscript(pTHX_ const HV *const hv, const SV *const val);
@@ -5435,7 +5435,7 @@ STATIC void S_unreferenced_to_tmp_stack(pTHX_ AV *const unreferenced);
54355435
# endif
54365436
#endif
54375437
#if defined(PERL_IN_SV_C) || defined (PERL_IN_OP_C)
5438-
PERL_CALLCONV SV * Perl_varname(pTHX_ const GV *const gv, const char gvtype, PADOFFSET targ, const SV *const keyname, I32 aindex, int subscript_type)
5438+
PERL_CALLCONV SV * Perl_varname(pTHX_ const GV *const gv, const char gvtype, PADOFFSET targ, const SV *const keyname, SSize_t aindex, int subscript_type)
54395439
__attribute__warn_unused_result__;
54405440

54415441
#endif

sv.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15612,7 +15612,7 @@ S_find_hash_subscript(pTHX_ const HV *const hv, const SV *const val)
1561215612
/* Look for an entry in the array whose value has the same SV as val;
1561315613
* If so, return the index, otherwise return -1. */
1561415614

15615-
STATIC I32
15615+
STATIC SSize_t
1561615616
S_find_array_subscript(pTHX_ const AV *const av, const SV *const val)
1561715617
{
1561815618
PERL_ARGS_ASSERT_FIND_ARRAY_SUBSCRIPT;
@@ -15623,7 +15623,7 @@ S_find_array_subscript(pTHX_ const AV *const av, const SV *const val)
1562315623

1562415624
if (val != &PL_sv_undef) {
1562515625
SV ** const svp = AvARRAY(av);
15626-
I32 i;
15626+
SSize_t i;
1562715627

1562815628
for (i=AvFILLp(av); i>=0; i--)
1562915629
if (svp[i] == val)
@@ -15645,7 +15645,7 @@ S_find_array_subscript(pTHX_ const AV *const av, const SV *const val)
1564515645

1564615646
SV*
1564715647
Perl_varname(pTHX_ const GV *const gv, const char gvtype, PADOFFSET targ,
15648-
const SV *const keyname, I32 aindex, int subscript_type)
15648+
const SV *const keyname, SSize_t aindex, int subscript_type)
1564915649
{
1565015650

1565115651
SV * const name = sv_newmortal();
@@ -15758,7 +15758,7 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv,
1575815758
|| (obase->op_type == OP_PADRANGE
1575915759
&& SvTYPE(PAD_SVl(obase->op_targ)) == SVt_PVHV)
1576015760
);
15761-
I32 index = 0;
15761+
SSize_t index = 0;
1576215762
SV *keysv = NULL;
1576315763
int subscript_type = FUV_SUBSCRIPT_WITHIN;
1576415764

@@ -15944,7 +15944,7 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv,
1594415944
keysv, 0, FUV_SUBSCRIPT_HASH);
1594515945
}
1594615946
else {
15947-
const I32 index
15947+
const SSize_t index
1594815948
= find_array_subscript((const AV *)sv, uninit_sv);
1594915949
if (index >= 0)
1595015950
return varname(gv, '@', o->op_targ,
@@ -16140,7 +16140,7 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv,
1614016140
keysv, 0, FUV_SUBSCRIPT_HASH);
1614116141
}
1614216142
else {
16143-
const I32 index
16143+
const SSize_t index
1614416144
= find_array_subscript((const AV *)sv, uninit_sv);
1614516145
if (index >= 0)
1614616146
return varname(agg_gv, '@', agg_targ,

t/lib/warnings/9uninit

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,3 +2159,24 @@ Use of uninitialized value $r in addition (+) at - line 6.
21592159
Use of uninitialized value $t in subtraction (-) at - line 8.
21602160
Use of uninitialized value $v in integer addition (+) at - line 11.
21612161
Use of uninitialized value $x in integer subtraction (-) at - line 13.
2162+
########
2163+
# NAME 64-bit array subscripts
2164+
# SKIP ? eval { my $q = pack "q", 0 }; $@
2165+
use warnings 'uninitialized';
2166+
2167+
# aelem + const
2168+
use constant foo => \0;
2169+
$SIG{__WARN__} = sub {
2170+
print
2171+
$_[0] =~ /\$a\[([^]]+)]/ && $1 == foo
2172+
? "ok\n"
2173+
: ("$1 != ",0+foo,"\n")
2174+
};
2175+
() = "$a[foo]";
2176+
undef $SIG{__WARN__};
2177+
2178+
# Multideref
2179+
() = "$a[140688675223280]";
2180+
EXPECT
2181+
Use of uninitialized value $a[140688675223280] in string at - line 15.
2182+
ok

0 commit comments

Comments
 (0)