From 7213702d3f400ecd376865146fa87230c1693d53 Mon Sep 17 00:00:00 2001 From: Ole Christian Eidheim Date: Thu, 27 Aug 2015 14:22:02 +0200 Subject: [PATCH] Fixed potential crash if file-read accidently splits up an UTF-8 char. --- src/sourcefile.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/sourcefile.cc b/src/sourcefile.cc index 7fc796b..260a5fb 100644 --- a/src/sourcefile.cc +++ b/src/sourcefile.cc @@ -20,13 +20,18 @@ bool juci::filesystem::read(const std::string &path, Glib::RefPtr buffer(buffer_size); size_t read_length; + std::string buffer_str; while((read_length=input.read(&buffer[0], buffer_size).gcount())>0) { - auto ustr=Glib::ustring(std::string(&buffer[0], read_length)); - if(ustr.validate()) - text_buffer->insert_at_cursor(ustr); - else { - input.close(); - return false; + buffer_str+=std::string(&buffer[0], read_length); + if(buffer_str.back()>=0) { + auto ustr=Glib::ustring(buffer_str); + buffer_str=""; + if(ustr.validate()) + text_buffer->insert_at_cursor(ustr); + else { + input.close(); + return false; + } } } input.close();