git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] daemon.c:handle: Remove unneeded check for null pointer.

From
Stefan Beller <stefanbeller@googlemail.com>
Date
May 26, 2013, 19:54 UTC
Message-ID
<1369598080-9561-1-git-send-email-stefanbeller@googlemail.com>

The handle function has the signature static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen); so the addr pointer may be passed as null syntactically.

However there is just one place in daemon.c, which calls the handle function in function service_loop in daemon.c:1044: handle(incoming, &ss.sa, sslen); so there is always a valid pointer for the sockaddr passed to the handle function.

The code in question was to its place in f9c87be6, when following the git blame it originates from 5b276ee4. That commit 5b276ee4 also seems to copy around the ipv6 code block and the sockaddr pointer check being null is introduced. However that commit has already a redundant check on addr being a null pointer before.

I am including the authors of said patches to the receivers.
---
 daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/daemon.c b/daemon.c
index 6aeddcb..5e48c1e 100644
--- a/daemon.c
+++ b/daemon.c
@@ -760,7 +760,7 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
 		snprintf(portbuf, sizeof(portbuf), "REMOTE_PORT=%d",
 		    ntohs(sin_addr->sin_port));
 #ifndef NO_IPV6
-	} else if (addr && addr->sa_family == AF_INET6) {
+	} else if (addr->sa_family == AF_INET6) {
 		struct sockaddr_in6 *sin6_addr = (void *) addr;
 
 		char *buf = addrbuf + 12;
-- 
1.8.3
Message 1 of 1 in “daemon.c:handle: Remove unneeded check for null pointer.”
  1. daemon.c:handle: Remove unneeded check for null pointer.Stefan Beller, May 26, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.