diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-03-19 13:29:04 +0100 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-03-19 13:29:04 +0100 |
commit | a2869ef39d1e78c70877df27dc9a6ebc66962842 (patch) | |
tree | 98715f56cd4792a9c8b68a9933765a113fd37d41 | |
parent | 1f8db0fc5a1da29346119937da5fe559469af2bc (diff) |
Make clang static code analyzer happy (300+ -> 5)
-rw-r--r-- | source/dialogs/combi.c | 5 | ||||
-rw-r--r-- | source/dialogs/dmenu.c | 6 | ||||
-rw-r--r-- | source/dialogs/run.c | 3 | ||||
-rw-r--r-- | source/dialogs/script.c | 3 | ||||
-rw-r--r-- | source/dialogs/ssh.c | 3 | ||||
-rw-r--r-- | source/helper.c | 3 | ||||
-rw-r--r-- | source/keyb.c | 3 | ||||
-rw-r--r-- | source/rofi.c | 3 | ||||
-rw-r--r-- | source/textbox.c | 3 | ||||
-rw-r--r-- | source/view.c | 7 | ||||
-rw-r--r-- | source/xrmoptions.c | 8 |
11 files changed, 31 insertions, 16 deletions
diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 1a266968..3dc1a773 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -53,9 +53,10 @@ static void combi_mode_parse_switchers ( Mode *sw ) char *savept = NULL; // Make a copy, as strtok will modify it. char *switcher_str = g_strdup ( config.combi_modi ); + const char * const sep = ","; // Split token on ','. This modifies switcher_str. - for ( char *token = strtok_r ( switcher_str, ",", &savept ); token != NULL; - token = strtok_r ( NULL, ",", &savept ) ) { + for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; + token = strtok_r ( NULL, sep, &savept ) ) { // Resize and add entry. pd->switchers = (Mode * *) g_realloc ( pd->switchers, sizeof ( Mode* ) * ( pd->num_switchers + 1 ) ); diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 9add4934..89352bba 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -123,7 +123,8 @@ static unsigned int dmenu_mode_get_num_entries ( const Mode *sw ) static void parse_pair ( char *input, struct range_pair *item ) { int index = 0; - for ( char *token = strsep ( &input, "-" ); token != NULL; token = strsep ( &input, "-" ) ) { + const char * const sep = "-"; + for ( char *token = strsep ( &input, sep ); token != NULL; token = strsep ( &input, sep ) ) { if ( index == 0 ) { item->start = item->stop = (unsigned int) strtoul ( token, NULL, 10 ); index++; @@ -145,7 +146,8 @@ static void parse_ranges ( char *input, struct range_pair **list, unsigned int * if ( input == NULL ) { return; } - for ( char *token = strtok_r ( input, ",", &endp ); token != NULL; token = strtok_r ( NULL, ",", &endp ) ) { + const char *const sep =","; + for ( char *token = strtok_r ( input, sep, &endp ); token != NULL; token = strtok_r ( NULL, sep, &endp ) ) { // Make space. *list = g_realloc ( ( *list ), ( ( *length ) + 1 ) * sizeof ( struct range_pair ) ); // Parse a single pair. diff --git a/source/dialogs/run.c b/source/dialogs/run.c index f6c51ce7..fc8afa89 100644 --- a/source/dialogs/run.c +++ b/source/dialogs/run.c @@ -249,7 +249,8 @@ static char ** get_apps ( unsigned int *length ) return NULL; } - for ( const char *dirname = strtok ( path, ":" ); dirname != NULL; dirname = strtok ( NULL, ":" ) ) { + const char *const sep = ":"; + for ( const char *dirname = strtok ( path, sep ); dirname != NULL; dirname = strtok ( NULL, sep ) ) { DIR *dir = opendir ( dirname ); if ( dir != NULL ) { diff --git a/source/dialogs/script.c b/source/dialogs/script.c index 99f7e41c..ef2c8d45 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -183,7 +183,8 @@ Mode *script_switcher_parse_setup ( const char *str ) char *endp = NULL; char *parse = g_strdup ( str ); unsigned int index = 0; - for ( char *token = strtok_r ( parse, ":", &endp ); token != NULL; token = strtok_r ( NULL, ":", &endp ) ) { + const char *const sep = ":"; + for ( char *token = strtok_r ( parse, sep, &endp ); token != NULL; token = strtok_r ( NULL, sep, &endp ) ) { if ( index == 0 ) { g_strlcpy ( sw->name, token, 32 ); } diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index a2fe8b3f..28b66a3d 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -303,7 +303,8 @@ static char ** get_ssh ( unsigned int *length ) // (how many host names contain spaces?). while ( ( token = strtok ( NULL, SSH_TOKEN_DELIM ) ) ) { // We do not want to show wildcard entries, as you cannot ssh to them. - if ( *token == '!' || strpbrk ( token, "*?" ) ) { + const char *const sep = "*?"; + if ( *token == '!' || strpbrk ( token, sep ) ) { continue; } diff --git a/source/helper.c b/source/helper.c index ab1c1d18..e145910c 100644 --- a/source/helper.c +++ b/source/helper.c @@ -211,7 +211,8 @@ char **tokenize ( const char *input, int case_sensitive ) // Iterate over tokens. // strtok should still be valid for utf8. - for ( token = strtok_r ( str, " ", &saveptr ); token != NULL; token = strtok_r ( NULL, " ", &saveptr ) ) { + const char * const sep = " "; + for ( token = strtok_r ( str, sep, &saveptr ); token != NULL; token = strtok_r ( NULL, sep, &saveptr ) ) { retv = g_realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) ); if ( config.glob ) { char *str = g_strdup_printf ( "*%s*", token ); diff --git a/source/keyb.c b/source/keyb.c index 6d3dbec4..972dd0c3 100644 --- a/source/keyb.c +++ b/source/keyb.c @@ -111,7 +111,8 @@ gboolean parse_keys_abe ( void ) abe[iter].num_bindings = 0; // Iter over bindings. - for ( char *entry = strtok_r ( keystr, ",", &sp ); entry != NULL; entry = strtok_r ( NULL, ",", &sp ) ) { + const char *const sep = ","; + for ( char *entry = strtok_r ( keystr, sep, &sp ); entry != NULL; entry = strtok_r ( NULL, sep, &sp ) ) { abe[iter].kb = g_realloc ( abe[iter].kb, ( abe[iter].num_bindings + 1 ) * sizeof ( KeyBinding ) ); KeyBinding *kb = &( abe[iter].kb[abe[iter].num_bindings] ); if ( !x11_parse_key ( entry, &( kb->modmask ), &( kb->keysym ) ) ) { diff --git a/source/rofi.c b/source/rofi.c index 0acb1c94..fd048680 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -403,11 +403,12 @@ static int add_mode ( const char * token ) } static void setup_modi ( void ) { + const char *const sep =","; char *savept = NULL; // Make a copy, as strtok will modify it. char *switcher_str = g_strdup ( config.modi ); // Split token on ','. This modifies switcher_str. - for ( char *token = strtok_r ( switcher_str, ",", &savept ); token != NULL; token = strtok_r ( NULL, ",", &savept ) ) { + for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) { add_mode ( token ); } // Free string that was modified by strtok_r diff --git a/source/textbox.c b/source/textbox.c index 29fb2149..f50355ee 100644 --- a/source/textbox.c +++ b/source/textbox.c @@ -622,7 +622,8 @@ static void textbox_parse_string ( const char *str, RowColor *color ) char *endp = NULL; char *token; int index = 0; - for ( token = strtok_r ( cstr, ",", &endp ); token != NULL; token = strtok_r ( NULL, ",", &endp ) ) { + const char *const sep = ","; + for ( token = strtok_r ( cstr, sep, &endp ); token != NULL; token = strtok_r ( NULL, sep, &endp ) ) { switch ( index ) { case 0: diff --git a/source/view.c b/source/view.c index bfdc19a4..3a188561 100644 --- a/source/view.c +++ b/source/view.c @@ -62,6 +62,9 @@ #include "xcb.h" +const char *const separator_style_none = "none"; +const char *const separator_style_dash = "dash"; + GThreadPool *tpool = NULL; RofiViewState *current_active_menu = NULL; @@ -931,8 +934,8 @@ void rofi_view_update ( RofiViewState *state ) } color_separator ( d ); - if ( strcmp ( config.separator_style, "none" ) ) { - if ( strcmp ( config.separator_style, "dash" ) == 0 ) { + if ( strcmp ( config.separator_style, separator_style_none ) ) { + if ( strcmp ( config.separator_style, separator_style_dash ) == 0 ) { const double dashes[1] = { 4 }; cairo_set_dash ( d, dashes, 1, 0.0 ); } diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 07486d4e..021f4198 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -523,13 +523,15 @@ void config_parse_xresources_theme_dump ( void ) printf ( "! ROFI Color theme\n" ); printf ( "! User: %s\n", g_get_user_name () ); printf ( "! ------------------------------------------------------------------------------\n" ); - const char * namePrefix = "rofi"; + const char * const namePrefix = "rofi"; + const char colorPrefix[] = "color-"; + const char separatorStyle[] = "separator-style"; unsigned int entries = sizeof ( xrmOptions ) / sizeof ( *xrmOptions ); for ( unsigned int i = 0; i < entries; ++i ) { - if ( strncmp ( xrmOptions[i].name, "color-", 6 ) == 0 ) { + if ( strncmp ( xrmOptions[i].name, colorPrefix, sizeof(colorPrefix)-1 ) == 0 ) { xresource_dump_entry ( namePrefix, &xrmOptions[i] ); } - else if ( strcmp ( xrmOptions[i].name, "separator-style" ) == 0 ) { + else if ( strcmp ( xrmOptions[i].name, separatorStyle ) == 0 ) { xresource_dump_entry ( namePrefix, &xrmOptions[i] ); } } |