Re: multiple unsequenced modifications

Bruno Haible <[email protected]>
Newsgroups gmane.lisp.clisp.devel
Message-ID <2014611.Ls74tacvFW@omega>
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


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
clisp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.