[gedit] Fix off-by-one error in modeline scanning
- From: Paolo Borelli <pborelli src gnome org>
- To: svn-commits-list gnome org
- Subject: [gedit] Fix off-by-one error in modeline scanning
- Date: Sat, 2 May 2009 07:24:31 -0400 (EDT)
commit a52c85cf3a6bb66ec4da43cf09103080dd642f81
Author: Jonathan Rascher <jrascher gmail com>
Date: Fri May 1 16:35:05 2009 -0500
Fix off-by-one error in modeline scanning
Modified parse_modeline to work properly with line numbers indexed from
one, not zero. This makes the modelines plugin scan the correct lines
(as stated in the manual) and fixes GNOME bug #580494.
---
plugins/modelines/modeline-parser.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/plugins/modelines/modeline-parser.c b/plugins/modelines/modeline-parser.c
index c989a72..d56aab3 100644
--- a/plugins/modelines/modeline-parser.c
+++ b/plugins/modelines/modeline-parser.c
@@ -481,6 +481,9 @@ parse_kate_modeline (gchar *s,
return s;
}
+/* Scan a line for vi(m)/emacs/kate modelines.
+ * Line numbers are counted starting at one.
+ */
static void
parse_modeline (gchar *s,
gint line_number,
@@ -495,7 +498,7 @@ parse_modeline (gchar *s,
if (!g_ascii_isspace (prev))
continue;
- if ((line_number < 3 || line_number >= line_count - 3) &&
+ if ((line_number <= 3 || line_number > line_count - 3) &&
(strncmp (s, "ex:", 3) == 0 ||
strncmp (s, "vi:", 3) == 0 ||
strncmp (s, "vim:", 4) == 0))
@@ -505,13 +508,13 @@ parse_modeline (gchar *s,
while (*s != ':') s++;
s = parse_vim_modeline (s + 1, options);
}
- else if (line_number < 2 && strncmp (s, "-*-", 3) == 0)
+ else if (line_number <= 2 && strncmp (s, "-*-", 3) == 0)
{
gedit_debug_message (DEBUG_PLUGINS, "Emacs modeline on line %d", line_number);
s = parse_emacs_modeline (s + 3, options);
}
- else if ((line_number < 10 || line_number >= line_count - 10) &&
+ else if ((line_number <= 10 || line_number > line_count - 10) &&
strncmp (s, "kate:", 5) == 0)
{
gedit_debug_message (DEBUG_PLUGINS, "Kate modeline on line %d", line_number);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]