diff options
author | Ludovic Courtès <ludo@gnu.org> | 2011-04-27 20:34:08 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2011-04-27 20:34:08 +0200 |
commit | a42d79711b2366861cf4e6fa884eae709617121d (patch) | |
tree | b2ca3b75961543fdae58e1fab35dfd72c004f40c /libguile/ports.c | |
parent | d84783a80c186b0b13e3aeb206384bb198bf41e6 (diff) | |
download | guile-a42d79711b2366861cf4e6fa884eae709617121d.tar.gz |
Gracefully handle unterminated UTF-8 sequences instead of hitting an `assert'.
* libguile/ports.c (get_codepoint): Return EILSEQ when OUTPUT_SIZE == 0.
* test-suite/tests/ports.test ("string ports"): Add 2 tests for
unterminated sequences.
Diffstat (limited to 'libguile/ports.c')
-rw-r--r-- | libguile/ports.c | 14 |
1 files changed, 9 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; |