diff mbox series

[hurd,commited] hurd sendmsg: Fix warning on calling CMSG_*HDR

Message ID 20191229165108.2856915-1-samuel.thibault@ens-lyon.org
State New
Headers show
Series [hurd,commited] hurd sendmsg: Fix warning on calling CMSG_*HDR | expand

Commit Message

Samuel Thibault Dec. 29, 2019, 4:51 p.m. UTC
---
 sysdeps/mach/hurd/sendmsg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andreas Schwab Dec. 29, 2019, 5:12 p.m. UTC | #1
On Dez 29 2019, Samuel Thibault wrote:

> diff --git a/sysdeps/mach/hurd/sendmsg.c b/sysdeps/mach/hurd/sendmsg.c
> index 0c19b3223c..3d7317cec4 100644
> --- a/sysdeps/mach/hurd/sendmsg.c
> +++ b/sysdeps/mach/hurd/sendmsg.c
> @@ -108,7 +108,7 @@ __libc_sendmsg (int fd, const struct msghdr *message, int flags)
>  
>    /* Allocate enough room for ports.  */
>    cmsg = CMSG_FIRSTHDR (message);
> -  for (; cmsg; cmsg = CMSG_NXTHDR (message, cmsg))
> +  for (; cmsg; cmsg = CMSG_NXTHDR ((struct msghdr *) message, cmsg))

Why is the first argument of __cmsg_nxthdr not const?

Andreas.
Samuel Thibault Dec. 29, 2019, 5:21 p.m. UTC | #2
Andreas Schwab, le dim. 29 déc. 2019 18:12:02 +0100, a ecrit:
> > -  for (; cmsg; cmsg = CMSG_NXTHDR (message, cmsg))
> > +  for (; cmsg; cmsg = CMSG_NXTHDR ((struct msghdr *) message, cmsg))
> 
> Why is the first argument of __cmsg_nxthdr not const?

I don't know, it is so on other systems as well.

I guess an issue is that if it was const, CMSG_NXTHDR would only
be allowed to return a const, and the caller might actually want a
non-const (and it passed a non-const). So it'd be a choice between
cast-parameter vs cast-returned-value.

Samuel
Andreas Schwab Dec. 29, 2019, 6:08 p.m. UTC | #3
On Dez 29 2019, Samuel Thibault wrote:

> Andreas Schwab, le dim. 29 déc. 2019 18:12:02 +0100, a ecrit:
>> > -  for (; cmsg; cmsg = CMSG_NXTHDR (message, cmsg))
>> > +  for (; cmsg; cmsg = CMSG_NXTHDR ((struct msghdr *) message, cmsg))
>> 
>> Why is the first argument of __cmsg_nxthdr not const?
>
> I don't know, it is so on other systems as well.
>
> I guess an issue is that if it was const, CMSG_NXTHDR would only
> be allowed to return a const,

The return value is not based on the first argument.

Andreas.
Samuel Thibault Dec. 29, 2019, 6:46 p.m. UTC | #4
Andreas Schwab, le dim. 29 déc. 2019 19:08:37 +0100, a ecrit:
> On Dez 29 2019, Samuel Thibault wrote:
> 
> > Andreas Schwab, le dim. 29 déc. 2019 18:12:02 +0100, a ecrit:
> >> > -  for (; cmsg; cmsg = CMSG_NXTHDR (message, cmsg))
> >> > +  for (; cmsg; cmsg = CMSG_NXTHDR ((struct msghdr *) message, cmsg))
> >> 
> >> Why is the first argument of __cmsg_nxthdr not const?
> >
> > I don't know, it is so on other systems as well.
> >
> > I guess an issue is that if it was const, CMSG_NXTHDR would only
> > be allowed to return a const,
> 
> The return value is not based on the first argument.

Oh, right. Then I don't know, I just see it so everywhere else.

Samuel
Florian Weimer Dec. 29, 2019, 6:48 p.m. UTC | #5
* Andreas Schwab:

> On Dez 29 2019, Samuel Thibault wrote:
>
>> diff --git a/sysdeps/mach/hurd/sendmsg.c b/sysdeps/mach/hurd/sendmsg.c
>> index 0c19b3223c..3d7317cec4 100644
>> --- a/sysdeps/mach/hurd/sendmsg.c
>> +++ b/sysdeps/mach/hurd/sendmsg.c
>> @@ -108,7 +108,7 @@ __libc_sendmsg (int fd, const struct msghdr
>> *message, int flags)
>>  
>>    /* Allocate enough room for ports.  */
>>    cmsg = CMSG_FIRSTHDR (message);
>> -  for (; cmsg; cmsg = CMSG_NXTHDR (message, cmsg))
>> +  for (; cmsg; cmsg = CMSG_NXTHDR ((struct msghdr *) message, cmsg))
>
> Why is the first argument of __cmsg_nxthdr not const?

Some programmers expect that CMSG_NXTHDR can be used to construct
ancillary data.  See bug 13500.
Andreas Schwab Dec. 29, 2019, 7:09 p.m. UTC | #6
On Dez 29 2019, Florian Weimer wrote:

> * Andreas Schwab:
>
>> On Dez 29 2019, Samuel Thibault wrote:
>>
>>> diff --git a/sysdeps/mach/hurd/sendmsg.c b/sysdeps/mach/hurd/sendmsg.c
>>> index 0c19b3223c..3d7317cec4 100644
>>> --- a/sysdeps/mach/hurd/sendmsg.c
>>> +++ b/sysdeps/mach/hurd/sendmsg.c
>>> @@ -108,7 +108,7 @@ __libc_sendmsg (int fd, const struct msghdr
>>> *message, int flags)
>>>  
>>>    /* Allocate enough room for ports.  */
>>>    cmsg = CMSG_FIRSTHDR (message);
>>> -  for (; cmsg; cmsg = CMSG_NXTHDR (message, cmsg))
>>> +  for (; cmsg; cmsg = CMSG_NXTHDR ((struct msghdr *) message, cmsg))
>>
>> Why is the first argument of __cmsg_nxthdr not const?
>
> Some programmers expect that CMSG_NXTHDR can be used to construct
> ancillary data.  See bug 13500.

How is that related to the first argument?

Andreas.
diff mbox series

Patch

diff --git a/sysdeps/mach/hurd/sendmsg.c b/sysdeps/mach/hurd/sendmsg.c
index 0c19b3223c..3d7317cec4 100644
--- a/sysdeps/mach/hurd/sendmsg.c
+++ b/sysdeps/mach/hurd/sendmsg.c
@@ -108,7 +108,7 @@  __libc_sendmsg (int fd, const struct msghdr *message, int flags)
 
   /* Allocate enough room for ports.  */
   cmsg = CMSG_FIRSTHDR (message);
-  for (; cmsg; cmsg = CMSG_NXTHDR (message, cmsg))
+  for (; cmsg; cmsg = CMSG_NXTHDR ((struct msghdr *) message, cmsg))
     if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
       nports += (cmsg->cmsg_len - CMSG_ALIGN (sizeof (struct cmsghdr)))
 		/ sizeof (int);
@@ -119,7 +119,7 @@  __libc_sendmsg (int fd, const struct msghdr *message, int flags)
   nports = 0;
   for (cmsg = CMSG_FIRSTHDR (message);
        cmsg;
-       cmsg = CMSG_NXTHDR (message, cmsg))
+       cmsg = CMSG_NXTHDR ((struct msghdr *) message, cmsg))
     {
       if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
 	{