]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Don't malloc pointer size when we mean data size
authorRoy Marples <roy@marples.name>
Thu, 11 Oct 2007 20:30:24 +0000 (20:30 +0000)
committerRoy Marples <roy@marples.name>
Thu, 11 Oct 2007 20:30:24 +0000 (20:30 +0000)
configure.c
dhcpcd.c
duid.c
info.c
interface.c
logger.c
socket.c

index 66ff70afc5290da366b4e05e7d5002d892ecf9bc..0847b2eab0966e9b9ba38ce7cda07e97adb2ba1a 100644 (file)
@@ -192,7 +192,7 @@ static int _make_ntp (const char *file, const char *ifname, const dhcp_t *dhcp)
                        return -1;
                }
        } else {
-               buffer = xmalloc (sizeof (char *) * BUFFERSIZE);
+               buffer = xmalloc (sizeof (char) * BUFFERSIZE);
                memset (buffer, 0, BUFFERSIZE);
                while (fgets (buffer, BUFFERSIZE, f)) {
                        a = buffer;
@@ -305,7 +305,7 @@ static int make_nis (const char *ifname, const dhcp_t *dhcp)
                return -1;
        }
 
-       prefix = xmalloc (sizeof (char *) * PREFIXSIZE);
+       prefix = xmalloc (sizeof (char) * PREFIXSIZE);
        *prefix = '\0';
        fprintf (f, "# Generated by dhcpcd for interface %s\n", ifname);
 
@@ -531,9 +531,9 @@ int configure (const options_t *options, interface_t *iface,
                make_nis(iface->name, dhcp);
 #endif
 
-       curhostname = xmalloc (sizeof (char *) * MAXHOSTNAMELEN);
+       curhostname = xmalloc (sizeof (char) * MAXHOSTNAMELEN);
        *curhostname = '\0';
-       newhostname = xmalloc (sizeof (char *) * MAXHOSTNAMELEN);
+       newhostname = xmalloc (sizeof (char) * MAXHOSTNAMELEN);
        *newhostname = '\0';
 
        /* Now we have made a resolv.conf we can obtain a hostname if we need it */
@@ -547,7 +547,7 @@ int configure (const options_t *options, interface_t *iface,
                struct addrinfo hints, *res;
                int result;
 
-               addr = xmalloc (sizeof (char *) * NI_MAXHOST);
+               addr = xmalloc (sizeof (char) * NI_MAXHOST);
                salen = sizeof (struct sockaddr);
                memset (&su.sa, 0, salen);
                su.sin.sin_family = AF_INET;
index 25519da64927a8fedebdf6920cd8eb1cdd3f3799..55641b2af5757e0b137c0d075e25f4d077c177ce 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -447,7 +447,7 @@ int main(int argc, char **argv)
                exit (EXIT_FAILURE);
        }
 
-       prefix = xmalloc (sizeof (char *) * IF_NAMESIZE + 3);
+       prefix = xmalloc (sizeof (char) * (IF_NAMESIZE + 3));
        snprintf (prefix, IF_NAMESIZE, "%s: ", options->interface);
        setlogprefix (prefix);
        snprintf (options->pidfile, sizeof (options->pidfile), PIDFILE,
diff --git a/duid.c b/duid.c
index 160b131c5ad1b5b052157e97d5e90b426e98b2e6..2645677f2048ab2968d8caa744caf0efd824ee2d 100644 (file)
--- a/duid.c
+++ b/duid.c
@@ -59,7 +59,7 @@ void get_duid (interface_t *iface)
        if ((fp = fopen (DUIDFILE, "r"))) {
                char *fduid;
                char *fdp;
-               fduid = fdp = xmalloc ((sizeof (char *) * DUID_LEN * 2) + 1);
+               fduid = fdp = xmalloc ((sizeof (char) * DUID_LEN * 2) + 1);
                if (fscanf (fp, "%260s", fduid) == 1) {
                        char c[3];
                        c[2] = '\0';
diff --git a/info.c b/info.c
index b32771787ccb4ec2ee7b9038ac1695d2055c3659..2a7920a0215784fe8c8d2a214dee32c8d620d5c7 100644 (file)
--- a/info.c
+++ b/info.c
@@ -340,7 +340,7 @@ bool read_info (const interface_t *iface, dhcp_t *dhcp)
 
        dhcp->frominfo = true;
 
-       buffer = xmalloc (sizeof (char *) * BUFFERSIZE);
+       buffer = xmalloc (sizeof (char) * BUFFERSIZE);
        memset (buffer, 0, BUFFERSIZE);
        while ((fgets (buffer, BUFFERSIZE, fp))) {
                var = buffer;
index 9964ad360eaead8715d1c86acdbdbb4dc60a87ca..70dba71e56191fca792d55251b866c09341b1875 100644 (file)
@@ -271,7 +271,6 @@ interface_t *read_interface (const char *ifname, int metric)
        if (! ifname)
                return NULL;
 
-       memset (hwaddr, sizeof (hwaddr), 0);
        memset (&ifr, 0, sizeof (struct ifreq));
        strlcpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
 
@@ -304,7 +303,7 @@ interface_t *read_interface (const char *ifname, int metric)
                        goto exit;
        }
 
-       hwaddr = xmalloc (sizeof (unsigned char *) * HWADDR_LEN);
+       hwaddr = xmalloc (sizeof (unsigned char) * HWADDR_LEN);
        memcpy (hwaddr, ifr.ifr_hwaddr.sa_data, hwlen);
        family = ifr.ifr_hwaddr.sa_family;
 #else
@@ -315,7 +314,7 @@ interface_t *read_interface (const char *ifname, int metric)
                goto exit;
        }
 
-       hwaddr = xmalloc (sizeof (unsigned char *) * HWADDR_LEN);
+       hwaddr = xmalloc (sizeof (unsigned char) * HWADDR_LEN);
        if (_do_interface (ifname, hwaddr, &hwlen, NULL, false, false) != 1) {
                logger (LOG_ERR, "could not find interface %s", ifname);
                goto exit;
@@ -601,7 +600,7 @@ static int do_route (const char *ifname,
                if (netmask.s_addr == INADDR_BROADCAST) 
                        rtm.hdr.rtm_flags |= RTF_HOST;
 
-               hwaddr = xmalloc (sizeof (unsigned char *) * HWADDR_LEN);
+               hwaddr = xmalloc (sizeof (unsigned char) * HWADDR_LEN);
                _do_interface (ifname, hwaddr, &hwlen, NULL, false, false);
                memset (&su, 0, sizeof (struct sockaddr_storage));
                su.sdl.sdl_len = sizeof (struct sockaddr_dl);
@@ -697,7 +696,7 @@ static int send_netlink(struct nlmsghdr *hdr)
                return -1;
        }
 
-       buffer = xmalloc (sizeof (char *) * BUFFERLEN);
+       buffer = xmalloc (sizeof (char) * BUFFERLEN);
        memset (buffer, 0, BUFFERLEN);
        iov.iov_base = buffer;
 
index f812dd36b818d3119a544636941a90d911ae56f3..5fc184f68d88cc5f80487f7f0dcd132587fea257 100644 (file)
--- a/logger.c
+++ b/logger.c
@@ -100,7 +100,7 @@ void logger(int level, const char *fmt, ...)
        if (level < LOG_DEBUG || level <= loglevel) {
                int len = strlen (logprefix);
                int fmt2len = strlen (fmt) + len + 1;
-               char *fmt2 = malloc (sizeof (char *) * fmt2len);
+               char *fmt2 = malloc (sizeof (char) * fmt2len);
                char *pf = fmt2;
                if (fmt2) {
                        memcpy (pf, logprefix, len);
index bb93992996c1be7c3fc307ed178fc699d9ca457b..639e16507686689aedc5a38028078709c1a94829 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -240,7 +240,7 @@ int open_socket (interface_t *iface, bool arp)
        int buf = 0;
        struct bpf_program p;
 
-       device = xmalloc (sizeof (char *) * PATH_MAX);
+       device = xmalloc (sizeof (char) * PATH_MAX);
        do {
                snprintf (device, PATH_MAX, "/dev/bpf%d",  n++);
                fd = open (device, O_RDWR);