diff options
author | Kuang-che Wu <kcwu@csie.org> | 2014-01-08 15:03:25 +0100 |
---|---|---|
committer | Ailin Nemui <ailin@esf51.localdomain> | 2014-06-18 22:47:17 +0200 |
commit | fc4a4d24718f92542e4c606d3f3ff2cf81e8f5e3 (patch) | |
tree | 28322ce534ffac23e09334c84f7a11dfacfc9e9f /src/fe-text/textbuffer.c | |
parent | 0331970d64db01bd2db0d86a253393938b2539f1 (diff) | |
download | irssi-fc4a4d24718f92542e4c606d3f3ff2cf81e8f5e3.zip |
Fix UTF-8 character corruption every 32kb of text buffer
Diffstat (limited to 'src/fe-text/textbuffer.c')
-rw-r--r-- | src/fe-text/textbuffer.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c index 0ba7d16e..69f5969c 100644 --- a/src/fe-text/textbuffer.c +++ b/src/fe-text/textbuffer.c @@ -23,6 +23,7 @@ #include "module.h" #include "misc.h" #include "formats.h" +#include "utf8.h" #include "textbuffer.h" @@ -154,6 +155,17 @@ static void text_chunk_append(TEXT_BUFFER_REC *buffer, chunk = buffer->cur_text; while (chunk->pos + len >= TEXT_CHUNK_USABLE_SIZE) { left = TEXT_CHUNK_USABLE_SIZE - chunk->pos; + + /* don't split utf-8 character. (assume we can split non-utf8 anywhere.) */ + if (left < len && !is_utf8_leading(data[left])) { + int i; + for (i = 1; i < 4 && left >= i; i++) + if (is_utf8_leading(data[left - i])) { + left -= i; + break; + } + } + if (left > 0 && data[left-1] == 0) left--; /* don't split the commands */ |