addressing &out[k].sa was arguably undefined, despite &out[k] being
defined the slot one past the end of an array, since the member access
.sa is intervening between the [] operator and the & operator.
? sizeof(struct sockaddr_in)
: sizeof(struct sockaddr_in6),
.ai_addr = (void *)&out[k].sa,
- .ai_canonname = outcanon,
- .ai_next = &out[k+1].ai };
+ .ai_canonname = outcanon };
+ if (k) out[k-1].ai.ai_next = &out[k].ai;
switch (addrs[i].family) {
case AF_INET:
out[k].sa.sin.sin_family = AF_INET;
}
}
out[0].ref = nais;
- out[nais-1].ai.ai_next = 0;
*res = &out->ai;
return 0;
}