From 4eb8205f5605e680f83ce062e7d03fcf2bc26c3e Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Wed, 9 Apr 2014 14:44:26 +0200 Subject: [PATCH] Export: don't try to read past the document end A faulty bound checking resulted in reading a byte past the document end, which resulted in Scintilla returning byte 0 because the position was invalid. By adding this NUL byte to the string used to build the body, the body was truncated after the last document byte (as C strings are NUL-terminated), leading to any format structure after it to be missing from the output. This broke HTML and LaTeX export if the last line didn't end with a newline, as the last line's style closing structure were missing. --- plugins/export.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/export.c b/plugins/export.c index 946275d4d..c4543330b 100644 --- a/plugins/export.c +++ b/plugins/export.c @@ -393,7 +393,7 @@ static void write_latex_file(GeanyDocument *doc, const gchar *filename, /* read the document and write the LaTeX code */ body = g_string_new(""); doc_len = sci_get_length(sci); - for (i = 0; i <= doc_len; i++) + for (i = 0; i < doc_len; i++) { style = sci_get_style_at(sci, i); c = sci_get_char_at(sci, i); @@ -635,7 +635,7 @@ static void write_html_file(GeanyDocument *doc, const gchar *filename, /* read the document and write the HTML body */ body = g_string_new(""); doc_len = sci_get_length(sci); - for (i = 0; i <= doc_len; i++) + for (i = 0; i < doc_len; i++) { style = sci_get_style_at(sci, i); c = sci_get_char_at(sci, i); -- 2.11.4.GIT