Wireshark mailing list archives

Re: error: logical && with non-zero constant will always evaluate as true


From: Evan Huus <eapache () gmail com>
Date: Sat, 29 Dec 2012 10:37:42 -0500

While 'separators' is not immediately constant either,
wtap_file_read_till_separator (the function containing the strchr) is
called in only one place, and that call passes in a string constant to
the 'separators' parameter.

GCC is smart enough to figure that out, so __builtin_constant_p [1]
returns 1, leading to the warning you're seeing.

From my perspective, this is a compiler bug. The code as written is
perfectly correct, and GCC is optimizing it and then warning on the
partially-optimized code before completing the optimization (which is
to evaluate the big string of &&'s to false because
__builtin_constant_p(c) is false, resulting in a simple call to
__builtin_strchr (s, c)).

The GCC in squeeze is two patch versions shy of latest in that series
(4.4.5 vs 4.4.7). I don't see any reference to this particular bug in
the changelogs, but it might help to try a newer compiler. If not, I
would suggest filing a bug against Debian's GCC package and let them
figure out who ought to deal with it.

In the meantime, I'm not really sure what the best workaround is...

[1] http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Other-Builtins.html#index-g_t_005f_005fbuiltin_005fconstant_005fp-2868

On Sat, Dec 29, 2012 at 10:17 AM, Martin Kaiser <lists () kaiser cx> wrote:
Dear all,

I get this warning (error) when I compile svn head

peektagged.c: In function ‘wtap_file_read_till_separator’:
peektagged.c:150: error: logical ‘&&’ with non-zero constant
will always
evaluate as true
make[2]: *** [libwiretap_la-peektagged.lo] Error 1


The offending line is

   if (strchr (separators, c) != NULL)

which seems to evaluate on my system (debian squeeze) to something like

  (__extension__ (__builtin_constant_p (c) && !__builtin_constant_p (s) \
        && (c) == '\0'                    \
        ? (char *) __rawmemchr (s, c)                 \
        : __builtin_strchr (s, c)))


I still don't understand the problem. c is not constant, it's read from
a file.

Commenting out

AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wlogical-op)

in configure.ac will stop the warning.

Any ideas how to fix this properly?

Thanks,

   Martin



___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev () wireshark org>
Archives:    http://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request () wireshark org?subject=unsubscribe
___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev () wireshark org>
Archives:    http://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request () wireshark org?subject=unsubscribe


Current thread: