From 2c93c7a2777f786f2778a0904567a93cc561671b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 18 Sep 2013 21:08:57 -0400 Subject: [PATCH] Use the appropriate string search functions instead of strstr everywhere. This mostly means using strchr, but I also found: option_parser.c:load_ini_file: - replace multiple calls to strstr with strpbrk notification.c:notification_init: - replace string_replace in a while loop with a single call to string_replace_char redo string replace all --- dunstify.c | 6 +++--- src/option_parser.c | 14 ++++++-------- src/x.c | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/dunstify.c b/dunstify.c index 6636a7c..6ae1788 100644 --- a/dunstify.c +++ b/dunstify.c @@ -199,7 +199,7 @@ void closed(NotifyNotification *n, gpointer foo) void add_action(NotifyNotification *n, char *str) { char *action = str; - char *label = strstr(str, ","); + char *label = strchr(str, ','); if (!label || *(label+1) == '\0') { g_printerr("Malformed action. Excpected \"action,label\", got \"%s\"", str); @@ -215,14 +215,14 @@ void add_action(NotifyNotification *n, char *str) void add_hint(NotifyNotification *n, char *str) { char *type = str; - char *name = strstr(str, ":"); + char *name = strchr(str, ':'); if (!name || *(name+1) == '\0') { g_printerr("Malformed hint. Expected \"type:name:value\", got \"%s\"", str); return; } *name = '\0'; name++; - char *value = strstr(name, ":"); + char *value = strchr(name, ':'); if (!value || *(value+1) == '\0') { g_printerr("Malformed hint. Expected \"type:name:value\", got \"%s\"", str); return; diff --git a/src/option_parser.c b/src/option_parser.c index 7b682cd..48d92e0 100644 --- a/src/option_parser.c +++ b/src/option_parser.c @@ -214,7 +214,7 @@ int load_ini_file(FILE * fp) continue; if (*start == '[') { - char *end = strstr(start + 1, "]"); + char *end = strchr(start + 1, ']'); if (!end) { printf ("Warning: invalid config file at line %d\n", @@ -232,7 +232,7 @@ int load_ini_file(FILE * fp) continue; } - char *equal = strstr(start + 1, "="); + char *equal = strchr(start + 1, '='); if (!equal) { printf("Warning: invalid config file at line %d\n", line_num); @@ -244,9 +244,9 @@ int load_ini_file(FILE * fp) char *key = g_strstrip(start); char *value = g_strstrip(equal + 1); - char *quote = strstr(value, "\""); + char *quote = strchr(value, '"'); if (quote) { - char *closing_quote = strstr(quote + 1, "\""); + char *closing_quote = strchr(quote + 1, '"'); if (!closing_quote) { printf ("Warning: invalid config file at line %d\n", @@ -257,9 +257,7 @@ int load_ini_file(FILE * fp) closing_quote = '\0'; } else { - char *comment = strstr(value, "#"); - if (!comment) - comment = strstr(value, ";"); + char *comment = strpbrk(value, "#;"); if (comment) comment = '\0'; } @@ -291,7 +289,7 @@ int cmdline_find_option(char *key) return -1; } char *key1 = g_strdup(key); - char *key2 = strstr(key1, "/"); + char *key2 = strchr(key1, '/'); if (key2) { *key2 = '\0'; diff --git a/src/x.c b/src/x.c index a5e5c70..4316853 100644 --- a/src/x.c +++ b/src/x.c @@ -1383,7 +1383,7 @@ void x_shortcut_init(keyboard_shortcut * ks) if (str == NULL) die("Unable to allocate memory", EXIT_FAILURE); - while (strstr(str, "+")) { + while (strchr(str, '+')) { char *mod = str; while (*str != '+') str++;