Bug 429531

Summary: perl incorrect calculation
Product: [Fedora] Fedora Reporter: Need Real Name <mal>
Component: perlAssignee: Marcela Mašláňová <mmaslano>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: 8CC: jpazdziora, kasal, perl-devel, rc040203, tcallawa
Target Milestone: ---Keywords: Reopened
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: perl-5.8.8-33.fc8 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-03-13 13:58:08 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
test program
none
simplified test none

Description Need Real Name 2008-01-21 12:41:29 UTC
perl-5.8.8-31 and all other 5.8.8 series execute attached code incorrectly

It produces the output:

Use of uninitialized value in concatenation (.) or string at test.pl line 71.
TBN= A=<DATA>T1<ENDMID></end> TXT 
Use of uninitialized value in concatenation (.) or string at test.pl line 71.
TBN= A=<DATA>T2<ENDMID></end> TXT 
Use of uninitialized value in concatenation (.) or string at test.pl line 71.
TBN= A=<DATA>T3<ENDMID></end> TXT 
Use of uninitialized value in concatenation (.) or string at test.pl line 71.
TBN= A=<DATA>T4<ENDMID></end> TXT 
Use of uninitialized value in concatenation (.) or string at test.pl line 71.
TBN= A=<DATA>T5<ENDMID></end> TXT 
Use of uninitialized value in concatenation (.) or string at test.pl line 71.
TBN= A=<DATA>T6<ENDMID></end> TXT 


when I replace the 
my($tmpbname)=$a=~m@<DATA>([^<>]*)@isg;
by exactly the same meaning:
my $x=$a;
my($tmpbname)=$x=~m@<DATA>([^<>]*)@isg;

the program produces correct output

TBN=T1 A=<APARTMENT>T1<ENDMID></end> TXT 
TBN=T2 A=<APARTMENT>T2<ENDMID></end> TXT 
TBN=T3 A=<APARTMENT>T3<ENDMID></end> TXT 
TBN=T4 A=<APARTMENT>T4<ENDMID></end> TXT 
TBN=T5 A=<APARTMENT>T5<ENDMID></end> TXT 
TBN=T6 A=<APARTMENT>T6<ENDMID></end> TXT 


Description of problem:


Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1.
2.
3.
  
Actual results:


Expected results:


Additional info:

Comment 1 Need Real Name 2008-01-21 12:43:33 UTC
Created attachment 292361 [details]
test program

perl -w test.pl
then comment 
my($tmpbname)=$a=~m@<DATA>([^<>]*)@isg;
and uncomment

my $x=$a;
my($tmpbname)=$x=~m@<DATA>([^<>]*)@isg;
and perl -w test.pl 
again

Comment 2 Need Real Name 2008-01-21 12:50:29 UTC
Created attachment 292362 [details]
simplified test

output 1
my($tmpbname)=$a=~m@<DATA>([^<>]*)@isg;

Use of uninitialized value in concatenation (.) or string at test2.pl line 28.
TBN= A=<DATA>J1</END>
Use of uninitialized value in concatenation (.) or string at test2.pl line 28.
TBN= A=<DATA>J2</END>
Use of uninitialized value in concatenation (.) or string at test2.pl line 28.
TBN= A=<DATA>J3</END>
Use of uninitialized value in concatenation (.) or string at test2.pl line 28.
TBN= A=<DATA>J4</END>
Use of uninitialized value in concatenation (.) or string at test2.pl line 28.
TBN= A=<DATA>J5</END>

output 2 
my $x=$a;
my($tmpbname)=$x=~m@<DATA>([^<>]*)@isg;

TBN=J1 A=<DATA>J1</END>
TBN=J2 A=<DATA>J2</END>
TBN=J3 A=<DATA>J3</END>
TBN=J4 A=<DATA>J4</END>
TBN=J5 A=<DATA>J5</END>

Comment 3 Jan Pazdziora 2008-02-28 13:05:22 UTC
The test program from comment 2 works on on Fedora 8 with

$ rpm -q perl
perl-5.8.8-33.fc8.x86_64

Proposing to close with CURRENTRELEASE.

Comment 4 Need Real Name 2008-03-01 13:17:58 UTC
On F7 it does not produce correct output. I did not try yet on F8.

# rpm -q perl
perl-5.8.8-28.fc7
# perl -w test2.pl
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J1</END>
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J2</END>
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J3</END>
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J4</END>
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J5</END>


