diff options
-rw-r--r-- | libguile/ports.c | 14 | ||||
-rw-r--r-- | test-suite/tests/ports.test | 14 |
2 files changed, 23 insertions, 5 deletions
diff --git a/libguile/ports.c b/libguile/ports.c index 6e0ae6c8b..b5ad95ec7 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -1174,6 +1174,10 @@ get_codepoint (SCM port, scm_t_wchar *codepoint, output_size = sizeof (utf8_buf) - output_left; } + if (SCM_UNLIKELY (output_size == 0)) + /* An unterminated sequence. */ + err = EILSEQ; + if (SCM_UNLIKELY (err != 0)) { /* Reset the `iconv' state. */ @@ -1190,11 +1194,11 @@ get_codepoint (SCM port, scm_t_wchar *codepoint, input encoding errors.) */ } else - /* Convert the UTF8_BUF sequence to a Unicode code point. */ - *codepoint = utf8_to_codepoint (utf8_buf, output_size); - - if (SCM_LIKELY (err == 0)) - update_port_lf (*codepoint, port); + { + /* Convert the UTF8_BUF sequence to a Unicode code point. */ + *codepoint = utf8_to_codepoint (utf8_buf, output_size); + update_port_lf (*codepoint, port); + } *len = bytes_consumed; diff --git a/test-suite/tests/ports.test b/test-suite/tests/ports.test index c9337248a..d4924fe01 100644 --- a/test-suite/tests/ports.test +++ b/test-suite/tests/ports.test @@ -531,6 +531,20 @@ (read-char -> #\μ) (read-char -> eof))) + (test-decoding-error (206 187 206) "UTF-8" 'error + ;; Unterminated sequence. + (tests + (read-char -> #\λ) + (read-char -> error) + (read-char -> eof))) + + (test-decoding-error (206 187 206) "UTF-8" 'substitute + ;; Unterminated sequence. + (tests + (read-char -> #\λ) + (read-char -> #\?) + (read-char -> eof))) + (test-decoding-error (255 65 66 67) "UTF-8" 'error (tests ;; `peek-char' should repeatedly raise an error. |