Closed p5pRT closed 21 years ago
The following line of code prints one line on standard output:
print($x = (do {} . "This should be printed twice.\n")); print $x;
I would have expected that it prints the line twice\, as the value assigned to $x in the first statement should be used by the two print statements in the same way. But it prints the line just once. This behavior is different from perl 5.6.1.
The documentation says
do BLOCK Not really a function. Returns the value of the last command in the sequence of commands indicated by BLOCK. When modified by a loop modifier\, executes the BLOCK once before testing the loop condition. (On other statements the loop modifiers test the conditional first.)
in this case there *is* no last command in the sequence of commands indicated by BLOCK. So one could argue that this is not a bug\, because I use an undocumented feature of Perl - but the upgrade to 5.8.0. still broke my code!
Thanks\,
Bart Wage
[resent by popular demand -rs]
The following line of code prints one line on standard output:
print($x = (do {} . "This should be printed twice.\n")); print $x;
I would have expected that it prints the line twice\, as the value assigned to $x in the first statement should be used by the two print statements in the same way. But it prints the line just once. This behavior is different from perl 5.6.1.
The documentation says
do BLOCK Not really a function. Returns the value of the last command in the sequence of commands indicated by BLOCK. When modified by a loop modifier\, executes the BLOCK once before testing the loop condition. (On other statements the loop modifiers test the conditional first.)
in this case there *is* no last command in the sequence of commands indicated by BLOCK. So one could argue that this is not a bug\, because I use an undocumented feature of Perl - but the upgrade to 5.8.0. still broke my code!
Thanks\,
Bart Wage
In article \m3k7h8ky6q\.wl\_rspier@​pobox\.com\, Bart Wage \perlbug\-followup@​perl\.org writes:
[resent by popular demand -rs]
The following line of code prints one line on standard output:
print($x = (do {} . "This should be printed twice.\n")); print $x;
Can in fact easily be transformed into a coredump: perl -wle '$z=5+($x = do {} . 2)'
On Tue\, Jan 14\, 2003 at 10:54:43PM +0000\, Ton Hospel wrote:
In article \m3k7h8ky6q\.wl\_rspier@​pobox\.com\, Bart Wage \perlbug\-followup@​perl\.org writes:
[resent by popular demand -rs] The following line of code prints one line on standard output: print($x = (do {} . "This should be printed twice.\n")); print $x;
Can in fact easily be transformed into a coredump: perl -wle '$z=5+($x = do {} . 2)'
Here in maintperl (MAINT18448)\, the first example prints two lines as normal\, and the coredump case does not coredump. Seems like already fixed to me.
/Autrijus/
Autrijus Tang \autrijus@​autrijus\.org wrote:
On Tue\, Jan 14\, 2003 at 10:54:43PM +0000\, Ton Hospel wrote:
In article \m3k7h8ky6q\.wl\_rspier@​pobox\.com\, Bart Wage \perlbug\-followup@​perl\.org writes:
[resent by popular demand -rs] The following line of code prints one line on standard output: print($x = (do {} . "This should be printed twice.\n")); print $x;
Can in fact easily be transformed into a coredump: perl -wle '$z=5+($x = do {} . 2)'
Here in maintperl (MAINT18448)\, the first example prints two lines as normal\, and the coredump case does not coredump. Seems like already fixed to me.
Seems to be fixed in blead too.
Here's a test case :
--- t/op/do.t (revision 581) +++ t/op/do.t (working copy) @@ -31\,7 +31\,7 @@ return $ok; }
-print "1..21\n"; +print "1..22\n";
# Test do &sub and proper @_ handling. $_[0] = 0; @@ -89\,6 +89\,10 @@
# 6 must be interpreted as a file name here ok( (!defined do 6) && $!\, "'do 6' : $!" ); + +# [perl #19545] +push @t\, ($u = (do {} . "This should be printed twice.\n")); +ok( $#t == 0\, "empty do result value" );
END { 1 while unlink("$$.16"\, "$$.17"\, "$$.18"); End.
On Wed\, Jan 15\, 2003 at 10:39:29AM +0100\, Rafael Garcia-Suarez wrote:
Autrijus Tang \autrijus@​autrijus\.org wrote:
On Tue\, Jan 14\, 2003 at 10:54:43PM +0000\, Ton Hospel wrote:
In article \m3k7h8ky6q\.wl\_rspier@​pobox\.com\, Bart Wage \perlbug\-followup@​perl\.org writes:
[resent by popular demand -rs] The following line of code prints one line on standard output: print($x = (do {} . "This should be printed twice.\n")); print $x;
Can in fact easily be transformed into a coredump: perl -wle '$z=5+($x = do {} . 2)'
Here in maintperl (MAINT18448)\, the first example prints two lines as normal\, and the coredump case does not coredump. Seems like already fixed to me.
Seems to be fixed in blead too.
It's "fixed" in 5.8.0 if you run it under valgrind:
$ /usr/local/bin/perl5.8.0 -wle '$z=5+($x = do {} . 2)' Name "main::z" used only once: possible typo at -e line 1. Name "main::x" used only once: possible typo at -e line 1. Use of uninitialized value in concatenation (.) or string at -e line 1. Segmentation fault $ valgrind /usr/local/bin/perl5.8.0 -wle '$z=5+($x = do {} . 2)' ==3311== Memcheck\, a.k.a. Valgrind\, a memory error detector for x86-linux. ==3311== Copyright (C) 2002\, and GNU GPL'd\, by Julian Seward. ==3311== Using valgrind-1.9.3\, a program instrumentation system for x86-linux. ==3311== Copyright (C) 2000-2002\, and GNU GPL'd\, by Julian Seward. ==3311== Estimated CPU clock rate is 733 MHz ==3311== For more details\, rerun with: -v ==3311== syntax error at -e line 1\, at EOF Execution of -e aborted due to compilation errors. ==3311== ==3311== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) ==3311== malloc/free: in use at exit: 45840 bytes in 574 blocks. ==3311== malloc/free: 781 allocs\, 207 frees\, 59678 bytes allocated. ==3311== For a detailed leak analysis\, rerun with: --leak-check=yes ==3311== For counts of detected errors\, rerun with: -v
Notice that it now thinks that there is a syntax error. I can't see how that can happen. (thinks) Something is busting past the end of a local variable? That's the biggest class of bug that valgrind can't see.
Also. 5.6.1 doesn't give the use of unitialised value warning\, whereas 5.8 and 5.005_03 do:
perl5.6.1 -wle '$z=5+($x = do {} . 2)' Name "main::x" used only once: possible typo at -e line 1. Name "main::z" used only once: possible typo at -e line 1.
and the coredump from 5.8?
Program received signal SIGSEGV\, Segmentation fault.
0x080c2070 in Perl_pp_add () at pp_hot.c:326
326 useleft = USE_LEFT(TOPm1s);
(gdb) where
#0 0x080c2070 in Perl_pp_add () at pp_hot.c:326
#1 0x080ad42b in Perl_runops_debug () at dump.c:1398
#2 0x0806043b in S_run_body (oldscope=1) at perl.c:1681
#3 0x0806000f in perl_run (my_perl=0x8164088) at perl.c:1600
#4 0x0805cb5b in main (argc=3\, argv=0xbffff9f4\, env=0xbffffa04)
at perlmain.c:85
#5 0x40081657 in __libc_start_main (main=0x805cab0 \
(gdb) print *sp[-1] Cannot access memory at address 0x209
I believe there's more to this one than meets the eye. Can anyone run purify\, the third degree\, or similar\, on it?
Nicholas Clark
On Wed\, Jan 15\, 2003 at 10:39:05AM +0000\, Nicholas Clark wrote:
On Wed\, Jan 15\, 2003 at 10:39:29AM +0100\, Rafael Garcia-Suarez wrote:
Autrijus Tang \autrijus@​autrijus\.org wrote:
Here in maintperl (MAINT18448)\, the first example prints two lines as normal\, and the coredump case does not coredump. Seems like already fixed to me.
Seems to be fixed in blead too.
I believe there's more to this one than meets the eye. Can anyone run purify\, the third degree\, or similar\, on it?
Oops. Maybe I was premature:
$ perl5.8.0 -wle 'print 1\, 2\, 3\, 4' 1234 $ perl5.8.0 -wle 'print 1\, 2\, 3\, do {}\, 4' 4 $ ./perl -Ilib -wle 'print 1\, 2\, 3\, 4' 1234 $ ./perl -Ilib -wle 'print 1\, 2\, 3\, do {}\, 4' 1234
It looks like do {} was doing something evil to the stack\, but it is fixed now\, and wasn't broken previously:
$ perl5.6.1 -Ilib -wle 'print 1\, 2\, 3\, do {}\, 4' 1234
although there's a bug introduced between 5.6.0 and 5.6.1:
$ perl5.6.0 -wle 'print do {} . 4' Use of uninitialized value in concatenation (.) at -e line 1. 4 $ perl5.6.1 -wle 'print do {} . 4' 4
Hmm: $ perl5.8.0 -wle 'print do {} . 4' Use of uninitialized value in concatenation (.) or string at -e line 1.
(doesn't print 4)
Nicholas Clark
I wrote:
Seems to be fixed in blead too.
Here's a test case :
Which I added as change #18487.
@rspier - Status changed from 'new' to 'resolved'
Migrated from rt.perl.org#19545 (status was 'resolved')
Searchable as RT19545$