DBus booleans seem to stamp on more space than a C99 boolean
[dhcpcd-ui] / src / libdhcpcd / main.c
index 6e4059e2dbb714e5e2a428062b585f0228a8e299..7bffcbe1548ccd8de7c5e885b2751d3c3cef87ee 100644 (file)
@@ -144,10 +144,9 @@ dhcpcd_open(char **error)
        }
        if (bus == NULL)
                return NULL;
-       con = malloc(sizeof(*con));
+       con = calloc(1, sizeof(*con));
        if (con == NULL)
                goto bad;
-       memset(con, 0, sizeof(*con));
        con->bus = bus;
        if (!dbus_connection_set_watch_functions(bus,
                dhcpcd_add_watch, dhcpcd_delete_watch, NULL, con, NULL))
@@ -398,20 +397,18 @@ dhcpcd_if_new(DHCPCD_CONNECTION *con, DBusMessageIter *array, char **order)
        DHCPCD_IF *i;
        char *s;
        uint32_t u32;
-       bool b;
-       int errors;
+       int b, errors;
 
        if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY) {
                errno = EINVAL;
                return NULL;
        }
        dbus_message_iter_recurse(array, &dict);
-       i = malloc(sizeof(*i));
+       i = calloc(1, sizeof(*i));
        if (i == NULL) {
                dhcpcd_error_set(con, 0, errno);
                return NULL;
        }
-       memset(i, 0, sizeof(*i));
        errors = con->errors;
        for (;
             dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY;
@@ -436,6 +433,8 @@ dhcpcd_if_new(DHCPCD_CONNECTION *con, DBusMessageIter *array, char **order)
                                break;
                        strlcpy(i->reason, s, sizeof(i->reason));
                } else if (strcmp(s, "Wireless") == 0) {
+                       /* b is an int as DBus booleans want more space than
+                        * a C99 boolean */
                        if (!dhcpcd_iter_get(con, &var, DBUS_TYPE_BOOLEAN, &b))
                                break;
                        i->wireless = b;
@@ -446,7 +445,7 @@ dhcpcd_if_new(DHCPCD_CONNECTION *con, DBusMessageIter *array, char **order)
                } else if (strcmp(s, "IPAddress") == 0) {
                        if (!dhcpcd_iter_get(con, &var, DBUS_TYPE_UINT32, &u32))
                                break;
-                               i->ip.s_addr = u32;
+                       i->ip.s_addr = u32;
                } else if (strcmp(s, "SubnetCIDR") == 0)
                        dbus_message_iter_get_basic(&var, &i->cidr);
                else if (order != NULL && strcmp(s, "InterfaceOrder") == 0)