From fccd5fda24a9689f5890abc8d824f7a8da139550 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 19 Jan 2016 00:59:30 -0800 Subject: Fix regression: get-char on string input stream. This happened on 2015-07-29, before TXR 111, "Deriving streams from the same base" commit. * stream.c (string_in_get_char): Must retrieve the character at the previous position, not the incremented one. Otherwise we lose the first character, and of course we blow up with an out of range access when we hit the end of the string. --- stream.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'stream.c') diff --git a/stream.c b/stream.c index 2d6e1b0b..7d35e7e1 100644 --- a/stream.c +++ b/stream.c @@ -1292,8 +1292,9 @@ static val string_in_get_char(val stream) struct string_in *s = coerce(struct string_in *, stream->co.handle); if (length_str_gt(s->string, s->pos)) { - set(mkloc(s->pos, stream), plus(s->pos, one)); - return chr_str(s->string, s->pos); + val pos = s->pos; + set(mkloc(s->pos, stream), plus(pos, one)); + return chr_str(s->string, pos); } return nil; -- cgit v1.2.3