[PATCH] sockaddr.3type: BUGS: Document that libc should be fixed using a union

Alejandro Colomar alx.manpages@gmail.com
Sun Feb 5 15:31:30 GMT 2023


Formatted version:

BUGS
        sockaddr_storage was designed back when strict aliasing wasn’t a  prob‐
        lem.  Back then, one would define a variable of that type, and then ac‐
        cess it as any of the other sockaddr_* types, depending on the value of
        the  first  member.   This is Undefined Behavior.  However, there is no
        way to use these APIs without invoking Unedfined  Behavior,  either  in
        the  user  program  or  in libc, so it is still recommended to use this
        method.  The only correct way to use  different  types  in  an  API  is
        through  a  union.   However, that union must be implemented in the li‐
        brary, since the type must be shared between the library and user code,
        so libc should be fixed by implementing sockaddr_storage as a union.
-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20230205/9a54cc03/attachment.sig>


More information about the Gcc mailing list