summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQC <qball@gmpclient.org>2015-07-07 21:50:09 +0200
committerQC <qball@gmpclient.org>2015-07-07 21:51:15 +0200
commit1de8d448f70cce50c2b5da3a1857b77c6e133b8d (patch)
treeead710912d6bc0c144023b83cf6e837dfafed0bb
parentb3bc620211617443dfe1cefab4bfdc9d944f64d9 (diff)
Make color parsing more robust, report failing of parsing color.
Involves: #181
-rw-r--r--source/textbox.c20
-rw-r--r--source/x11-helper.c16
2 files changed, 26 insertions, 10 deletions
diff --git a/source/textbox.c b/source/textbox.c
index d5fe2e52..f6f7d0d9 100644
--- a/source/textbox.c
+++ b/source/textbox.c
@@ -667,10 +667,16 @@ static void parse_color ( Visual *visual, Colormap colormap,
col.red = ( ( val & 0x00FF0000 ) >> 16 ) * 255;
col.green = ( ( val & 0x0000FF00 ) >> 8 ) * 255;
col.blue = ( ( val & 0x000000FF ) ) * 255;
- XftColorAllocValue ( display, visual, colormap, &col, color );
+ if ( !XftColorAllocValue ( display, visual, colormap, &col, color ) ) {
+ fprintf ( stderr, "Failed to parse color: '%s'\n", bg );
+ exit ( EXIT_FAILURE );
+ }
}
else {
- XftColorAllocName ( display, visual, colormap, bg, color );
+ if ( !XftColorAllocName ( display, visual, colormap, bg, color ) ) {
+ fprintf ( stderr, "Failed to parse color: '%s'\n", bg );
+ exit ( EXIT_FAILURE );
+ }
}
}
static void textbox_parse_string ( XVisualInfo *visual, Colormap colormap, const char *str, RowColor *color )
@@ -686,19 +692,19 @@ static void textbox_parse_string ( XVisualInfo *visual, Colormap colormap, const
switch ( index )
{
case 0:
- parse_color ( visual->visual, colormap, token, &( color->bg ) );
+ parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->bg ) );
break;
case 1:
- parse_color ( visual->visual, colormap, token, &( color->fg ) );
+ parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->fg ) );
break;
case 2:
- parse_color ( visual->visual, colormap, token, &( color->bgalt ) );
+ parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->bgalt ) );
break;
case 3:
- parse_color ( visual->visual, colormap, token, &( color->hlbg ) );
+ parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->hlbg ) );
break;
case 4:
- parse_color ( visual->visual, colormap, token, &( color->hlfg ) );
+ parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->hlfg ) );
break;
}
index++;
diff --git a/source/x11-helper.c b/source/x11-helper.c
index 8c158272..dd43f7b7 100644
--- a/source/x11-helper.c
+++ b/source/x11-helper.c
@@ -443,12 +443,22 @@ unsigned int color_get ( Display *display, const char *const name )
color.blue = ( ( color.pixel & 0x000000FF ) ) * 255;
if ( !truecolor ) {
// This will drop alpha part.
- return XAllocColor ( display, map, &color ) ? color.pixel : None;
+ Status st = XAllocColor ( display, map, &color );
+ if ( st == None ) {
+ fprintf ( stderr, "Failed to parse color: '%s'\n", name );
+ exit ( EXIT_FAILURE );
+ }
+ return color.pixel;
}
return color.pixel;
}
else {
- return XAllocNamedColor ( display, map, name, &color, &color ) ? color.pixel : None;
+ Status st = XAllocNamedColor ( display, map, name, &color, &color );
+ if ( st == None ) {
+ fprintf ( stderr, "Failed to parse color: '%s'\n", name );
+ exit ( EXIT_FAILURE );
+ }
+ return color.pixel;
}
}
@@ -462,7 +472,7 @@ unsigned int color_background ( Display *display )
gchar **vals = g_strsplit ( config.color_window, ",", 2 );
if ( vals != NULL && vals[0] != NULL ) {
- retv = color_get ( display, vals[0] );
+ retv = color_get ( display, g_strstrip ( vals[0] ) );
}
g_strfreev ( vals );
return retv;