Browse Source

Fixed potential crash if file-read accidently splits up an UTF-8 char.

merge-requests/365/head
Ole Christian Eidheim 10 years ago
parent
commit
7213702d3f
  1. 17
      src/sourcefile.cc

17
src/sourcefile.cc

@ -20,13 +20,18 @@ bool juci::filesystem::read(const std::string &path, Glib::RefPtr<Gtk::TextBuffe
if(input) { if(input) {
std::vector<char> buffer(buffer_size); std::vector<char> buffer(buffer_size);
size_t read_length; size_t read_length;
std::string buffer_str;
while((read_length=input.read(&buffer[0], buffer_size).gcount())>0) { while((read_length=input.read(&buffer[0], buffer_size).gcount())>0) {
auto ustr=Glib::ustring(std::string(&buffer[0], read_length)); buffer_str+=std::string(&buffer[0], read_length);
if(ustr.validate()) if(buffer_str.back()>=0) {
text_buffer->insert_at_cursor(ustr); auto ustr=Glib::ustring(buffer_str);
else { buffer_str="";
input.close(); if(ustr.validate())
return false; text_buffer->insert_at_cursor(ustr);
else {
input.close();
return false;
}
} }
} }
input.close(); input.close();

Loading…
Cancel
Save