From 9090952300ea0a4179d34db9d1939384f7076ddb Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Mon, 2 Apr 2018 13:47:01 -0400 Subject: [PATCH] Issue #252 - Fix off-by-one error When decrementing the length to account for newlines, also decrement the code point count. --- CHANGELOG.md | 1 + runtime.c | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f223dca..1a473fa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Bug Fixes +- Fixed an off-by-one error in `read-line` where the function erroneously reported an extra character was read from `stdin`. Thanks to wasamasa for the bug report. - Fixed a CPS optimization issue where multiple copies of the same lambda are introduced during beta expansion, which causes the optimizer to potentially pick up the wrong value when optimizing-out function calls later on. Thanks to @Chant on Github for providing the report and a test program demonstrating the issue. ## 0.7.2 - February 15, 2018 diff --git a/runtime.c b/runtime.c index 826775b3..b52b3ce5 100644 --- a/runtime.c +++ b/runtime.c @@ -6629,6 +6629,7 @@ object Cyc_io_read_line(void *data, object cont, object port) while (len > 0 && (buf[len - 1] == '\n' || buf[len - 1] == '\r')) { len--; + num_cp--; } buf[len] = '\0'; make_string_noalloc(s, buf, len);