develooper Front page | perl.perl5.porters | Postings from July 2009

Re: [perl #67912] syswrite prints garbage if called with empty scalar and non-zero offset

Thread Previous | Thread Next
From:
chromatic
Date:
July 27, 2009 04:03
Subject:
Re: [perl #67912] syswrite prints garbage if called with empty scalar and non-zero offset
Message ID:
200907270402.45959.chromatic@wgz.org
On Monday 27 July 2009 01:01:32 David Taylor wrote:
> # New Ticket Created by  David Taylor
> # Please include the string:  [perl #67912]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=67912 >
>
>
> In a stock 5.10.0 perl with the default build options, syswrite prints
> garbage if called with the empty string as the scalar and a non-zero
> offset:
>
> $ /usr/local/refperl/5.10.0/bin/perl -e 'my $foo = ""; syswrite
> STDOUT, $foo, 100, 1' | less
> <DC>8   /null^@^@^@^Y^@^@^@^A^@^@^@     ^@^@^@^P^@^@^@X^V9
> 
^@^@^@^@<89>^@^@^@<80><A6>^U^H^@^@^@^@^@<A6>^U^H^@^@^@^@<80><A7>^U^H^@^@^@^
>@^@
> 
<A7>^U^H^@^@^@^@<80><A8>^U^H^@^@^@^@^@<A9>^U^H^@^@^@^@^@<A5>^U^H^@^@^@^@<80
>><A4>^U^H^@ (END)

Confirmed in blead.  This looks like a fencepost error.  With the included 
patch, I get instead an error:

$ ./perl -e 'my $foo = ""; syswrite
STDOUT, $foo, 100, 1'
Offset outside string at -e line 1.

I suspect that the comparison should be > instead of >=, but it's late here 
and another set of eyes would help.

diff --git a/pp_sys.c b/pp_sys.c
index 23f79ba..ec12cd4 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1919,7 +1919,7 @@ PP(pp_send)
                    DIE(aTHX_ "Offset outside string");
                }
                offset += blen_chars;
-           } else if (offset >= (IV)blen_chars && blen_chars > 0) {
+           } else if (offset >= (IV)blen_chars) {
                Safefree(tmpbuf);
                DIE(aTHX_ "Offset outside string");
            }

-- c

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