threads / patch / 1981

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

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

## tl;dr

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

replies: 2people: 3as markdown or json

Horst von Brand· Sep 29, 2005, 23:11 UTC · lore
Pavel Roskin <proski@gnu.org> wrote:
Show 18 quoted lines
> 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>
> 
> 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);
Shouldn't this be size_t?
>  				int incoming = accept(sockfd, (struct sockaddr *)&ss, &sslen);
>  				if (incoming < 0) {
>  					switch (errno) {
-- 
Dr. Horst H. von Brand                   User #22616 counter.li.org
Departamento de Informatica                     Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria              +56 32 654239
Casilla 110-V, Valparaiso, Chile                Fax:  +56 32 797513
Pavel Roskin· Sep 30, 2005, 04:09 UTC · re: Horst von Brand · lore
Quoting Horst von Brand <vonbrand@inf.utfsm.cl>:
> > +				unsigned int sslen = sizeof(ss);
>
> Shouldn't this be size_t?
No.  That would actually break things on big-endian 64-bit platforms.

You can see "info libc" for the whole story. My (limited!) understanding is that it should be 32-bit for compatibility reasons, so socklen_t was a trick to fool size_t proponents from the POSIX committee :-)

-- Regards, Pavel Roskin

H. Peter Anvin· Sep 30, 2005, 04:46 UTC · re: Pavel Roskin · lore
Pavel Roskin wrote:
Show 14 quoted lines
> Quoting Horst von Brand <vonbrand@inf.utfsm.cl>:
> 
> 
>>>+				unsigned int sslen = sizeof(ss);
>>
>>Shouldn't this be size_t?
> 
> 
> No.  That would actually break things on big-endian 64-bit platforms.
> 
> You can see "info libc" for the whole story.  My (limited!) understanding is
> that it should be 32-bit for compatibility reasons, so socklen_t was a trick to
> fool size_t proponents from the POSIX committee :-)
> 

Formally it should be "socklen_t" or "int". It should *not* be "unsigned int"!

	-hpa

← back to recent threads