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.



git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3843 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2009-06-05 15:59:58 +00:00
parent 6f0d6d79ab
commit 60c7d9e5cf
4 changed files with 53 additions and 29 deletions

View File

@ -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>

View File

@ -18,7 +18,7 @@ margin_folding=0x000000;0xdfdfdf;false;false
# 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 @@ marker_translucency=256;256;false;false
# 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

View File

@ -233,42 +233,59 @@ static gint rotate_rgb(gint color)
}
/* 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 @@ static void get_keyfile_hex(GKeyFile *config, GKeyFile *configh,
}
/* 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)

View File

@ -943,7 +943,8 @@ gchar *utils_make_human_readable_str(guint64 size, gulong block_size,
/* 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;