[PATCH 2/3] Suppress all compilation warnings

Etienne CHAMPETIER etienne.champetier at free.fr
Mon Feb 4 21:24:17 UTC 2013


---
 libhttpd/api.c     |   12 ++++++------
 src/conf.c         |   27 ++++++---------------------
 src/ping_thread.c  |    8 ++++++--
 src/util.c         |    3 +--
 src/wdctl_thread.c |   21 ++++++++++++++-------
 5 files changed, 33 insertions(+), 38 deletions(-)

diff --git a/libhttpd/api.c b/libhttpd/api.c
index 0a750fa..4a86162 100644
--- a/libhttpd/api.c
+++ b/libhttpd/api.c
@@ -308,12 +308,12 @@ request *httpdGetConnection(server, timeout)
 	httpd	*server;
 	struct	timeval *timeout;
 {
-	int	result;
-	fd_set	fds;
-	struct  sockaddr_in     addr;
-	size_t  addrLen;
-	char	*ipaddr;
-	request	*r;
+	int		result;
+	fd_set		fds;
+	struct  	sockaddr_in     addr;
+	socklen_t	addrLen;
+	char		*ipaddr;
+	request		*r;
 
 	FD_ZERO(&fds);
 	FD_SET(server->serverSock, &fds);
diff --git a/src/conf.c b/src/conf.c
index a16d7da..8394cfc 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -244,13 +244,11 @@ parse_auth_server(FILE *file, const char *filename, int *linenum)
 	ssl_port = DEFAULT_AUTHSERVSSLPORT;
 	ssl_available = DEFAULT_AUTHSERVSSLAVAILABLE;
 	
-	/* Read first line */	
-	memset(line, 0, MAX_BUF);
-	fgets(line, MAX_BUF - 1, file);
-	(*linenum)++; /* increment line counter. */
 
 	/* Parsing loop */
-	while ((line[0] != '\0') && (strchr(line, '}') == NULL)) {
+	while (memset(line, 0, MAX_BUF) && fgets(line, MAX_BUF - 1, file) && (strchr(line, '}') == NULL)) {
+		(*linenum)++; /* increment line counter. */
+
 		/* skip leading blank spaces */
 		for (p1 = line; isblank(*p1); p1++);
 
@@ -330,11 +328,6 @@ parse_auth_server(FILE *file, const char *filename, int *linenum)
 					break;
 			}
 		}
-
-		/* Read next line */
-		memset(line, 0, MAX_BUF);
-		fgets(line, MAX_BUF - 1, file);
-		(*linenum)++; /* increment line counter. */
 	}
 
 	/* only proceed if we have an host and a path */
