[Mingw-users] socklen_t data type

Back to archive index
Keith Marshall keith****@users*****
Tue Jun 30 15:54:18 JST 2020


On 30/06/2020 03:32, Eli Zaretskii wrote:
>> From: Keith Marshall <keith****@users*****>
>> Date: Mon, 29 Jun 2020 22:34:58 +0100
>>
>>> This causes trouble when compiling a recent GDB: both Gnulib and
>>> GDB's own sources assume that socklen_t is a signed int.  Moreover,
>>> winsock functions like 'accept' and 'getsockname', expect an 'int *'
>>> type of their last argument, and it is customary to pass a 
>>> 'socklen_t *' value there.
>> 
>> Ouch!  I'm guessing that the difference in "signedness" raises warnings,
>> at best, and possibly even incompatible type conflict errors?
> 
> GDB is a C++ program these days, and is compiled with -fpermissive, so
> this causes errors.

Surely -fpermissive relaxes the error checking for type conflicts,
(possibly among other conditions -- I don't know what its scope is), so
such errors would be downgraded to warnings.  Do you, perhaps, mean that
GDB is compiled _without_ -fpermissive?

>> so if it makes life easier, feel free to modify your local copy, and
>> I'll revert that change for future releases.
> 
> Done; thanks.

There's more to it.  As I reported in:

   https://savannah.gnu.org/bugs/?57725

a primary motivator for the change to unsigned socklen_t was to avoid a
proliferation of casts in <wspiapi.h>, (of which, at the time, I seemed
to be writing quite a number).  Reviewing it again, I seem to have ended
up with only one such cast which remains necessary, at line 917:

   if( (sa == NULL) || (len < sizeof( struct sockaddr )) )

With reversion to signed socklen_t, this should become:

   if( (sa == NULL) || (len < (socklen_t)(sizeof( struct sockaddr ))) )

BTW, it was compiling my <wspiapi,h> test program with C++, to verify
this, which led me to conclude that your understanding of -fpermissive
may be inverted.

-- 
Regards,
Keith.

Public key available from keys.gnupg.net
Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.osdn.me/mailman/archives/mingw-users/attachments/20200630/67a428c1/attachment.sig>


More information about the MinGW-Users mailing list
Back to archive index