]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
daemon: fix usage of calloc
authorVincent Bernat <vincent@bernat.ch>
Tue, 15 Oct 2024 19:05:14 +0000 (21:05 +0200)
committerVincent Bernat <vincent@bernat.ch>
Tue, 15 Oct 2024 19:06:10 +0000 (21:06 +0200)
First argument is the number of elements to allocate.

src/daemon/interfaces-linux.c
src/daemon/netlink.c

index 2ee2823f05caddf03d9f0e7ca57c67a822b66721..1bf6003d5dfb12f20198e8ff1a75c77ba96916b5 100644 (file)
@@ -256,7 +256,7 @@ iflinux_get_permanent_mac_ethtool(struct lldpd *cfg,
        int ret = -1;
        struct ifreq ifr = {};
        struct ethtool_perm_addr *epaddr =
-           calloc(sizeof(struct ethtool_perm_addr) + ETHER_ADDR_LEN, 1);
+           calloc(1, sizeof(struct ethtool_perm_addr) + ETHER_ADDR_LEN);
        if (epaddr == NULL) goto end;
 
        strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name));
@@ -390,7 +390,7 @@ iflinux_get_permanent_mac(struct lldpd *cfg, struct interfaces_device_list *inte
 #ifdef ENABLE_DOT3
 #  define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 (SCHAR_MAX)
 #  define ETHTOOL_DECLARE_LINK_MODE_MASK(name) \
-    uint32_t name[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32]
+         uint32_t name[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32]
 
 struct ethtool_link_usettings {
        struct ethtool_link_settings base;
index 36c1cfd4908d39e37131fddcb29fe5c95dc7010f..f8b39f9e69ab7fe76fe0715c6e9be68c281980d0 100644 (file)
@@ -352,7 +352,7 @@ netlink_parse_link(struct nlmsghdr *msg, struct interfaces_device *iff)
        iff->upper_idx = -1;
 
        for (attribute = IFLA_RTA(ifi); RTA_OK(attribute, len);
-            attribute = RTA_NEXT(attribute, len)) {
+           attribute = RTA_NEXT(attribute, len)) {
                switch (attribute->rta_type) {
                case IFLA_IFNAME:
                        /* Interface name */
@@ -470,7 +470,7 @@ netlink_parse_address(struct nlmsghdr *msg, struct interfaces_address *ifa)
        }
 
        for (attribute = IFA_RTA(ifi); RTA_OK(attribute, len);
-            attribute = RTA_NEXT(attribute, len)) {
+           attribute = RTA_NEXT(attribute, len)) {
                switch (attribute->rta_type) {
                case IFA_ADDRESS:
                        /* Address */
@@ -642,7 +642,7 @@ netlink_recv(struct lldpd *cfg, int s, struct interfaces_device_list *ifs,
                }
 
                for (msg = (struct nlmsghdr *)(void *)(iov.iov_base);
-                    NLMSG_OK(msg, len); msg = NLMSG_NEXT(msg, len)) {
+                   NLMSG_OK(msg, len); msg = NLMSG_NEXT(msg, len)) {
                        if (!(msg->nlmsg_flags & NLM_F_MULTI)) end = 1;
                        switch (msg->nlmsg_type) {
                        case NLMSG_DONE:
@@ -890,7 +890,7 @@ netlink_initialize(struct lldpd *cfg)
        if (cfg->g_netlink) return 0;
 
        log_debug("netlink", "initialize netlink subsystem");
-       if ((cfg->g_netlink = calloc(sizeof(struct lldpd_netlink), 1)) == NULL) {
+       if ((cfg->g_netlink = calloc(1, sizeof(struct lldpd_netlink))) == NULL) {
                log_warn("netlink", "unable to allocate memory for netlink subsystem");
                goto end;
        }