[Swan-dev] [Swan-commit] Changes to ref refs/heads/master

Andrew Cagney andrew.cagney at gmail.com
Tue Jan 19 00:56:23 UTC 2016

On 18 January 2016 at 18:17, D. Hugh Redelmeier <hugh at vault.libreswan.fi> wrote:
> New commits:
> commit f86565435a7c00f8419ced6631d131d35d18011e
> Author: D. Hugh Redelmeier <hugh at mimosa.com>
> Date:   Mon Jan 18 18:16:33 2016 -0500
>     pluto ikev2_spdb_struct.c: initialize structs the old way for old GCC

Actually this commit contained two changes.

Firstly, I like this:

+static bool print_join(struct print *buf, int n)
        if (n < 0 || buf->pos + n > sizeof(buf->buf))
                return FALSE;
        buf->pos += n;
        return TRUE;

but needs a further tweak (I was also going through it carefully today
as part of more logging).  It should be:

  if (n < 0)
    return FALSE;
  if (buf->pos + n >= sizeof(buf->buf)) {
    buf->pos = sizeof(buf->buf);
    return FALSE;

as, otherwise it will keep rewriting the end of the buffer.  I'm
tempted to also also rewrite the tail of the buffer to "...".

However, for this:

-       struct print buf = {0};
+       struct print buf;
+       print_init(&buf);


-               *proposal = (struct ikev2_proposal) {0};
+               static struct ikev2_proposal zero_proposal;     /*
naturally zero */

as discussed here,
the code's behaviour is very well defined (both for C90 and C99), it
is just that GCC throwing a needless hissy fit.  Anyway, if we're
really going to pacify errors like this then the standard way is to
just add a coma like this:

  struct print buf = {0,};

or this:

                        /* blat best with a new value */
                        *best = (struct ikev2_proposal) {
                                .propnum = remote_proposal.isap_protoid,
                                .protoid = remote_proposal.isap_protoid,
                                .remote_spi = remote_spi,

and this:

static struct ikev2_proposal default_ikev2_ike_proposal[] = {
                .protoid = IKEv2_SEC_PROTO_IKE,
                .transforms = {
                        [IKEv2_TRANS_TYPE_ENCR] = TR(ENCR_AES_GCM16_256), ...

(the latter two, didn't attract warnings :-)

More information about the Swan-dev mailing list