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

3 messages from 2005-09-29 to 2005-09-30. Participants: Horst von Brand, Pavel Roskin, H. Peter Anvin.
Thread: https://gitlist.dev/t/1981

## Horst von Brand, 2005-09-29 23:11

Subject: Re: [PATCH] Fix gcc-4 warning in accept() call
Message-ID: <200509292311.j8TNBZDm022135@inti.inf.utfsm.cl>
URL: https://gitlist.dev/e/200509292311.j8TNBZDm022135%40inti.inf.utfsm.cl
In-Reply-To: <proski@gnu.org>

```
Pavel Roskin <proski@gnu.org> wrote:
> 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, 2005-09-30 04:09

Subject: Re: [PATCH] Fix gcc-4 warning in accept() call
Message-ID: <20050930000917.rrwggw4g0gogs8w4@webmail.spamcop.net>
URL: https://gitlist.dev/e/20050930000917.rrwggw4g0gogs8w4%40webmail.spamcop.net
In-Reply-To: <200509292311.j8TNBZDm022135@inti.inf.utfsm.cl>

```
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, 2005-09-30 04:46

Subject: Re: [PATCH] Fix gcc-4 warning in accept() call
Message-ID: <433CC31A.9090808@zytor.com>
URL: https://gitlist.dev/e/433CC31A.9090808%40zytor.com
In-Reply-To: <20050930000917.rrwggw4g0gogs8w4@webmail.spamcop.net>

```
Pavel Roskin wrote:
> 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

```
