diff options
author | Daniel Wagner <daniel.wagner@bmw-carit.de> | 2013-08-08 10:42:41 +0200 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2013-08-20 11:33:29 +0300 |
commit | 889569b3e6bab53b119f863d932b6f36923de9a7 (patch) | |
tree | 4516b9dcbc689625d4c92f3150dd661beee7e95b | |
parent | afa1e7a2d5f95e58c80d3d6638b9d3baeb65ecc5 (diff) | |
download | pacrunner-889569b3e6bab53b119f863d932b6f36923de9a7.tar.gz |
tools: Do not compare expression against NULL
This patch generate via coccinelle with:
@ disable is_null,isnt_null1 @
expression E;
@@
(
- E == NULL
+ !E
|
- E != NULL
+ E
)
-rw-r--r-- | tools/manual-proxy-test.c | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/tools/manual-proxy-test.c b/tools/manual-proxy-test.c index 4ee4e87..813509d 100644 --- a/tools/manual-proxy-test.c +++ b/tools/manual-proxy-test.c @@ -62,7 +62,7 @@ struct pacrunner_manual_exclude { static enum pacrunner_manual_protocol get_protocol_from_string(const char *protocol) { - if (protocol == NULL) + if (!protocol) return PACRUNNER_PROTOCOL_ALL; if (g_strcmp0(protocol, "http") == 0) @@ -141,17 +141,17 @@ static int parse_uri(char *uri, /** * Make sure host and protocol, if given, are properly set. */ - if (host != NULL) + if (host) *host = NULL; - if (protocol != NULL) + if (protocol) *protocol = NULL; /** * The parsing will actually process on a copy of given uri */ scheme = g_strdup(uri); - if (scheme == NULL) + if (!scheme) goto error; cur = scheme; @@ -161,15 +161,15 @@ static int parse_uri(char *uri, * Note: protocol scheme is here totally ignored */ sep = strstr(cur, "://"); - if (sep != NULL) { + if (sep) { if (sep == cur) goto error; - if (protocol != NULL) { + if (protocol) { *sep = '\0'; *protocol = g_strdup(cur); - if (*protocol == NULL) + if (!*protocol) goto error; } @@ -183,7 +183,7 @@ static int parse_uri(char *uri, * no path should be present */ sep = strchr(cur, '/'); - if (sep != NULL) { + if (sep) { if (exclusion || (*(sep + 1) != '\0' && no_path)) goto error; @@ -196,7 +196,7 @@ static int parse_uri(char *uri, * Note: exclusion rule cannot contain such authentication information */ sep = strchr(cur, '@'); - if (sep != NULL) { + if (sep) { if (exclusion) goto error; @@ -209,11 +209,11 @@ static int parse_uri(char *uri, * Note: ipv6 format is not checked! */ sep = strchr(cur, '['); - if (sep != NULL) { + if (sep) { char *bracket; bracket = strchr(cur, ']'); - if (bracket == NULL) + if (!bracket) goto error; cur = sep; @@ -227,7 +227,7 @@ static int parse_uri(char *uri, * 5 - Checking port validity if present * Note: exclusion rule cannot embed port */ - if (sep != NULL) { + if (sep) { char *err = NULL; if (exclusion) @@ -299,7 +299,7 @@ static int parse_uri(char *uri, forbidden_chars = "%?!,;@\\'*|<>{}[]()+=$&~# \""; forbidden = g_strsplit_set(cur, forbidden_chars, -1); - if (forbidden != NULL) { + if (forbidden) { length = g_strv_length(forbidden); g_strfreev(forbidden); @@ -307,7 +307,7 @@ static int parse_uri(char *uri, goto error; } - if (host != NULL && *cur != '\0') { + if (host && *cur != '\0') { if (port > 0) { /** * Instead of transcoding the port back @@ -317,7 +317,7 @@ static int parse_uri(char *uri, cur = uri + (cur - scheme); sep = strchr(cur, '/'); - if (sep != NULL) + if (sep) length = sep - cur; else length = strlen(cur); @@ -326,7 +326,7 @@ static int parse_uri(char *uri, } else *host = g_strdup(cur); - if (*host == NULL) + if (!*host) goto error; } } else { @@ -342,7 +342,7 @@ static int parse_uri(char *uri, return ret; error: - if (protocol != NULL) { + if (protocol) { g_free(*protocol); *protocol = NULL; } @@ -357,7 +357,7 @@ static void free_exclude(gpointer data) struct pacrunner_manual_exclude *exclude; exclude = (struct pacrunner_manual_exclude *) data; - if (exclude == NULL) + if (!exclude) return; g_free(exclude->host); @@ -368,7 +368,7 @@ static void __pacrunner_manual_destroy_excludes(GList **excludes) { int i; - if (excludes == NULL) + if (!excludes) return; for (i = 0; i < PACRUNNER_PROTOCOL_MAXIMUM_NUMBER; i++) @@ -385,15 +385,15 @@ static GList **__pacrunner_manual_create_excludes(const char **excludes) int ret, proto; char **uri; - if (excludes == NULL) + if (!excludes) return NULL; result = g_try_malloc0(PACRUNNER_PROTOCOL_MAXIMUM_NUMBER * sizeof(GList *)); - if (result == NULL) + if (!result) return NULL; - for (uri = (char **)excludes; *uri != NULL; uri++) { + for (uri = (char **)excludes; *uri; uri++) { ret = parse_uri(*uri, &host, &protocol, true, true); if (ret < 0) @@ -405,13 +405,13 @@ static GList **__pacrunner_manual_create_excludes(const char **excludes) exclude = g_try_malloc0(sizeof( struct pacrunner_manual_exclude)); - if (exclude == NULL) + if (!exclude) goto error; exclude->appliance = ret; exclude->host = host; - if (host != NULL) + if (host) exclude->host_length = strlen(host); result[proto] = g_list_append(result[proto], exclude); @@ -436,7 +436,7 @@ static void __pacrunner_manual_destroy_servers(GList **servers) { int i; - if (servers == NULL) + if (!servers) return; for (i = 0; i < PACRUNNER_PROTOCOL_MAXIMUM_NUMBER; i++) @@ -474,7 +474,7 @@ static GList *append_proxy(GList *list, proxy = g_strdup_printf("%s %s", protocol_to_prefix_string(proto), host); - if (proxy == NULL) + if (!proxy) return list; return g_list_append(list, proxy); @@ -488,15 +488,15 @@ static GList **__pacrunner_manual_create_servers(const char **servers) int proto; int ret; - if (servers == NULL) + if (!servers) return NULL; result = g_try_malloc0(PACRUNNER_PROTOCOL_MAXIMUM_NUMBER * sizeof(GList *)); - if (result == NULL) + if (!result) return NULL; - for (uri = (char **)servers; *uri != NULL; uri++) { + for (uri = (char **)servers; *uri; uri++) { ret = parse_uri(*uri, &host, &protocol, true, false); if (ret < 0) @@ -539,20 +539,20 @@ static bool is_exclusion_matching(GList *excludes_list, GList *excludes = NULL; char *cursor; - for (excludes = excludes_list; excludes != NULL; + for (excludes = excludes_list; excludes; excludes = excludes->next) { exclusion = (struct pacrunner_manual_exclude *) excludes->data; - if (exclusion == NULL) + if (!exclusion) continue; cursor = NULL; - if (exclusion->host != NULL) + if (exclusion->host) cursor = strstr(host, exclusion->host); switch (exclusion->appliance) { case PACRUNNER_MANUAL_EXCLUDE_POST: - if (cursor == NULL) + if (!cursor) break; if ((int)strlen(cursor) < exclusion->host_length) @@ -568,8 +568,8 @@ static bool is_exclusion_matching(GList *excludes_list, break; case PACRUNNER_MANUAL_EXCLUDE_ANY: - if (exclusion->host != NULL) { - if (cursor != NULL) + if (exclusion->host) { + if (cursor) return true; else break; @@ -588,10 +588,10 @@ static bool is_url_excluded(GList **excludes, const char *host, enum pacrunner_manual_protocol proto) { - if (excludes == NULL) + if (!excludes) return false; - if (excludes[PACRUNNER_PROTOCOL_ALL] != NULL) + if (excludes[PACRUNNER_PROTOCOL_ALL]) if (is_exclusion_matching(excludes[PACRUNNER_PROTOCOL_ALL], host)) return true; @@ -599,7 +599,7 @@ static bool is_url_excluded(GList **excludes, if (proto == PACRUNNER_PROTOCOL_UNKNOWN) return false; - if (excludes[proto] != NULL) + if (excludes[proto]) if (is_exclusion_matching(excludes[proto], host)) return true; @@ -610,11 +610,11 @@ static inline char *append_server(char *prev_result, const char *proxy) { char *result; - if (prev_result == NULL) + if (!prev_result) return g_strdup(proxy); result = g_strjoin("; ", prev_result, proxy, NULL); - if (result == NULL) + if (!result) return prev_result; g_free(prev_result); @@ -629,7 +629,7 @@ static inline char *append_servers_to_proxy_string(char *prev_result, GList *list, *prev; prev = NULL; - for (list = proxies; list != NULL && list != prev; + for (list = proxies; list && list != prev; prev = list, list = list->next) result = append_server(result, (const char *) list->data); @@ -646,15 +646,15 @@ static char *generate_proxy_string(GList **servers, * protocol-based proxies first, if any... */ if (proto >= PACRUNNER_PROTOCOL_HTTP && proto < PACRUNNER_PROTOCOL_MAXIMUM_NUMBER) { - if (servers[proto] != NULL) + if (servers[proto]) result = append_servers_to_proxy_string(result, servers[proto]); if (proto == PACRUNNER_PROTOCOL_SOCKS) { - if (servers[PACRUNNER_PROTOCOL_SOCKS4] != NULL) + if (servers[PACRUNNER_PROTOCOL_SOCKS4]) result = append_servers_to_proxy_string(result, servers[PACRUNNER_PROTOCOL_SOCKS4]); - if (servers[PACRUNNER_PROTOCOL_SOCKS5] != NULL) + if (servers[PACRUNNER_PROTOCOL_SOCKS5]) result = append_servers_to_proxy_string(result, servers[PACRUNNER_PROTOCOL_SOCKS5]); } @@ -667,7 +667,7 @@ static char *generate_proxy_string(GList **servers, i == PACRUNNER_PROTOCOL_SOCKS5))) continue; - if (servers[i] != NULL) + if (servers[i]) result = append_servers_to_proxy_string(result, servers[i]); } @@ -684,7 +684,7 @@ static char *__pacrunner_manual_execute(const char *url, char *host = NULL; int proto; - if (servers == NULL) + if (!servers) return NULL; if (parse_uri((char *)url, &host, &protocol, false, false) < 0) @@ -709,7 +709,7 @@ static void dump_proxy_exclusion(gpointer data, gpointer user_data) struct pacrunner_manual_exclude *exclusion; exclusion = (struct pacrunner_manual_exclude *) data; - if (exclusion == NULL) + if (!exclusion) return; printf("\tappliance: %s\n", @@ -723,7 +723,7 @@ static void dump_excludes(GList **excludes) printf("EXCLUDES:\n"); - if (excludes == NULL) { + if (!excludes) { printf("\tNO EXCLUDES\n"); return; } @@ -731,7 +731,7 @@ static void dump_excludes(GList **excludes) for (i = 0; i < PACRUNNER_PROTOCOL_MAXIMUM_NUMBER; i++) { printf("Protocol: %s\n", get_protocol_to_string(i)); - if (excludes[i] == NULL) { + if (!excludes[i]) { printf("\tNONE\n"); continue; } @@ -752,7 +752,7 @@ static void dump_servers(GList **servers) printf("SERVERS:\n"); - if (servers == NULL) { + if (!servers) { printf("\tNO SERVERS\n"); return; } @@ -760,7 +760,7 @@ static void dump_servers(GList **servers) for (i = 0; i < PACRUNNER_PROTOCOL_MAXIMUM_NUMBER; i++) { printf("Protocol: %s\n", get_protocol_to_string(i)); - if (servers[i] == NULL) { + if (!servers[i]) { printf("\tNONE\n"); continue; } @@ -824,7 +824,7 @@ int main(int argc, char *argv[]) switch (opt) { case 'e': excludes_list = g_strsplit(optarg, ",", 0); - if (excludes_list == NULL) + if (!excludes_list) exit(EXIT_FAILURE); break; @@ -835,13 +835,13 @@ int main(int argc, char *argv[]) break; case 's': servers_list = g_strsplit(optarg, ",", 0); - if (servers_list == NULL) + if (!servers_list) exit(EXIT_FAILURE); break; case 't': tests_list = g_strsplit(optarg, ",", 0); - if (tests_list == NULL) + if (!tests_list) exit(EXIT_FAILURE); break; @@ -856,14 +856,14 @@ int main(int argc, char *argv[]) } } - if (servers_list == NULL || tests_list == NULL) { + if (!servers_list || !tests_list) { printf("You must provide server(s) and test(s) options\n"); exit(EXIT_FAILURE); } servers = __pacrunner_manual_create_servers((const char **) servers_list); - if (servers == NULL) + if (!servers) exit(EXIT_FAILURE); excludes = __pacrunner_manual_create_excludes((const char **) @@ -875,13 +875,13 @@ int main(int argc, char *argv[]) g_strfreev(excludes_list); g_strfreev(servers_list); - for (url = tests_list; *url != NULL; url++) { + for (url = tests_list; *url; url++) { char *proxy; printf("Url: %s -> ", *url); proxy = __pacrunner_manual_execute(*url, servers, excludes); - if (proxy == NULL) + if (!proxy) printf("DIRECT\n"); else printf("%s\n", proxy); |