threads / patch / 1979

patchFix gcc-4 warning in accept() call

Subject: [PATCH] Fix gcc-4 warning in accept() call

## tl;dr

5 messages between Sep 29, 2005 and Sep 30, 2005. Diffs are folded; open one to read it.

replies: 4people: 3as markdown or json

Pavel Roskin· Sep 29, 2005, 21:05 UTC · lore
Fix gcc-4 warning in accept() call

gcc-4 warns about sign mismatch in pointers. Third argument in accept() is socklen_t, which is unsigned. Since Linus doesn't like socklen_t (see commit 7fa090844f7d1624c7d1ffc621aae6aec84a1110), let's use unsigned int.

Signed-off-by: Pavel Roskin <proski@gnu.org>
Show changes to daemon.c +1 −1
diff --git a/daemon.c b/daemon.c
--- a/daemon.c
+++ b/daemon.c
@@ -459,7 +459,7 @@ static int serve(int port)
 
 			if (FD_ISSET(sockfd, &fds)) {
 				struct sockaddr_storage ss;
-				int sslen = sizeof(ss);
+				unsigned int sslen = sizeof(ss);
 				int incoming = accept(sockfd, (struct sockaddr *)&ss, &sslen);
 				if (incoming < 0) {
 					switch (errno) {
-- 
Regards,
Pavel Roskin
Junio C Hamano· Sep 30, 2005, 05:49 UTC · re: Pavel Roskin · lore

Re: [PATCH] Fix gcc-4 warning in accept() call

Pavel Roskin <proski@gnu.org> writes:
> gcc-4 warns about sign mismatch in pointers.  Third argument in accept()
> is socklen_t, which is unsigned.  Since Linus doesn't like socklen_t
> (see commit 7fa090844f7d1624c7d1ffc621aae6aec84a1110), let's use
> unsigned int.

Based on the list comments, I'd drop this patch -- it appears that gcc-4 warning is useless in this case.

H. Peter Anvin· Sep 30, 2005, 05:53 UTC · re: Junio C Hamano · lore

Re: [PATCH] Fix gcc-4 warning in accept() call

Junio C Hamano wrote:
Show 11 quoted lines
> Pavel Roskin <proski@gnu.org> writes:
> 
> 
>>gcc-4 warns about sign mismatch in pointers.  Third argument in accept()
>>is socklen_t, which is unsigned.  Since Linus doesn't like socklen_t
>>(see commit 7fa090844f7d1624c7d1ffc621aae6aec84a1110), let's use
>>unsigned int.
> 
> Based on the list comments, I'd drop this patch -- it appears
> that gcc-4 warning is useless in this case.
> 

No, it's not. The proper type, if you don't use socklen_t, is int, not unsigned int.

	-hpa
H. Peter Anvin· Sep 30, 2005, 05:58 UTC · re: H. Peter Anvin · lore

Re: [PATCH] Fix gcc-4 warning in accept() call

H. Peter Anvin wrote:
Show 18 quoted lines
> Junio C Hamano wrote:
> 
>> Pavel Roskin <proski@gnu.org> writes:
>>
>>
>>> gcc-4 warns about sign mismatch in pointers.  Third argument in accept()
>>> is socklen_t, which is unsigned.  Since Linus doesn't like socklen_t
>>> (see commit 7fa090844f7d1624c7d1ffc621aae6aec84a1110), let's use
>>> unsigned int.
>>
>>
>> Based on the list comments, I'd drop this patch -- it appears
>> that gcc-4 warning is useless in this case.
>>
> 
> No, it's not.  The proper type, if you don't use socklen_t, is int, not 
> unsigned int.
> 

Apparently I'm wrong; socklen_t is unsigned int at least on glibc for i386. I'll shut up now.

	-hpa
Junio C Hamano· Sep 30, 2005, 06:21 UTC · re: H. Peter Anvin · lore

Re: [PATCH] Fix gcc-4 warning in accept() call

"H. Peter Anvin" <hpa@zytor.com> writes:
> Apparently I'm wrong; socklen_t is unsigned int at least on glibc for 
> i386.  I'll shut up now.

Ah, I should shut up too. Thanks for checking what we should use.

← back to recent threads