aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2013-08-08 10:42:40 +0200
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-08-20 11:33:29 +0300
commitafa1e7a2d5f95e58c80d3d6638b9d3baeb65ecc5 (patch)
tree031d3c54cbe8ff838054025b334e828f9581ec35
parent30f5bc782c0cd599aecce545ba18254ec4c5f058 (diff)
downloadpacrunner-afa1e7a2d5f95e58c80d3d6638b9d3baeb65ecc5.tar.gz
core: 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--src/client.c4
-rw-r--r--src/log.c14
-rw-r--r--src/main.c4
-rw-r--r--src/manager.c12
-rw-r--r--src/manual.c94
-rw-r--r--src/plugin.c14
-rw-r--r--src/proxy.c44
7 files changed, 93 insertions, 93 deletions
diff --git a/src/client.c b/src/client.c
index 1919146..d354c2b 100644
--- a/src/client.c
+++ b/src/client.c
@@ -64,7 +64,7 @@ static void *jsrun_thread(void *data)
DBG("result %s", result);
- if (result == NULL)
+ if (!result)
result = direct;
g_dbus_send_reply(jsrun->conn, jsrun->msg, DBUS_TYPE_STRING, &result,
@@ -86,7 +86,7 @@ static DBusMessage *find_proxy_for_url(DBusConnection *conn,
struct jsrun_data *jsrun;
jsrun = g_try_new0(struct jsrun_data, 1);
- if (jsrun == NULL)
+ if (!jsrun)
return g_dbus_create_error(msg,
PACRUNNER_ERROR_INTERFACE ".Failed",
"Out of memory");
diff --git a/src/log.c b/src/log.c
index 9769e3d..74ad7e4 100644
--- a/src/log.c
+++ b/src/log.c
@@ -81,14 +81,14 @@ static bool is_enabled(struct pacrunner_debug_desc *desc)
{
int i;
- if (enabled == NULL)
+ if (!enabled)
return false;
- for (i = 0; enabled[i] != NULL; i++) {
- if (desc->name != NULL && g_pattern_match_simple(enabled[i],
+ for (i = 0; enabled[i]; i++) {
+ if (desc->name && g_pattern_match_simple(enabled[i],
desc->name))
return true;
- if (desc->file != NULL && g_pattern_match_simple(enabled[i],
+ if (desc->file && g_pattern_match_simple(enabled[i],
desc->file))
return true;
}
@@ -102,13 +102,13 @@ int __pacrunner_log_init(const char *debug, bool detach)
struct pacrunner_debug_desc *desc;
const char *name = NULL, *file = NULL;
- if (debug != NULL)
+ if (debug)
enabled = g_strsplit_set(debug, ":, ", 0);
for (desc = __start___debug; desc < __stop___debug; desc++) {
- if (file != NULL || name != NULL) {
+ if (file || name) {
if (g_strcmp0(desc->file, file) == 0) {
- if (desc->name == NULL)
+ if (!desc->name)
desc->name = name;
} else
file = NULL;
diff --git a/src/main.c b/src/main.c
index 7822660..aa3f876 100644
--- a/src/main.c
+++ b/src/main.c
@@ -158,7 +158,7 @@ int main(int argc, char *argv[])
g_option_context_add_main_entries(context, options, NULL);
if (!g_option_context_parse(context, &argc, &argv, &error)) {
- if (error != NULL) {
+ if (error) {
g_printerr("%s\n", error->message);
g_error_free(error);
} else
@@ -192,7 +192,7 @@ int main(int argc, char *argv[])
dbus_error_init(&err);
conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, PACRUNNER_SERVICE, &err);
- if (conn == NULL) {
+ if (!conn) {
if (dbus_error_is_set(&err)) {
fprintf(stderr, "%s\n", err.message);
dbus_error_free(&err);
diff --git a/src/manager.c b/src/manager.c
index dd0cb1f..1676466 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -83,11 +83,11 @@ static struct proxy_config *create_config(DBusConnection *conn,
struct proxy_config *config;
config = g_try_new0(struct proxy_config, 1);
- if (config == NULL)
+ if (!config)
return NULL;
config->proxy = pacrunner_proxy_create(interface);
- if (config->proxy == NULL) {
+ if (!config->proxy) {
g_free(config);
return NULL;
}
@@ -111,7 +111,7 @@ static char **extract_string_array(DBusMessageIter *array)
int index;
str = g_try_new(char *, 11);
- if (str == NULL)
+ if (!str)
return NULL;
index = 0;
@@ -121,7 +121,7 @@ static char **extract_string_array(DBusMessageIter *array)
dbus_message_iter_get_basic(array, &value);
- if (value == NULL || index > 9)
+ if (!value || index > 9)
break;
str[index++] = g_strdup(value);
@@ -209,7 +209,7 @@ static DBusMessage *create_proxy_config(DBusConnection *conn,
DBG("sender %s method %s interface %s", sender, method, interface);
DBG("url %s script %p", url, script);
- if (method == NULL) {
+ if (!method) {
reply = g_dbus_create_error(msg,
PACRUNNER_ERROR_INTERFACE ".Failed",
"No proxy method specified");
@@ -217,7 +217,7 @@ static DBusMessage *create_proxy_config(DBusConnection *conn,
}
config = create_config(conn, sender, interface);
- if (config == NULL) {
+ if (!config) {
reply = g_dbus_create_error(msg,
PACRUNNER_ERROR_INTERFACE ".Failed",
"Memory allocation failed");
diff --git a/src/manual.c b/src/manual.c
index 73d9398..16398d0 100644
--- a/src/manual.c
+++ b/src/manual.c
@@ -71,17 +71,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;
@@ -91,15 +91,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;
}
@@ -113,7 +113,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;
@@ -126,7 +126,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;
@@ -139,11 +139,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;
@@ -157,7 +157,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)
@@ -229,7 +229,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);
@@ -237,7 +237,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
@@ -247,7 +247,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);
@@ -256,7 +256,7 @@ static int parse_uri(char *uri,
} else
*host = g_strdup(cur);
- if (*host == NULL)
+ if (!*host)
goto error;
}
} else {
@@ -272,7 +272,7 @@ static int parse_uri(char *uri,
return ret;
error:
- if (protocol != NULL) {
+ if (protocol) {
g_free(*protocol);
*protocol = NULL;
}
@@ -284,7 +284,7 @@ error:
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)
@@ -332,7 +332,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);
@@ -346,15 +346,15 @@ GList **__pacrunner_manual_parse_servers(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)
@@ -394,7 +394,7 @@ void __pacrunner_manual_destroy_servers(GList **servers)
{
int i;
- if (servers == NULL)
+ if (!servers)
return;
for (i = 0; i < PACRUNNER_PROTOCOL_MAXIMUM_NUMBER; i++)
@@ -412,15 +412,15 @@ GList **__pacrunner_manual_parse_excludes(char **excludes)
int proto;
int ret;
- 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)
@@ -432,13 +432,13 @@ GList **__pacrunner_manual_parse_excludes(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);
@@ -464,7 +464,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);
@@ -475,7 +475,7 @@ void __pacrunner_manual_destroy_excludes(GList **excludes)
{
int i;
- if (excludes == NULL)
+ if (!excludes)
return;
for (i = 0; i < PACRUNNER_PROTOCOL_MAXIMUM_NUMBER; i++)
@@ -491,20 +491,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)
@@ -520,8 +520,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;
@@ -540,10 +540,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;
@@ -551,7 +551,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;
@@ -562,11 +562,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);
@@ -581,7 +581,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);
@@ -598,15 +598,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]);
}
@@ -619,7 +619,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]);
}
@@ -637,10 +637,10 @@ char *__pacrunner_manual_execute(const char *url, const char *host,
DBG("url %s host %s", url, host);
- if (servers == NULL || (url == NULL && host == NULL))
+ if (!servers || (!url && !host))
return NULL;
- if (url == NULL)
+ if (!url)
url = host;
if (parse_uri((char *)url, &host_p, &protocol, false, false) < 0)
diff --git a/src/plugin.c b/src/plugin.c
index c8552ca..d91cf3e 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -43,11 +43,11 @@ static bool add_plugin(void *handle, struct pacrunner_plugin_desc *desc)
{
struct pacrunner_plugin *plugin;
- if (desc->init == NULL)
+ if (!desc->init)
return false;
plugin = g_try_new0(struct pacrunner_plugin, 1);
- if (plugin == NULL)
+ if (!plugin)
return false;
plugin->handle = handle;
@@ -119,10 +119,10 @@ int __pacrunner_plugin_init(const char *pattern, const char *exclude)
}
dir = g_dir_open(PLUGINDIR, 0, NULL);
- if (dir == NULL)
+ if (!dir)
return -EIO;
- while ((file = g_dir_read_name(dir)) != NULL) {
+ while ((file = g_dir_read_name(dir))) {
struct pacrunner_plugin_desc *desc;
void *handle;
char *filename;
@@ -134,7 +134,7 @@ int __pacrunner_plugin_init(const char *pattern, const char *exclude)
filename = g_build_filename(PLUGINDIR, file, NULL);
handle = dlopen(filename, RTLD_NOW);
- if (handle == NULL) {
+ if (!handle) {
pacrunner_error("Can't load plugin %s: %s",
filename, dlerror());
g_free(filename);
@@ -144,7 +144,7 @@ int __pacrunner_plugin_init(const char *pattern, const char *exclude)
g_free(filename);
desc = dlsym(handle, "pacrunner_plugin_desc");
- if (desc == NULL) {
+ if (!desc) {
pacrunner_error("Can't load plugin description: %s",
dlerror());
dlclose(handle);
@@ -180,7 +180,7 @@ void __pacrunner_plugin_cleanup(void)
if (plugin->desc->exit)
plugin->desc->exit();
- if (plugin->handle != NULL)
+ if (plugin->handle)
dlclose(plugin->handle);
g_free(plugin);
diff --git a/src/proxy.c b/src/proxy.c
index 28521ea..8bb03af 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -52,7 +52,7 @@ struct pacrunner_proxy *pacrunner_proxy_create(const char *interface)
DBG("interface %s", interface);
proxy = g_try_new0(struct pacrunner_proxy, 1);
- if (proxy == NULL)
+ if (!proxy)
return NULL;
proxy->refcount = 1;
@@ -69,7 +69,7 @@ struct pacrunner_proxy *pacrunner_proxy_ref(struct pacrunner_proxy *proxy)
{
DBG("proxy %p", proxy);
- if (proxy == NULL)
+ if (!proxy)
return NULL;
g_atomic_int_inc(&proxy->refcount);
@@ -98,7 +98,7 @@ void pacrunner_proxy_unref(struct pacrunner_proxy *proxy)
{
DBG("proxy %p", proxy);
- if (proxy == NULL)
+ if (!proxy)
return;
if (!g_atomic_int_dec_and_test(&proxy->refcount))
@@ -114,7 +114,7 @@ const char *pacrunner_proxy_get_interface(struct pacrunner_proxy *proxy)
{
DBG("proxy %p", proxy);
- if (proxy == NULL)
+ if (!proxy)
return NULL;
return proxy->interface;
@@ -124,7 +124,7 @@ const char *pacrunner_proxy_get_script(struct pacrunner_proxy *proxy)
{
DBG("proxy %p", proxy);
- if (proxy == NULL)
+ if (!proxy)
return NULL;
return proxy->script;
@@ -135,7 +135,7 @@ static int set_method(struct pacrunner_proxy *proxy,
{
DBG("proxy %p method %d", proxy, method);
- if (proxy == NULL)
+ if (!proxy)
return -EINVAL;
if (proxy->method == method)
@@ -152,7 +152,7 @@ int pacrunner_proxy_set_direct(struct pacrunner_proxy *proxy)
{
DBG("proxy %p", proxy);
- if (proxy == NULL)
+ if (!proxy)
return -EINVAL;
pthread_mutex_lock(&proxy_mutex);
@@ -172,10 +172,10 @@ int pacrunner_proxy_set_manual(struct pacrunner_proxy *proxy,
DBG("proxy %p servers %p excludes %p", proxy, servers, excludes);
- if (proxy == NULL)
+ if (!proxy)
return -EINVAL;
- if (servers == NULL)
+ if (!servers)
return -EINVAL;
err = set_method(proxy, PACRUNNER_PROXY_METHOD_MANUAL);
@@ -183,7 +183,7 @@ int pacrunner_proxy_set_manual(struct pacrunner_proxy *proxy,
return err;
proxy->servers = __pacrunner_manual_parse_servers(servers);
- if (proxy->servers == NULL)
+ if (!proxy->servers)
return -EINVAL;
proxy->excludes = __pacrunner_manual_parse_excludes(excludes);
@@ -199,7 +199,7 @@ static void download_callback(char *content, void *user_data)
DBG("url %s content %p", proxy->url, content);
- if (content == NULL) {
+ if (!content) {
pacrunner_error("Failed to retrieve PAC script");
goto done;
}
@@ -224,7 +224,7 @@ int pacrunner_proxy_set_auto(struct pacrunner_proxy *proxy,
DBG("proxy %p url %s script %p", proxy, url, script);
- if (proxy == NULL)
+ if (!proxy)
return -EINVAL;
err = set_method(proxy, PACRUNNER_PROXY_METHOD_AUTO);
@@ -234,7 +234,7 @@ int pacrunner_proxy_set_auto(struct pacrunner_proxy *proxy,
g_free(proxy->url);
proxy->url = g_strdup(url);
- if (proxy->url == NULL) {
+ if (!proxy->url) {
g_free(proxy->script);
proxy->script = g_strdup(script);
} else {
@@ -242,7 +242,7 @@ int pacrunner_proxy_set_auto(struct pacrunner_proxy *proxy,
proxy->script = NULL;
}
- if (proxy->script != NULL) {
+ if (proxy->script) {
pacrunner_proxy_enable(proxy);
return 0;
}
@@ -276,15 +276,15 @@ int pacrunner_proxy_enable(struct pacrunner_proxy *proxy)
DBG("proxy %p", proxy);
- if (proxy == NULL)
+ if (!proxy)
return -EINVAL;
list = g_list_find(proxy_list, proxy);
- if (list != NULL)
+ if (list)
return -EEXIST;
proxy = pacrunner_proxy_ref(proxy);
- if (proxy == NULL)
+ if (!proxy)
return -EIO;
__pacrunner_js_set_proxy(proxy);
@@ -306,11 +306,11 @@ int pacrunner_proxy_disable(struct pacrunner_proxy *proxy)
DBG("proxy %p", proxy);
- if (proxy == NULL)
+ if (!proxy)
return -EINVAL;
list = g_list_find(proxy_list, proxy);
- if (list == NULL)
+ if (!list)
return -ENXIO;
pthread_mutex_lock(&proxy_mutex);
@@ -335,7 +335,7 @@ char *pacrunner_proxy_lookup(const char *url, const char *host)
while (proxy_updating)
pthread_cond_wait(&proxy_cond, &proxy_mutex);
- if (proxy_list == NULL) {
+ if (!proxy_list) {
pthread_mutex_unlock(&proxy_mutex);
return NULL;
}
@@ -353,7 +353,7 @@ char *pacrunner_proxy_lookup(const char *url, const char *host)
pthread_mutex_unlock(&proxy_mutex);
- if (selected_proxy == NULL)
+ if (!selected_proxy)
return NULL;
switch (selected_proxy->method) {
@@ -407,7 +407,7 @@ void __pacrunner_proxy_cleanup(void)
DBG("proxy %p", proxy);
- if (proxy != NULL)
+ if (proxy)
pacrunner_proxy_unref(proxy);
}