diff --git a/ChangeLog b/ChangeLog index 469a3d69..393d2dc7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-02-22 Nick Treleaven + + * src/templates.c: + Fix segfault when inserting e.g. fileheader template when the + template file is empty (#3070913, thanks to lphilpot). + + 2011-02-21 Enrico Tröger * plugins/filebrowser.c: diff --git a/src/templates.c b/src/templates.c index 995b0acd..c0626335 100644 --- a/src/templates.c +++ b/src/templates.c @@ -508,12 +508,15 @@ static void make_comment_block(GString *comment_text, gint filetype_idx, guint i /* add line_prefix to every line of comment_text */ lines = g_strsplit(comment_text->str, template_eol_char, -1); - len = g_strv_length(lines) - 1; - for (i = 0; i < len; i++) + len = g_strv_length(lines); + if (len > 0) /* prevent unsigned wraparound if comment_text is empty */ { - tmp = lines[i]; - lines[i] = g_strconcat(prefix, tmp, NULL); - g_free(tmp); + for (i = 0; i < len - 1; i++) + { + tmp = lines[i]; + lines[i] = g_strconcat(prefix, tmp, NULL); + g_free(tmp); + } } tmp = g_strjoinv(template_eol_char, lines);