Skip to content

Commit

Permalink
tools: Do not compare expression against NULL
Browse files Browse the repository at this point in the history
This patch generate via coccinelle with:

@ disable is_null,isnt_null1 @
expression E;
@@

(
- E == NULL
+ !E
|
- E != NULL
+ E
)
  • Loading branch information
Daniel Wagner authored and pfl committed Aug 7, 2013
1 parent bd99aaa commit c879c4f
Show file tree
Hide file tree
Showing 18 changed files with 255 additions and 255 deletions.
2 changes: 1 addition & 1 deletion tools/dbus-test.c
Expand Up @@ -59,7 +59,7 @@ int main(int argc, char *argv[])
dbus_error_init(&err);

conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
if (conn == NULL) {
if (!conn) {
if (dbus_error_is_set(&err)) {
fprintf(stderr, "%s\n", err.message);
dbus_error_free(&err);
Expand Down
2 changes: 1 addition & 1 deletion tools/dhcp-server-test.c
Expand Up @@ -89,7 +89,7 @@ int main(int argc, char *argv[])
printf("Create DHCP server for interface %d\n", index);

dhcp_server = g_dhcp_server_new(G_DHCP_IPV4, index, &error);
if (dhcp_server == NULL) {
if (!dhcp_server) {
handle_error(error);
exit(0);
}
Expand Down
4 changes: 2 additions & 2 deletions tools/dhcp-test.c
Expand Up @@ -102,7 +102,7 @@ static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data)

address = g_dhcp_client_get_address(dhcp_client);
printf("address %s\n", address);
if (address == NULL)
if (!address)
return;

option_value = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET);
Expand Down Expand Up @@ -143,7 +143,7 @@ int main(int argc, char *argv[])
printf("Create DHCP client for interface %d\n", index);

dhcp_client = g_dhcp_client_new(G_DHCP_IPV4, index, &error);
if (dhcp_client == NULL) {
if (!dhcp_client) {
handle_error(error);
exit(0);
}
Expand Down
4 changes: 2 additions & 2 deletions tools/iptables-test.c
Expand Up @@ -92,11 +92,11 @@ int main(int argc, char *argv[])
}

out:
if (table == NULL)
if (!table)
table = "filter";

for (i = optind - 1; i < argc; i++) {
if (rule != NULL) {
if (rule) {
tmp = rule;
rule = g_strdup_printf("%s %s", rule, argv[i]);
g_free(tmp);
Expand Down
12 changes: 6 additions & 6 deletions tools/iptables-unit.c
Expand Up @@ -40,14 +40,14 @@ static bool assert_rule(const char *table_name, const char *rule)
lines = g_strsplit(output, "\n", 0);
g_free(output);

for (i = 0; lines[i] != NULL; i++) {
for (i = 0; lines[i]; i++) {
DBG("lines[%02d]: %s\n", i, lines[i]);
if (g_strcmp0(lines[i], rule) == 0)
break;
}
g_strfreev(lines);

if (lines[i] == NULL)
if (!lines[i])
return false;

return true;
Expand Down Expand Up @@ -408,7 +408,7 @@ static void test_firewall_basic0(void)
int err;

ctx = __connman_firewall_create();
g_assert(ctx != NULL);
g_assert(ctx);

err = __connman_firewall_add_rule(ctx, "filter", "INPUT",
"-m mark --mark 999 -j LOG");
Expand Down Expand Up @@ -437,7 +437,7 @@ static void test_firewall_basic1(void)
int err;

ctx = __connman_firewall_create();
g_assert(ctx != NULL);
g_assert(ctx);

err = __connman_firewall_add_rule(ctx, "filter", "INPUT",
"-m mark --mark 999 -j LOG");
Expand All @@ -462,7 +462,7 @@ static void test_firewall_basic2(void)
int err;

ctx = __connman_firewall_create();
g_assert(ctx != NULL);
g_assert(ctx);

err = __connman_firewall_add_rule(ctx, "mangle", "INPUT",
"-j CONNMARK --restore-mark");
Expand Down Expand Up @@ -513,7 +513,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
Expand Down
22 changes: 11 additions & 11 deletions tools/manager-api.c
Expand Up @@ -38,7 +38,7 @@ static DBusMessage *set_property(DBusConnection *connection,
CONNMAN_MANAGER_PATH,
CONNMAN_MANAGER_INTERFACE,
"SetProperty");
if (message == NULL)
if (!message)
return NULL;

dbus_message_iter_init_append(message, &iter);
Expand All @@ -48,7 +48,7 @@ static DBusMessage *set_property(DBusConnection *connection,

reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (!reply) {
if (dbus_error_is_set(&error)) {
LOG("%s", error.message);
dbus_error_free(&error);
Expand All @@ -73,14 +73,14 @@ DBusMessage *manager_get_services(DBusConnection *connection)
CONNMAN_MANAGER_PATH,
CONNMAN_MANAGER_INTERFACE,
"GetServices");
if (message == NULL)
if (!message)
return NULL;

dbus_error_init(&error);

reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (!reply) {
if (dbus_error_is_set(&error)) {
LOG("%s", error.message);
dbus_error_free(&error);
Expand All @@ -105,14 +105,14 @@ DBusMessage *manager_get_properties(DBusConnection *connection)
CONNMAN_MANAGER_PATH,
CONNMAN_MANAGER_INTERFACE,
"GetProperties");
if (message == NULL)
if (!message)
return NULL;

dbus_error_init(&error);

reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (!reply) {
if (dbus_error_is_set(&error)) {
LOG("%s", error.message);
dbus_error_free(&error);
Expand Down Expand Up @@ -140,7 +140,7 @@ DBusMessage *manager_create_session(DBusConnection *connection,
CONNMAN_MANAGER_PATH,
CONNMAN_MANAGER_INTERFACE,
"CreateSession");
if (message == NULL)
if (!message)
return NULL;

dbus_error_init(&error);
Expand All @@ -158,7 +158,7 @@ DBusMessage *manager_create_session(DBusConnection *connection,

reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (!reply) {
if (dbus_error_is_set(&error)) {
LOG("%s", error.message);
dbus_error_free(&error);
Expand All @@ -185,7 +185,7 @@ DBusMessage *manager_destroy_session(DBusConnection *connection,
CONNMAN_MANAGER_PATH,
CONNMAN_MANAGER_INTERFACE,
"DestroySession");
if (message == NULL)
if (!message)
return NULL;

dbus_error_init(&error);
Expand All @@ -197,7 +197,7 @@ DBusMessage *manager_destroy_session(DBusConnection *connection,

reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (!reply) {
if (dbus_error_is_set(&error)) {
LOG("%s", error.message);
dbus_error_free(&error);
Expand Down Expand Up @@ -246,7 +246,7 @@ int manager_parse_properties(DBusMessage *msg,
const char *val;
dbus_message_iter_get_basic(&value, &val);

if (manager->state != NULL)
if (manager->state)
g_free(manager->state);

LOG("State %s", val);
Expand Down
4 changes: 2 additions & 2 deletions tools/netlink-test.c
Expand Up @@ -287,7 +287,7 @@ static void nfacct_get_callback(unsigned int error, const char *name,

g_assert_cmpuint(error, ==, 0);

if (name == NULL) {
if (!name) {
/* end of dump */
return;
}
Expand All @@ -311,7 +311,7 @@ static void nfacct_dump_callback(unsigned int error, const char *name,

g_assert_cmpuint(error, ==, 0);

if (name == NULL) {
if (!name) {
/* end of dump */
return;
}
Expand Down
6 changes: 3 additions & 3 deletions tools/resolv-test.c
Expand Up @@ -80,7 +80,7 @@ static void resolv_result(GResolvResultStatus status,

g_print("status: %s\n", status2str(status));

if (results != NULL) {
if (results) {
for (i = 0; results[i]; i++)
g_print("result: %s\n", results[i]);
}
Expand Down Expand Up @@ -108,7 +108,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
Expand All @@ -124,7 +124,7 @@ int main(int argc, char *argv[])
}

resolv = g_resolv_new(index);
if (resolv == NULL) {
if (!resolv) {
printf("failed to create resolver\n");
return 1;
}
Expand Down
24 changes: 12 additions & 12 deletions tools/session-api.c
Expand Up @@ -73,7 +73,7 @@ static GSList *session_parse_allowed_bearers(DBusMessageIter *iter)
dbus_message_iter_get_basic(&array, &bearer);

info = g_try_new0(struct test_bearer_info, 1);
if (info == NULL) {
if (!info) {
g_slist_foreach(list, bearer_info_cleanup, NULL);
g_slist_free(list);

Expand All @@ -97,7 +97,7 @@ static DBusMessage *notify_release(DBusConnection *conn,

LOG("session %p", session);

if (session->notify != NULL)
if (session->notify)
session->notify(session);

return NULL;
Expand Down Expand Up @@ -158,7 +158,7 @@ static DBusMessage *notify_update(DBusConnection *conn,
const char *val;
dbus_message_iter_get_basic(&value, &val);

if (info->bearer != NULL)
if (info->bearer)
g_free(info->bearer);

info->bearer = g_strdup(val);
Expand All @@ -167,7 +167,7 @@ static DBusMessage *notify_update(DBusConnection *conn,
const char *val;
dbus_message_iter_get_basic(&value, &val);

if (info->name != NULL)
if (info->name)
g_free(info->name);

info->name = g_strdup(val);
Expand All @@ -176,7 +176,7 @@ static DBusMessage *notify_update(DBusConnection *conn,
const char *val;
dbus_message_iter_get_basic(&value, &val);

if (info->interface != NULL)
if (info->interface)
g_free(info->interface);

info->interface = g_strdup(val);
Expand All @@ -199,7 +199,7 @@ static DBusMessage *notify_update(DBusConnection *conn,
dbus_message_iter_next(&array);
}

if (session->notify != NULL)
if (session->notify)
session->notify(session);

return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
Expand Down Expand Up @@ -239,7 +239,7 @@ static void append_allowed_bearers(DBusMessageIter *iter, void *user_data)
GSList *list;

for (list = info->allowed_bearers;
list != NULL; list = list->next) {
list; list = list->next) {
struct test_bearer_info *bearer_info = list->data;

dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
Expand All @@ -250,7 +250,7 @@ static void append_allowed_bearers(DBusMessageIter *iter, void *user_data)
void session_append_settings(DBusMessageIter *dict,
struct test_session_info *info)
{
if (info->allowed_bearers == NULL)
if (!info->allowed_bearers)
return;

connman_dbus_dict_append_array(dict, "AllowedBearers",
Expand All @@ -269,14 +269,14 @@ DBusMessage *session_connect(DBusConnection *connection,
session->session_path,
CONNMAN_SESSION_INTERFACE,
"Connect");
if (message == NULL)
if (!message)
return NULL;

dbus_error_init(&error);

reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (!reply) {
if (dbus_error_is_set(&error)) {
LOG("%s", error.message);
dbus_error_free(&error);
Expand All @@ -302,14 +302,14 @@ DBusMessage *session_disconnect(DBusConnection *connection,
session->session_path,
CONNMAN_SESSION_INTERFACE,
"Disconnect");
if (message == NULL)
if (!message)
return NULL;

dbus_error_init(&error);

reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (!reply) {
if (dbus_error_is_set(&error)) {
LOG("%s", error.message);
dbus_error_free(&error);
Expand Down

0 comments on commit c879c4f

Please sign in to comment.