On Tue, 19 Sep 2023 21:40:18 GMT, Chris Plummer <[email protected]> wrote:
> > Similar to @plummercj comment what about this code at L730:
> > ```
> > // Try to find bind address of preferred address family first.
> > for (ai = addrInfo; ai != NULL; ai = ai->ai_next) {
> > if (ai->ai_family == preferredAddressFamily) {
> > listenAddr = ai;
> > break;
> > }
> > }
> > ```
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > with AF_INET or AF_INET6 this would find a match, but with AF_UNSPEC then
> > it seems it will just leave `ai` pointing to the last entry. ???
>
> Wouldn't ai be NULL?
I think so, but does the value of `ai` when the loop exits matter? I don't see
any reads of that value. There's another use of `ai` on L752, but it gets
reinitialized first.
I could update this to something like the following, which I think will result
in equivalent behavior but is possibly more readable, and avoids unnecessarily
iterating over all the addresses:
// Try to find bind address of preferred address family first.
for (ai = addrInfo; ai != NULL; ai = ai->ai_next) {
- if (ai->ai_family == preferredAddressFamily) {
+ if (ai->ai_family == preferredAddressFamily || preferredAddressFamily
== AF_UNSPEC) {
listenAddr = ai;
break;
}
}
-------------
PR Comment: https://git.openjdk.org/jdk/pull/15796#issuecomment-1726572673