SF.net SVN: geany:[3843] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Fri Jun 5 15:59:59 UTC 2009
Revision: 3843
http://geany.svn.sourceforge.net/geany/?rev=3843&view=rev
Author: ntrel
Date: 2009-06-05 15:59:58 +0000 (Fri, 05 Jun 2009)
Log Message:
-----------
Fix segfault on parsing a filetypes.* style definition that has < 4
fields.
Allow style definitions to have missing fields to use the default
style fields.
Modified Paths:
--------------
trunk/ChangeLog
trunk/data/filetypes.common
trunk/src/highlighting.c
trunk/src/utils.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-06-05 15:57:01 UTC (rev 3842)
+++ trunk/ChangeLog 2009-06-05 15:59:58 UTC (rev 3843)
@@ -6,6 +6,11 @@
* src/editor.c:
Fix redrawing due to colourising just after the document is first
drawn. Now colourising should happen before the first draw.
+ * src/utils.c, src/highlighting.c, data/filetypes.common:
+ Fix segfault on parsing a filetypes.* style definition that has < 4
+ fields.
+ Allow style definitions to have missing fields to use the default
+ style fields.
2009-06-05 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/data/filetypes.common
===================================================================
--- trunk/data/filetypes.common 2009-06-05 15:57:01 UTC (rev 3842)
+++ trunk/data/filetypes.common 2009-06-05 15:59:58 UTC (rev 3843)
@@ -18,7 +18,7 @@
# background colour of the current line, only the second and third argument is interpreted
# use the third argument to enable or disable the highlighting of the current line (has to be true/false)
-current_line=0x0;0xf0f0f0;true;false
+current_line=0x000000;0xf0f0f0;true;false
# translucency for the current line(first argument) and the selection (second argument)
# values between 0 and 256 are accepted. Note for Windows 95, 98 and ME users:
@@ -40,7 +40,7 @@
# colour of the caret(the blinking cursor), only first and third argument is interpreted
# set the third argument to true to change the caret into a block caret
-caret=0x000000;0x0;false;false
+caret=0x000000;0x000000;false;false
# width of the caret(the blinking cursor), only first argument is interpreted
# width in pixels, use 0 to make it invisible, maximum width is 3
Modified: trunk/src/highlighting.c
===================================================================
--- trunk/src/highlighting.c 2009-06-05 15:57:01 UTC (rev 3842)
+++ trunk/src/highlighting.c 2009-06-05 15:59:58 UTC (rev 3843)
@@ -233,42 +233,59 @@
}
-/* FIXME: is not safe for badly formed key e.g. "key='" */
+static void parse_color(const gchar *str, gint *clr)
+{
+ gint c;
+
+ /* ignore empty strings */
+ if (!NZV(str))
+ return;
+
+ c = utils_strtod(str, NULL, FALSE);
+ if (c > -1)
+ {
+ *clr = c;
+ return;
+ }
+ geany_debug("Bad color '%s'", str);
+}
+
+
static void parse_keyfile_style(gchar **list,
const GeanyLexerStyle *default_style, GeanyLexerStyle *style)
{
+ gsize len;
+ gchar *str;
+
g_return_if_fail(default_style);
g_return_if_fail(style);
- if (G_LIKELY(list != NULL) && G_UNLIKELY(list[0] != NULL))
+ *style = *default_style;
+ style->foreground = rotate_rgb(default_style->foreground);
+ style->background = rotate_rgb(default_style->background);
+
+ if (!list)
+ return;
+
+ len = g_strv_length(list);
+
+ str = list[0];
+ if (len == 1 && isalpha(str[0]))
+ read_named_style(str, style);
+ else
{
- gchar *str = list[0];
-
- if (list[1] == NULL && isalpha(str[0]))
+ switch (len)
{
- read_named_style(str, style);
- return;
+ case 4:
+ style->italic = utils_atob(list[3]);
+ case 3:
+ style->bold = utils_atob(list[2]);
+ case 2:
+ parse_color(list[1], &style->background);
+ case 1:
+ parse_color(list[0], &style->foreground);
}
- else
- style->foreground = (gint) utils_strtod(str, NULL, FALSE);
}
- else
- style->foreground = rotate_rgb(default_style->foreground);
-
- if (G_LIKELY(list != NULL) && G_LIKELY(list[1] != NULL))
- style->background = (gint) utils_strtod(list[1], NULL, FALSE);
- else
- style->background = rotate_rgb(default_style->background);
-
- if (G_LIKELY(list != NULL) && G_LIKELY(list[2] != NULL))
- style->bold = utils_atob(list[2]);
- else
- style->bold = default_style->bold;
-
- if (G_LIKELY(list != NULL) && list[3] != NULL)
- style->italic = utils_atob(list[3]);
- else
- style->italic = default_style->italic;
}
@@ -304,6 +321,7 @@
}
+/* FIXME: is not safe for badly formed key e.g. "key=" */
static void get_keyfile_int(GKeyFile *config, GKeyFile *configh, const gchar *section,
const gchar *key, gint fdefault_val, gint sdefault_val,
GeanyLexerStyle *style)
Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c 2009-06-05 15:57:01 UTC (rev 3842)
+++ trunk/src/utils.c 2009-06-05 15:59:58 UTC (rev 3843)
@@ -943,7 +943,8 @@
/* utils_strtod() converts a string containing a hex colour ("0x00ff00") into an integer.
* Basically, it is the same as strtod() would do, but it does not understand hex colour values,
- * before ANSI-C99. With with_route set, it takes strings of the format "#00ff00". */
+ * before ANSI-C99. With with_route set, it takes strings of the format "#00ff00".
+ * Returns -1 on failure. */
gint utils_strtod(const gchar *source, gchar **end, gboolean with_route)
{
guint red, green, blue, offset = 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list