From: Gisle Aas Date: Thu, 29 Oct 2009 20:30:02 +0000 (+0100) Subject: Allow syswrite with offset same as length of string [perl #70095] X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3c9465285f823f6b117f10189230291c75f08e05;p=p5sagit%2Fp5-mst-13.2.git Allow syswrite with offset same as length of string [perl #70095] You are not really outside of the string then, but the effect will always be a noop since the number of bytes written will be capped to not exceed the length of the string as for other offsets. --- diff --git a/pp_sys.c b/pp_sys.c index d3430d1..015fcdf 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -1918,7 +1918,7 @@ PP(pp_send) DIE(aTHX_ "Offset outside string"); } offset += blen_chars; - } else if (offset >= (IV)blen_chars) { + } else if (offset > (IV)blen_chars) { Safefree(tmpbuf); DIE(aTHX_ "Offset outside string"); } diff --git a/t/op/sysio.t b/t/op/sysio.t index 966a516..f2c269e 100644 --- a/t/op/sysio.t +++ b/t/op/sysio.t @@ -70,12 +70,16 @@ is($x, 'abc'); ok(!-s $outfile); # should not be able to write from after the buffer -eval { syswrite(O, $x, 1, 3) }; +eval { syswrite(O, $x, 1, 4) }; like($@, qr/^Offset outside string /); # $x still intact is($x, 'abc'); +# but it should be ok to write from the end of the buffer +syswrite(O, $x, 0, 3); +syswrite(O, $x, 1, 3); + # $outfile still intact if ($reopen) { # must close file to update EOF marker for stat close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!"; @@ -97,7 +101,7 @@ if ($reopen) { # must close file to update EOF marker for stat ok(!-s $outfile); # [perl #67912] syswrite prints garbage if called with empty scalar and non-zero offset -eval { my $buf = ''; syswrite(O, $buf, 1, 0) }; +eval { my $buf = ''; syswrite(O, $buf, 1, 1) }; like($@, qr/^Offset outside string /); # $x still intact @@ -109,7 +113,7 @@ if ($reopen) { # must close file to update EOF marker for stat } ok(!-s $outfile); -eval { my $buf = 'x'; syswrite(O, $buf, 1, 1) }; +eval { my $buf = 'x'; syswrite(O, $buf, 1, 2) }; like($@, qr/^Offset outside string /); # $x still intact