develooper Front page | perl.perl5.porters | Postings from March 2008

Re: [PATCH] Double warning with perl -we 'my $a; substr $a, 0, 10,"foo"'

Thread Previous | Thread Next
From:
Vincent Pit
Date:
March 22, 2008 05:37
Subject:
Re: [PATCH] Double warning with perl -we 'my $a; substr $a, 0, 10,"foo"'
Message ID:
47E4FD96.6080304@profvince.com

> On Sat, Mar 22, 2008 at 01:04:55PM +0100, Vincent Pit wrote:
>   
>> substr gives two undefined warnings when the string is undef and the 
>> offset is 0 (in which case the undef string is grown and filled with the 
>> replacement). The attached patch fixes this by manually initializing the 
>>     
>
> Good catch.
>   
Credits to uniq -d t/lib/warnings/9uninit :)

>   
>> string to "" before inserting. Tested OK against 33547.
>>     
>
>   
>> --- pp.c	2008-02-14 13:10:38.000000000 +0100
>> +++ pp.c	2008-03-22 11:57:42.000000000 +0100
>> @@ -3178,6 +3178,8 @@
>>  		repl = SvPV_const(repl_sv_copy, repl_len);
>>  		repl_is_utf8 = DO_UTF8(repl_sv_copy) && SvCUR(sv);
>>  	    }
>> +	    if (!SvOK(sv))
>> +		sv_setpv(sv, "");
>>     
>
> sv_setpvs(sv, "") would be better, as sv_setpv() is going to do a strlen() on
> the string to find out how long it is.
>
> sv_setpvs(sv, "") will actually call sv_setpvn(sv, "", 0), but the former is
> less typing, and less error prone.
>   
Thanks, you're right. It wasn't in my 5.8.8's perlapi. Take 2 attached.




Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About