[PATCH] D95477: Replace use of deprecated gethostbyname by getaddrinfo.

Rafik Zurob via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 26 16:34:32 PST 2021


rzurob added a comment.

In D95477#2523851 <https://reviews.llvm.org/D95477#2523851>, @tschuett wrote:

> The man page uses:
>
>   memset(Hints, 0, sizeof(Hints));
>
> https://man7.org/linux/man-pages/man3/getaddrinfo.3.html

The POSIX specification discourages using memset to initialize addrinfo for portability reasons. 
https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html
Under "Application Usage", it says:

> Although it is common practice to initialize the hints structure using:
>
> struct addrinfo hints;
> memset(&hints, 0, sizeof hints);
>
> this method is not portable according to this standard, because the structure can contain pointer or floating-point members that are not required to have an all-bits-zero representation after default initialization. Portable methods make use of default initialization; for example:
>
> struct addrinfo hints = { 0 };
>
> or:
>
> static struct addrinfo hints_init;
> struct addrinfo hints = hints_init;




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95477/new/

https://reviews.llvm.org/D95477



More information about the llvm-commits mailing list