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
> The following code segfaults when data.txt contains one line of text
> with no newline.
Thanks for reporting, fixed.
leo
.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