Comment 5 Need Real Name 2008-03-01 13:58:26 UTC
The probles IS NOT FIXED IN
 rpm -q perl
perl-5.8.8-33.fc8

# perl -w test2.pl 
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J1</END>
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J2</END>
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J3</END>
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J4</END>
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J5</END>

The output IS INCORRECT

Comment 6 Jan Pazdziora 2008-03-03 08:20:58 UTC
(In reply to comment #5)
> The probles IS NOT FIXED IN
>  rpm -q perl
> perl-5.8.8-33.fc8
> 
> # perl -w test2.pl 
> Use of uninitialized value in concatenation (.) or string at attachment.cgi
line 28.
> TBN= A=<DATA>J1</END>
> Use of uninitialized value in concatenation (.) or string at attachment.cgi
line 28.
> TBN= A=<DATA>J2</END>
> Use of uninitialized value in concatenation (.) or string at attachment.cgi
line 28.
> TBN= A=<DATA>J3</END>
> Use of uninitialized value in concatenation (.) or string at attachment.cgi
line 28.
> TBN= A=<DATA>J4</END>
> Use of uninitialized value in concatenation (.) or string at attachment.cgi
line 28.
> TBN= A=<DATA>J5</END>
> 
> The output IS INCORRECT

Hmm, I missed that -w -- we really should have use warnings in the source file.

By the way, how come that the warning message talks about attachment.cgi when
you run perl on test2.pl.

Comment 7 Jan Pazdziora 2008-03-03 09:27:15 UTC
BTW, I've reproduced the problem on 5.8.5 and also on perl-5.8.0-88.7 in RHEL 3.

Comment 8 Need Real Name 2008-03-03 15:37:22 UTC
>By the way, how come that the warning message talks about attachment.cgi when
you run perl on test2.pl.

It is copy/paste error of the first line. The file with the perl program is
attachment.cgi -
the one called "simplified test" attached to this report:
https://bugzilla.redhat.com/attachment.cgi?id=292362

The correct output, when I comment the line
# my($tmpbname)=$a=~m@<DATA>([^<>]*)@isg;
and uncomment the lines
        my $x=$a;
        my($tmpbname)=$x=~m@<DATA>([^<>]*)@isg;
should be this:
#perl -w attachment.cgi 
TBN=J1 A=<DATA>J1</END>
TBN=J2 A=<DATA>J2</END>
TBN=J3 A=<DATA>J3</END>
TBN=J4 A=<DATA>J4</END>
TBN=J5 A=<DATA>J5</END>

The difference is the TBN= one of strings J1,J2,J3,J4,J5
while with the another code it produces
TBN= value of undef







Comment 9 Need Real Name 2008-03-13 13:09:57 UTC
same problem with perl-5.8.8-36.fc8
# rpm -q perl ; perl -w attachment.cgi
perl-5.8.8-36.fc8
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J1</END>
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J2</END>
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J3</END>
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J4</END>
Use of uninitialized value in concatenation (.) or string at attachment.cgi line 28.
TBN= A=<DATA>J5</END>


Comment 10 Tom "spot" Callaway 2008-03-13 13:26:47 UTC
FWIW, the test cases also fail on 5.10.0. We may want to file this upstream.

Comment 11 Marcela Mašláňová 2008-03-13 13:39:26 UTC
Already is: http://rt.perl.org/rt3/Public/Bug/Display.html?id=50072

Comment 12 Tom "spot" Callaway 2008-03-13 13:58:08 UTC
Indeed, when looking at that ticket, I agree with the assessment of the p5p
commenter, this "bug" is being caused by the /g.

Changing:

my($tmpbname)=$a=~m@<DATA>([^<>]*)@isg;

to

my($tmpbname)=$a=~m@<DATA>([^<>]*)@is;

Resolves this issue. Closing as NOTABUG. If the original poster disagrees, I
suggest that it be directed at upstream, where the ticket is still open.

Comment 13 Need Real Name 2008-03-13 21:40:32 UTC
I just followed the link and read explanations.

What I can say.
For functions to have a side effect - this happens and sometimes unavoidable.
But for OPERATORS to have a side effect
is ugly and wrong.

But it may be too late to change in perl.

Comment 14 Yitzchak Scott-Thoennes 2008-03-17 00:56:00 UTC
Using /g in your scalar-context match in the if() explicitly requests the side
effect.  If you don't want it, don't do that then.