nmh-workers
[Top] [All Lists]

Re: [Nmh-workers] Announcing the second release candidate of nmh 1.7.1

2018-01-23 07:27:25
  From: Ralph Corderoy <ralph@inputplus.co.uk>
  Date: Tue, 23 Jan 2018 11:03:46 +0000
  Subject: Re: [Nmh-workers] Announcing the second release candidate of nmh
      1.7.1

  | Does swapping the strlen and true line above shut it up?

It wouldn't.   The issue will be that some gcc versions (I've never
understood whether it is getting worse, or better, with newer versions)
simply don't understand the concept of conditional initialization
coupled with guarded references.

If there is no guaranteed initialization (which must obviously always be
executed) and there is any reference at all, you'll end up with that warning
on those gcc versions.   The flow analysis simply isn't good enough.

The easy solution is just to change:

        int var;                /* or whatever it is */
to
        int var = -1;           /* XXX: silence the dog */

and be done with it (and just ignore the minor cost of the totally
useless unnecessary init).

Sometimes you can instead change

        if (whatever) {
                var = set;
                guard = true;
        }

into

        if (whatever) {
                var = set;
                guard = true;
        } else
                var = garbage;

instead - then you only pay the (execution) cost of the garbage
assignment when the (usually) more common case is not executed.
This doesn't al,ways work - and obviously not in the case where
this code is embedded in a loop, and the idea is that you do the
init just once, so code like

        for (i = 0; i < MAX; i++) {
                /* ... */
                if (i == 0)
                        var = init_var;

                /* ... more code with references to var */
        }
        /* more code with refs to var */

can't be handled that way, and in any case, hiding the dummy
init that way isn't generally worth the hidden costs (extra
branches, more difficult to understand for humans) execpt when the
init is costly (like a large struct or array init).

Sometimes the init can just be done before the loop in cases like
this (even if it does mean duplicating a bunch of other code that
is in the first /*...*/ block above, in others that's just too hard,
but in any case the first (silence the cur) method will almost always
work.   Since no-one ever references the var when it has the dummy
value in it, it should make no difference what value is assigned
(NULL generally works for pointers, and 0 or -1 for ints).

kre

-- 
Nmh-workers
https://lists.nongnu.org/mailman/listinfo/nmh-workers

<Prev in Thread] Current Thread [Next in Thread>