diff src/lib/net.c @ 21389:59437f8764c6

global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro. Used the following script: C_FILES=`git ls-files *.c` H_FILES=`git ls-files *.h` for F in "$C_FILES $H_FILES"; do echo "$F" perl -p -i -e 's/safe_memset\(&\(?([^,]*)\)?,\s*0,\s*sizeof\(\g1\)\)/i_zero_safe(&$1)/g' $F perl -p -i -e 's/safe_memset\(([^,]*),\s*0,\s*sizeof\(\*\g1\)\)/i_zero_safe($1)/g' $F perl -p -i -e 's/memset\(&\(?([^,]*)\)?,\s*0,\s*sizeof\(\g1\)\)/i_zero(&$1)/g' $F perl -p -i -e 's/memset\(([^,]*),\s*0,\s*sizeof\(\*\g1\)\)/i_zero($1)/g' $F done
author Stephan Bosch <stephan.bosch@dovecot.fi>
date Wed, 11 Jan 2017 01:57:46 +0100
parents 5ab8dc1a4a6f
children 22c5f005625a
line wrap: on
line diff
--- a/src/lib/net.c	Tue Jan 10 19:23:30 2017 +0200
+++ b/src/lib/net.c	Wed Jan 11 01:57:46 2017 +0100
@@ -127,7 +127,7 @@
 {
 	/* IP structs may be sent across processes. Clear the whole struct
 	   first to make sure it won't leak any data across processes. */
-	memset(ip, 0, sizeof(*ip));
+	i_zero(ip);
 
 	ip->family = so->sin.sin_family;
 
@@ -139,7 +139,7 @@
 	if (ip->family == AF_INET)
 		memcpy(&ip->u.ip4, &so->sin.sin_addr, sizeof(ip->u.ip4));
 	else
-		memset(&ip->u, 0, sizeof(ip->u));
+		i_zero(&ip->u);
 }
 
 static inline void sin_set_port(union sockaddr_union *so, in_port_t port)
@@ -176,7 +176,7 @@
 	}
 
 	/* create the socket */
-	memset(&so, 0, sizeof(so));
+	i_zero(&so);
         so.sin.sin_family = ip->family;
 	fd = socket(ip->family, sock_type, 0);
 
@@ -267,7 +267,7 @@
 	int fd;
 
 	/* create the socket */
-	memset(&so, 0, sizeof(so));
+	i_zero(&so);
         so.sin.sin_family = ip->family;
 	fd = socket(ip->family, SOCK_STREAM, 0);
 	if (fd == -1) {
@@ -289,7 +289,7 @@
 	union sockaddr_union_unix sa;
 	int fd, ret;
 
-	memset(&sa, 0, sizeof(sa));
+	i_zero(&sa);
 	sa.un.sun_family = AF_UNIX;
 	if (i_strocpy(sa.un.sun_path, path, sizeof(sa.un.sun_path)) < 0) {
 		/* too long path */
@@ -437,7 +437,7 @@
 	int ret, fd, opt = 1;
 	socklen_t len;
 
-	memset(&so, 0, sizeof(so));
+	i_zero(&so);
 	sin_set_port(&so, *port);
 	sin_set_ip(&so, my_ip);
 
@@ -514,7 +514,7 @@
 	} sa;
 	int fd;
 
-	memset(&sa, 0, sizeof(sa));
+	i_zero(&sa);
 	sa.un.sun_family = AF_UNIX;
 	if (i_strocpy(sa.un.sun_path, path, sizeof(sa.un.sun_path)) < 0) {
 		/* too long path */
@@ -601,7 +601,7 @@
 	}
 	if (so.sin.sin_family == AF_UNIX) {
 		if (addr_r != NULL)
-			memset(addr_r, 0, sizeof(*addr_r));
+			i_zero(addr_r);
 		if (port_r != NULL) *port_r = 0;
 	} else {
 		if (addr_r != NULL) sin_get_ip(&so, addr_r);
@@ -735,7 +735,7 @@
 	char hbuf[NI_MAXHOST];
 	int ret;
 
-	memset(&so, 0, sizeof(so));
+	i_zero(&so);
 	sin_set_ip(&so, ip);
 	ret = getnameinfo(&so.sa, addrlen, hbuf, sizeof(hbuf), NULL, 0,
 			  NI_NAMEREQD);
@@ -758,7 +758,7 @@
 		return -1;
 	if (so.sin.sin_family == AF_UNIX) {
 		if (addr != NULL)
-			memset(addr, 0, sizeof(*addr));
+			i_zero(addr);
 		if (port != NULL) *port = 0;
 	} else {
 		if (addr != NULL) sin_get_ip(&so, addr);
@@ -779,7 +779,7 @@
 		return -1;
 	if (so.sin.sin_family == AF_UNIX) {
 		if (addr != NULL)
-			memset(addr, 0, sizeof(*addr));
+			i_zero(addr);
 		if (port != NULL) *port = 0;
 	} else {
 		if (addr != NULL) sin_get_ip(&so, addr);