Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

getaddrinfo_async: Check return value of getservbyname_r earlier #18

Closed
wants to merge 1 commit into from
Closed

getaddrinfo_async: Check return value of getservbyname_r earlier #18

wants to merge 1 commit into from

Conversation

nmeum
Copy link

@nmeum nmeum commented Oct 7, 2018

If getservbyname_r fails (or HAVE_GETSERVBYNAME_R_4_ARGS is not defined)
it doesn't make any sense to access member of the servent struct as it
will not be initialized then. Calling endservent_r shouldn't be
necessary either then.

GCC 8 also complains about this code part when compiling with
the -Wmaybe-uninitialized flag.

If getservbyname_r fails (or HAVE_GETSERVBYNAME_R_4_ARGS is not defined)
it doesn't make any sense to access member of the servent struct as it
will not be initialized then. Calling endservent_r shouldn't be
necessary either then.

GCC 8 also complains about this code part when compiling with
the -Wmaybe-uninitialized flag.
@ericfaurot
Copy link
Contributor

I agree that accessing the servent struct unconditionnaly is not nice but I would still call endservent_r().
How about something like the attached diff instead?

better.diff.txt

@nmeum
Copy link
Author

nmeum commented Oct 23, 2018

How about something like the attached diff instead?

Looks good to me.

@ericfaurot
Copy link
Contributor

The relevant changes have been commited

@ericfaurot ericfaurot closed this Nov 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants