[gedit] modeline: do not advance beyond string end
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] modeline: do not advance beyond string end
- Date: Sun, 8 May 2016 09:36:42 +0000 (UTC)
commit b3a4e29300d50f8fa1c759a11408216671c9a275
Author: Paolo Borelli <pborelli gnome org>
Date: Sun May 8 11:07:42 2016 +0200
modeline: do not advance beyond string end
If while parsing a modeline we already reach \0 we should not
increment the pointer, we must instead break out of the loop.
plugins/modelines/modeline-parser.c | 23 +++++++++++++++++------
1 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/plugins/modelines/modeline-parser.c b/plugins/modelines/modeline-parser.c
index 33de301..095c0ae 100644
--- a/plugins/modelines/modeline-parser.c
+++ b/plugins/modelines/modeline-parser.c
@@ -573,18 +573,21 @@ parse_kate_modeline (gchar *s,
* Line numbers are counted starting at one.
*/
static void
-parse_modeline (gchar *s,
+parse_modeline (gchar *line,
gint line_number,
gint line_count,
ModelineOptions *options)
{
- gchar prev;
+ gchar *s = line;
/* look for the beginning of a modeline */
- for (prev = ' '; (s != NULL) && (*s != '\0'); prev = *(s++))
+ while (s != NULL && *s != '\0')
{
- if (!g_ascii_isspace (prev))
+ if (s > line && !g_ascii_isspace (*(s - 1)))
+ {
+ s++;
continue;
+ }
if ((line_number <= 3 || line_number > line_count - 3) &&
(strncmp (s, "ex:", 3) == 0 ||
@@ -593,8 +596,12 @@ parse_modeline (gchar *s,
{
gedit_debug_message (DEBUG_PLUGINS, "Vim modeline on line %d", line_number);
- while (*s != ':') s++;
- s = parse_vim_modeline (s + 1, options);
+ while (*s != ':')
+ {
+ s++;
+ }
+
+ s = parse_vim_modeline (s + 1, options);
}
else if (line_number <= 2 && strncmp (s, "-*-", 3) == 0)
{
@@ -609,6 +616,10 @@ parse_modeline (gchar *s,
s = parse_kate_modeline (s + 5, options);
}
+ else
+ {
+ s++;
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]