@@ -408,13 +401,10 @@ parse_firewall_ruleset(const char *ruleset, FILE *file, const char *filename, in
 
 	debug(LOG_DEBUG, "Adding Firewall Rule Set %s", ruleset);
 	
-	/* Read first line */	
-	memset(line, 0, MAX_BUF);
-	fgets(line, MAX_BUF - 1, file);
-	(*linenum)++; /* increment line counter. */
-
 	/* Parsing loop */
-	while ((line[0] != '\0') && (strchr(line, '}') == NULL)) {
+	while (memset(line, 0, MAX_BUF) && fgets(line, MAX_BUF - 1, file) && (strchr(line, '}') == NULL)) {
+		(*linenum)++; /* increment line counter. */
+
 		/* skip leading blank spaces */
 		for (p1 = line; isblank(*p1); p1++);
 
@@ -462,11 +452,6 @@ parse_firewall_ruleset(const char *ruleset, FILE *file, const char *filename, in
 					break;
 			}
 		}
-
-		/* Read next line */
-		memset(line, 0, MAX_BUF);
-		fgets(line, MAX_BUF - 1, file);
-		(*linenum)++; /* increment line counter. */
 	}
 
 	debug(LOG_DEBUG, "Firewall Rule Set %s added.", ruleset);
diff --git a/src/ping_thread.c b/src/ping_thread.c
index cf1a6ef..af7cc07 100644
--- a/src/ping_thread.c
+++ b/src/ping_thread.c
@@ -125,7 +125,9 @@ ping(void)
 	 * Populate uptime, memfree and load
 	 */
 	if ((fh = fopen("/proc/uptime", "r"))) {
-		fscanf(fh, "%lu", &sys_uptime);
+		if(fscanf(fh, "%lu", &sys_uptime) != 1)
+                	debug(LOG_CRIT, "Failed to read uptime");
+
 		fclose(fh);
 	}
 	if ((fh = fopen("/proc/meminfo", "r"))) {
@@ -142,7 +144,9 @@ ping(void)
 		fclose(fh);
 	}
 	if ((fh = fopen("/proc/loadavg", "r"))) {
-		fscanf(fh, "%f", &sys_load);
+		if(fscanf(fh, "%f", &sys_load) != 1)
+			debug(LOG_CRIT, "Failed to read loadavg");
+
 		fclose(fh);
 	}
 
diff --git a/src/util.c b/src/util.c
index 90eeb00..d6962da 100644
--- a/src/util.c
+++ b/src/util.c
@@ -302,8 +302,7 @@ get_ext_iface(void)
 		input = fopen("/proc/net/route", "r");
 		while (!feof(input)) {
 			/* XXX scanf(3) is unsafe, risks overrun */ 
-			fscanf(input, "%s %s %*s %*s %*s %*s %*s %*s %*s %*s %*s\n", device, gw);
-			if (strcmp(gw, "00000000") == 0) {
+			if ((fscanf(input, "%s %s %*s %*s %*s %*s %*s %*s %*s %*s %*s\n", device, gw) == 2) && strcmp(gw, "00000000") == 0) {
 				free(gw);
 				debug(LOG_INFO, "get_ext_iface(): Detected %s as the default interface after try %d", device, i);
 				return device;
diff --git a/src/wdctl_thread.c b/src/wdctl_thread.c
index 0cfadbb..5946f3c 100644
--- a/src/wdctl_thread.c
+++ b/src/wdctl_thread.c
@@ -72,7 +72,7 @@ static void wdctl_restart(int);
 void
 thread_wdctl(void *arg)
 {
-	int	fd;
+	int	*fd;
 	char	*sock_name;
 	struct 	sockaddr_un	sa_un;
 	int result;
@@ -125,14 +125,17 @@ thread_wdctl(void *arg)
 	while (1) {
 		len = sizeof(sa_un); 
 		memset(&sa_un, 0, len);
-		if ((fd = accept(wdctl_socket_server, (struct sockaddr *)&sa_un, &len)) == -1){
+		fd = (int *) safe_malloc(sizeof(int));
+		if ((*fd = accept(wdctl_socket_server, (struct sockaddr *)&sa_un, &len)) == -1){
 			debug(LOG_ERR, "Accept failed on control socket: %s",
 					strerror(errno));
+			free(fd);
 		} else {
 			debug(LOG_DEBUG, "Accepted connection on wdctl socket %d (%s)", fd, sa_un.sun_path);
 			result = pthread_create(&tid, NULL, &thread_wdctl_handler, (void *)fd);
 			if (result != 0) {
 				debug(LOG_ERR, "FATAL: Failed to create a new thread (wdctl handler) - exiting");
+				free(fd);
 				termination_handler(0);
 			}
 			pthread_detach(tid);
@@ -153,8 +156,8 @@ thread_wdctl_handler(void *arg)
 
 	debug(LOG_DEBUG, "Entering thread_wdctl_handler....");
 
-	fd = (int)arg;
-	
+	fd = *((int *) arg);
+	free(arg);
 	debug(LOG_DEBUG, "Read bytes and stuff from %d", fd);
 
 	/* Init variables */
@@ -214,7 +217,8 @@ wdctl_status(int fd)
 	status = get_status_text();
 	len = strlen(status);
 
-	write(fd, status, len);
+	if(write(fd, status, len) == -1)
+		debug(LOG_CRIT, "Write error: %s", strerror(errno));
 
 	free(status);
 }
@@ -374,7 +378,9 @@ wdctl_reset(int fd, char *arg)
 	else {
 		debug(LOG_DEBUG, "Client not found.");
 		UNLOCK_CLIENT_LIST();
-		write(fd, "No", 2);
+		if(write(fd, "No", 2) == -1)
+                	debug(LOG_CRIT, "Unable to write No: %s", strerror(errno));
+		
 		return;
 	}
 
@@ -388,7 +394,8 @@ wdctl_reset(int fd, char *arg)
 	
 	UNLOCK_CLIENT_LIST();
 	
-	write(fd, "Yes", 3);
+	if(write(fd, "Yes", 3) == -1)
+		debug(LOG_CRIT, "Unable to write Yes: %s", strerror(errno));
 	
 	debug(LOG_DEBUG, "Exiting wdctl_reset...");
 }
-- 
1.7.9.5


--------------090002010409030908050205
Content-Type: text/x-patch;
 name="0003-Add-many-const.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0003-Add-many-const.patch"



More information about the Nodogsplash mailing list