summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-01-19 00:59:30 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-01-19 00:59:30 -0800
commitfccd5fda24a9689f5890abc8d824f7a8da139550 (patch)
tree47819eace65d3604fb26d953189fda0fc0cecc5f
parent1043bad18b114590c78d1db804339a457fd37d96 (diff)
downloadtxr-fccd5fda24a9689f5890abc8d824f7a8da139550.tar.gz
txr-fccd5fda24a9689f5890abc8d824f7a8da139550.tar.bz2
txr-fccd5fda24a9689f5890abc8d824f7a8da139550.zip
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.
-rw-r--r--stream.c5
1 files changed, 3 insertions, 2 deletions
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;