Commit cbaea1a1 authored by Victor Ananjevsky's avatar Victor Ananjevsky

fix segfault when opening zero-length file in text-info dialog

parent d24e98cc
...@@ -375,28 +375,31 @@ fill_buffer_from_file () ...@@ -375,28 +375,31 @@ fill_buffer_from_file ()
return; return;
} }
gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (text_buffer), &iter, 0); if (len <= 0)
return;
if (!g_utf8_validate (buf, -1, NULL))
{ gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (text_buffer), &iter, 0);
gchar *utftext =
g_convert_with_fallback (buf, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL, NULL); if (!g_utf8_validate (buf, -1, NULL))
if (options.text_data.formatted && !options.common_data.editable) {
gtk_text_buffer_insert_markup (GTK_TEXT_BUFFER (text_buffer), &end, utftext, -1); gchar *utftext =
else g_convert_with_fallback (buf, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL, NULL);
gtk_text_buffer_insert (GTK_TEXT_BUFFER (text_buffer), &end, utftext, -1); if (options.text_data.formatted && !options.common_data.editable)
g_free (utftext); gtk_text_buffer_insert_markup (GTK_TEXT_BUFFER (text_buffer), &end, utftext, -1);
} else
else gtk_text_buffer_insert (GTK_TEXT_BUFFER (text_buffer), &end, utftext, -1);
{ g_free (utftext);
if (options.text_data.formatted && !options.common_data.editable) }
gtk_text_buffer_insert_markup (GTK_TEXT_BUFFER (text_buffer), &end, buf, -1); else
else {
gtk_text_buffer_insert (GTK_TEXT_BUFFER (text_buffer), &end, buf, -1); if (options.text_data.formatted && !options.common_data.editable)
} gtk_text_buffer_insert_markup (GTK_TEXT_BUFFER (text_buffer), &end, buf, -1);
else
/* We had a newline in the buffer to begin with. (The buffer always contains gtk_text_buffer_insert (GTK_TEXT_BUFFER (text_buffer), &end, buf, -1);
* a newline, so we delete to the end of the buffer to clean up. }
/* We had a newline in the buffer to begin with. (The buffer always contains
* a newline, so we delete to the end of the buffer to clean up.
*/ */
gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (text_buffer), &end); gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (text_buffer), &end);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment