Module Name:    src
Committed By:   christos
Date:           Thu Dec  9 00:11:00 UTC 2010

Modified Files:
        src/usr.sbin/ldpd: fsm.c label.c ldp_peer.c mpls_interface.c
            mpls_routes.c notifications.c socketops.c tlv_stack.c

Log Message:
- no cast for malloc
- malloc + memset = calloc
- sizeof(type) -> sizeof(*var)
- small indents


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/fsm.c src/usr.sbin/ldpd/label.c \
    src/usr.sbin/ldpd/ldp_peer.c src/usr.sbin/ldpd/mpls_interface.c \
    src/usr.sbin/ldpd/mpls_routes.c src/usr.sbin/ldpd/notifications.c \
    src/usr.sbin/ldpd/socketops.c src/usr.sbin/ldpd/tlv_stack.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/ldpd/fsm.c
diff -u src/usr.sbin/ldpd/fsm.c:1.1 src/usr.sbin/ldpd/fsm.c:1.2
--- src/usr.sbin/ldpd/fsm.c:1.1	Wed Dec  8 02:20:14 2010
+++ src/usr.sbin/ldpd/fsm.c	Wed Dec  8 19:10:59 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: fsm.c,v 1.1 2010/12/08 07:20:14 kefren Exp $ */
+/* $NetBSD: fsm.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
 		if (hi->ldp_id.s_addr == pduid->ldp_id.s_addr)
 			break;
 	if (hi == NULL) {
-		hi = (struct hello_info *)malloc(sizeof(struct hello_info));
+		hi = malloc(sizeof(*hi));
 		if (!hi) {
 			fatalp("Cannot alloc a hello info");
 			return;
@@ -145,13 +145,12 @@
 			if (sa->sin_addr.s_addr << 24 >> 24 != 127)
 				adrcount++;
 		}
-	t = (struct address_list_tlv *) malloc(sizeof(struct address_list_tlv)
-				 + (adrcount - 1) * sizeof(struct in_addr));
+	t = malloc(sizeof(*t) + (adrcount - 1) * sizeof(struct in_addr));
 
 	if (!t) {
 		fatalp("build_address_list_tlv: malloc problem\n");
 		return NULL;
-		}
+	}
 
 	t->type = htons(LDP_ADDRESS);
 	t->length = htons(sizeof(struct address_list_tlv) - TLV_TYPE_LENGTH
Index: src/usr.sbin/ldpd/label.c
diff -u src/usr.sbin/ldpd/label.c:1.1 src/usr.sbin/ldpd/label.c:1.2
--- src/usr.sbin/ldpd/label.c:1.1	Wed Dec  8 02:20:14 2010
+++ src/usr.sbin/ldpd/label.c	Wed Dec  8 19:10:59 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: label.c,v 1.1 2010/12/08 07:20:14 kefren Exp $ */
+/* $NetBSD: label.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -58,13 +58,12 @@
 	struct label   *l;
 	char	spreftmp[INET_ADDRSTRLEN];
 
-	l = (struct label *) malloc(sizeof(struct label));
-	memset(l, 0, sizeof(struct label));
+	l = calloc(1, sizeof(*l));
 
 	if (!l) {
 		fatalp("label_add: malloc problem\n");
 		return NULL;
-		}
+	}
 
 	assert(so_dest);
 	assert(so_pref);
Index: src/usr.sbin/ldpd/ldp_peer.c
diff -u src/usr.sbin/ldpd/ldp_peer.c:1.1 src/usr.sbin/ldpd/ldp_peer.c:1.2
--- src/usr.sbin/ldpd/ldp_peer.c:1.1	Wed Dec  8 02:20:14 2010
+++ src/usr.sbin/ldpd/ldp_peer.c	Wed Dec  8 19:10:59 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: ldp_peer.c,v 1.1 2010/12/08 07:20:14 kefren Exp $ */
+/* $NetBSD: ldp_peer.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -87,14 +87,13 @@
 	}
 
 	/* Set the peer in CONNECTING/CONNECTED state */
-	p = (struct ldp_peer *) malloc(sizeof(struct ldp_peer));
+	p = calloc(1, sizeof(*p));
 
 	if (!p) {
 		fatalp("ldp_peer_new: malloc problem\n");
 		return NULL;
-		}
+	}
 
-	memset(p, 0, sizeof(struct ldp_peer));
 	SLIST_INSERT_HEAD(&ldp_peer_head, p, peers);
 	memcpy(&p->address, a, sizeof(struct in_addr));
 	memcpy(&p->ldp_id, ldp_id, sizeof(struct in_addr));
@@ -282,14 +281,12 @@
 	if (check_ifaddr(p, a))
 		return LDP_E_ALREADY_DONE;
 
-	lpa = (struct ldp_peer_address*)malloc(sizeof(struct ldp_peer_address));
+	lpa = calloc(1, sizeof(*lpa));
 
 	if (!lpa) {
 		fatalp("add_ifaddr: malloc problem\n");
 		return LDP_E_MEMORY;
-		}
-
-	memset(lpa, 0, sizeof(struct ldp_peer_address));
+	}
 
 	memcpy(&lpa->address, a, sizeof(struct in_addr));
 
@@ -355,8 +352,7 @@
 void 
 add_my_if_addrs(struct in_addr * a, int count)
 {
-	myaddresses = (struct in_addr *) malloc((count + 1) *
-	    (sizeof(struct in_addr)));
+	myaddresses = calloc((count + 1), sizeof(*myaddresses));
 
 	if (!myaddresses) {
 		fatalp("add_my_if_addrs: malloc problem\n");
@@ -378,7 +374,7 @@
 	if (ldp_peer_get_lm(p, a, prefix))
 		return LDP_E_ALREADY_DONE;
 
-	lma = (struct label_mapping *) malloc(sizeof(struct label_mapping));
+	lma = malloc(sizeof(*lma));
 
 	if (!lma) {
 		fatalp("ldp_peer_add_mapping: malloc problem\n");
@@ -468,7 +464,7 @@
 		debugp("Cannot match that prefix to the specified peer\n");
 		return NULL;
 	}
-	rv = (struct peer_map *) malloc(sizeof(struct peer_map));
+	rv = malloc(sizeof(*rv));
 
 	if (!rv) {
 		fatalp("ldp_test_mapping: malloc problem\n");
Index: src/usr.sbin/ldpd/mpls_interface.c
diff -u src/usr.sbin/ldpd/mpls_interface.c:1.1 src/usr.sbin/ldpd/mpls_interface.c:1.2
--- src/usr.sbin/ldpd/mpls_interface.c:1.1	Wed Dec  8 02:20:14 2010
+++ src/usr.sbin/ldpd/mpls_interface.c	Wed Dec  8 19:10:59 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: mpls_interface.c,v 1.1 2010/12/08 07:20:14 kefren Exp $ */
+/* $NetBSD: mpls_interface.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -164,7 +164,11 @@
 
 	/* Add switching route */
 	so_dest = make_mpls_union(lab->binding);
-	so_nexthop = (union sockunion *)malloc(sizeof(union sockunion));
+	so_nexthop = malloc(sizeof(*so_nexthop));
+	if (!so_nexthop) {
+		fatalp("Out of memory\n");
+		return LDP_E_MEMORY;
+	}
 	memcpy(so_nexthop, so_gate, so_gate->sa.sa_len);
 	so_tag = make_mpls_union(label);
 	if (add_route(so_dest, NULL, so_nexthop, NULL, so_tag, FREESO, RTM_ADD) != LDP_E_OK)
@@ -183,11 +187,19 @@
 		so_pref = from_cidr_to_union(len);
 
 	/* Add tag to route */
-	so_nexthop = (union sockunion *)malloc(sizeof(union sockunion));
+	so_nexthop = malloc(sizeof(*so_nexthop));
+	if (!so_nexthop) {
+		fatalp("Out of memory\n");
+		return LDP_E_MEMORY;
+	}
 	memcpy(so_nexthop, so_gate, so_gate->sa.sa_len);
 	so_tag = make_mpls_union(label);
 	if (so_oldifa != NULL) {
-		so_ifa = (union sockunion *)malloc(sizeof(union sockunion));
+		so_ifa = malloc(sizeof(*so_ifa));
+		if (!so_ifa) {
+			fatalp("Out of memory\n");
+			return LDP_E_MEMORY;
+		}
 		memcpy(so_ifa, so_oldifa, so_oldifa->sa.sa_len);
 	} else
 		so_ifa = NULL;
Index: src/usr.sbin/ldpd/mpls_routes.c
diff -u src/usr.sbin/ldpd/mpls_routes.c:1.1 src/usr.sbin/ldpd/mpls_routes.c:1.2
--- src/usr.sbin/ldpd/mpls_routes.c:1.1	Wed Dec  8 02:20:15 2010
+++ src/usr.sbin/ldpd/mpls_routes.c	Wed Dec  8 19:10:59 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: mpls_routes.c,v 1.1 2010/12/08 07:20:15 kefren Exp $ */
+/* $NetBSD: mpls_routes.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -158,14 +158,12 @@
 {
 	union sockunion *so_inet;
 
-	so_inet = (union sockunion *) malloc(sizeof(union sockunion));
+	so_inet = calloc(1, sizeof(*so_inet));
 
 	if (!so_inet) {
 		fatalp("make_inet_union: malloc problem\n");
 		return NULL;
-		}
-
-	memset(so_inet, 0, sizeof(union sockunion));
+	}
 
 	so_inet->sin.sin_len = sizeof(struct sockaddr_in);
 	so_inet->sin.sin_family = AF_INET;
@@ -180,14 +178,12 @@
 {
 	union sockunion *so_mpls;
 
-	so_mpls = (union sockunion *) malloc(sizeof(union sockunion));
+	so_mpls = calloc(1, sizeof(*so_mpls));
 
 	if (!so_mpls) {
 		fatalp("make_mpls_union: malloc problem\n");
 		return NULL;
-		}
-
-	memset(so_mpls, 0, sizeof(union sockunion));
+	}
 
 	so_mpls->smpls.smpls_len = sizeof(struct sockaddr_mpls);
 	so_mpls->smpls.smpls_family = AF_MPLS;
@@ -218,15 +214,12 @@
 	*m = (*m >> (32 - prefixlen) ) << (32 - prefixlen);
 	*m = ntohl(*m);
 
-	u = (union sockunion *) malloc(sizeof(union sockunion));
+	u = calloc(1, sizeof(*u));
 
 	if (!u) {
 		fatalp("from_cidr_to_union: malloc problem\n");
 		return NULL;
 	}
-
-	memset (u, 0, sizeof(union sockunion));
-
 	u->sin.sin_len = sizeof(struct sockaddr_in);
 	u->sin.sin_family = AF_INET;
 	u->sin.sin_addr.s_addr = *m;
@@ -848,8 +841,10 @@
 		fatalp("route-sysctl-estimate: %s", strerror(errno));
 		return LDP_E_ROUTE_ERROR;
 	}
-	if ((buf = malloc(needed)) == 0)
-		return LDP_E_ROUTE_ERROR;
+	if ((buf = malloc(needed)) == NULL) {
+		fatalp("route-sysctl-estimate: %s", strerror(errno));
+		return LDP_E_MEMORY;
+	}
 	if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
 		free(buf);
 		return LDP_E_ROUTE_ERROR;
Index: src/usr.sbin/ldpd/notifications.c
diff -u src/usr.sbin/ldpd/notifications.c:1.1 src/usr.sbin/ldpd/notifications.c:1.2
--- src/usr.sbin/ldpd/notifications.c:1.1	Wed Dec  8 02:20:15 2010
+++ src/usr.sbin/ldpd/notifications.c	Wed Dec  8 19:10:59 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: notifications.c,v 1.1 2010/12/08 07:20:15 kefren Exp $ */
+/* $NetBSD: notifications.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -44,12 +44,12 @@
 build_notification(uint32_t msg, uint32_t n)
 {
 	struct notification_tlv *t;
-	t = (struct notification_tlv *) malloc(sizeof(struct notification_tlv));
+	t = malloc(sizeof(*t));
 
 	if (!t) {
 		fatalp("build_notification: malloc problem\n");
 		return NULL;
-		}
+	}
 
 	t->type = htons(LDP_NOTIFICATION);
 	t->length = htons(sizeof(struct notification_tlv) - TLV_TYPE_LENGTH);
Index: src/usr.sbin/ldpd/socketops.c
diff -u src/usr.sbin/ldpd/socketops.c:1.1 src/usr.sbin/ldpd/socketops.c:1.2
--- src/usr.sbin/ldpd/socketops.c:1.1	Wed Dec  8 02:20:15 2010
+++ src/usr.sbin/ldpd/socketops.c	Wed Dec  8 19:10:59 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: socketops.c,v 1.1 2010/12/08 07:20:15 kefren Exp $ */
+/* $NetBSD: socketops.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -250,11 +250,10 @@
 			/* IPv4 Transport Address */			\
 			sizeof(struct transport_address_tlv))
 
-	if ((v = malloc(HELLO_MSG_SIZE)) == NULL) {
+	if ((v = calloc(1, HELLO_MSG_SIZE)) == NULL) {
 		fatalp("malloc problem in send_hello()\n");
 		return;
 	}
-	memset(v, 0, HELLO_MSG_SIZE);
 
 	spdu = (struct ldp_pdu *)((char *)v);
 	t = (struct hello_tlv *)(spdu + 1);
Index: src/usr.sbin/ldpd/tlv_stack.c
diff -u src/usr.sbin/ldpd/tlv_stack.c:1.1 src/usr.sbin/ldpd/tlv_stack.c:1.2
--- src/usr.sbin/ldpd/tlv_stack.c:1.1	Wed Dec  8 02:20:15 2010
+++ src/usr.sbin/ldpd/tlv_stack.c	Wed Dec  8 19:10:59 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: tlv_stack.c,v 1.1 2010/12/08 07:20:15 kefren Exp $ */
+/* $NetBSD: tlv_stack.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -217,7 +217,7 @@
 	 * Got it ?
 	 */
 
-	lmt = (struct label_map_tlv *) malloc(
+	lmt = malloc(
 		sizeof(struct label_map_tlv) +
 		sizeof(struct fec_tlv) +
 		sizeof(struct prefix_tlv) - sizeof(struct in_addr) +
@@ -229,7 +229,7 @@
 	if (!lmt) {
 		fatalp("send_label_tlv: malloc problem\n");
 		return;
-		}
+	}
 
 	lmt->type = htons(LDP_LABEL_MAPPING);
 	lmt->length = htons(sizeof(struct label_map_tlv) - TLV_TYPE_LENGTH
@@ -314,7 +314,7 @@
 	 * network. Yes, we don't have to announce label here
 	 */
 
-	lmt = (struct label_map_tlv *) malloc(sizeof(struct label_map_tlv)
+	lmt = malloc(sizeof(struct label_map_tlv)
 	      + sizeof(struct fec_tlv)
 	      + sizeof(struct prefix_tlv) - sizeof(struct in_addr) +
 			ldp_ceil8(prefixlen));

Reply via email to