From: Bruno H. <br...@cl...> - 2017-12-07 11:00:33
|
Hi Sam, > I get this: > --8<---------------cut here---------------start------------->8--- > modules/rawsock/rawsock.c:893:48: warning: multiple unsequenced > modifications to 'STACK' [-Wunsequenced] > --8<---------------cut here---------------end--------------->8--- > > because of > > --8<---------------cut here---------------start------------->8--- > struct addrinfo hints = {addrinfo_flags(), > check_socket_domain(popSTACK()), > check_socket_type(popSTACK()), > get_socket_protocol(popSTACK()), > 0,NULL,NULL,NULL}; > --8<---------------cut here---------------end--------------->8--- GCC told you about one problem with this code. The other problem is that the code assumes a certain order of the members of 'struct addrinfo'. Which is not guaranteed by POSIX: [1] says "The <netdb.h> header shall define the addrinfo structure, which shall include at least the following members:" > The only honest way to avoid the issue is > > --8<---------------cut here---------------start------------->8--- > struct addrinfo hints = {0,0,0,0,0,NULL,NULL,NULL}; > hints.ai_flags = addrinfo_flags(); > hints.ai_family = check_socket_domain(popSTACK()); > hints.ai_socktype = check_socket_type(popSTACK()); > hints.ai_protocol = get_socket_protocol(popSTACK()); > --8<---------------cut here---------------end--------------->8--- This is better, but it too suffers from the second problem. How about this? struct addrinfo hints; memset(&hints,0,sizeof(hints)); hints.ai_flags = addrinfo_flags(); hints.ai_family = check_socket_domain(popSTACK()); hints.ai_socktype = check_socket_type(popSTACK()); hints.ai_protocol = get_socket_protocol(popSTACK()); > It is worth bothering with? Definitely! Bruno [1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netdb.h.html |