Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #33716] Segfault while using readline

5 views
Skip to first unread message

Matt Diephouse

unread,
Jan 8, 2005, 4:04:07 AM1/8/05
to bugs-bi...@rt.perl.org
# New Ticket Created by Matt Diephouse
# Please include the string: [perl #33716]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=33716 >


The following code segfaults when data.txt contains one line of text
with no newline. While $S0 does have the proper length, it prints as an
empty string in a trace.

.sub main @MAIN
$P0 = open "data.txt", "<"
$S0 = readline $P0
$S1 = substr $S0, 0, 1, ""
end
.end

Adding a newline to the file eliminates the segfault.

--
matt diephouse
http://matt.diephouse.com

Leopold Toetsch

unread,
Jan 9, 2005, 9:51:32 AM1/9/05
to perl6-i...@perl.org
Matt Diephouse <parrotbug...@parrotcode.org> wrote:

> The following code segfaults when data.txt contains one line of text
> with no newline.

Thanks for reporting, fixed.

leo

Matt Diephouse

unread,
Jan 10, 2005, 10:34:12 AM1/10/05
to l...@toetsch.at, perl6-i...@perl.org
Now files that end in a newline return an empty string on the last
iteration. (I'm not sure if that's correct.) That looks to be at least
partially to blame for this code's bus error on os x:

.sub main @MAIN
$P0 = open "test.pir", "<"
LOOP:
unless $P0 goto END
$S0 = readline $P0
$S1 = substr $S0, -1, 1
if $S1 != "\n" goto LOOP
goto LOOP
END:
end
.end

(Make sure you save it with a newline after ".end".) If you s/-1,
1/-1/, it works (This may be related to #33747). It will also work if
you insert "unless $S0 goto END" after the readline.

--
matt diephouse
http://matt.diephouse.com

0 new messages