Re: [Wireshark-dev] error: logical with non-zero constant will always evaluate as true

2013-01-04 Thread Jeff Morriss

Guy Harris wrote:

On Jan 3, 2013, at 1:40 PM, Jeff Morriss jeff.morriss...@gmail.com wrote:


Jeff Morriss wrote:

My (Fedora 10) gcc 4.3.2 was also generating this warning; it would seem that a 
fair spread of gcc versions seem to have the problem.
I added a configure check to stop using -Wlogical-op if the compiler is 
generating this warning in r46916.

Interestingly the Ubuntu buildbot says it would also get the warning:


checking whether we can add -Wlogical-op to CFLAGS... yes
checking whether -Wlogical-op generates warnings from strchr()... yes


Which means that

#include string.h
  
	int

foo(char *sep, int c)
{
if (strchr (sep, c) != NULL)
return 1;
else
return 0;
}

int
main(int argc, char **argv)
{
return foo(\\, 'a');
}

fails to compile with the CFLAGS value at the time the test is done, plus 
-Werror; it could be failing for some other reason.  To quote the comment when 
I finally got it working for -Wshadow:

Declare foo() before defining it - if we configure with
--enable-extra-gcc-checks, given that we're building with -Werror (so
that we find out whether the compiler issues a warning for a particular
construct), we have to avoid constructs that will provoke *other*
warnings.

so the code in question has to avoid whatever other warnings are being used, 
and the Ubuntu buildbot builds with --enable-extra-gcc-checks, so it warns 
about functions not declared with prototypes before they're defined.  I've 
checked in a change to declare foo() before it's defined; we'll see whether 
that fixes it.


Lesson to self: don't just be happy when 'configure' spits out the 
expected result.  Instead look at config.log and see *why* I got the 
expected result...  There were a bunch of other warnings in there which 
I didn't get when hand-compiling the program because I wasn't using all 
the options 'configure' was.

___
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-requ...@wireshark.org?subject=unsubscribe


Re: [Wireshark-dev] error: logical with non-zero constant will always evaluate as true

2013-01-03 Thread Jakub Zawadzki
On Sat, Dec 29, 2012 at 10:37:42AM -0500, Evan Huus wrote:
 In the meantime, I'm not really sure what the best workaround is...

What about using memchr() ?
This might be little stupid, but if we avoid warning this way (in cost
of some readability)...

Cheers,
 Kuba.
___
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-requ...@wireshark.org?subject=unsubscribe


Re: [Wireshark-dev] error: logical with non-zero constant will always evaluate as true

2013-01-03 Thread Jeff Morriss

Jeff Morriss wrote:
My (Fedora 10) gcc 4.3.2 was also generating this warning; it would seem 
that a fair spread of gcc versions seem to have the problem.


I added a configure check to stop using -Wlogical-op if the compiler is 
generating this warning in r46916.


Interestingly the Ubuntu buildbot says it would also get the warning:


checking whether we can add -Wlogical-op to CFLAGS... yes
checking whether -Wlogical-op generates warnings from strchr()... yes


but it was not getting the error before.

I wonder if the use of ccache on the bot was having some effect?  Or 
something else?

___
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-requ...@wireshark.org?subject=unsubscribe


Re: [Wireshark-dev] error: logical with non-zero constant will always evaluate as true

2013-01-03 Thread Guy Harris

On Jan 3, 2013, at 1:40 PM, Jeff Morriss jeff.morriss...@gmail.com wrote:

 Jeff Morriss wrote:
 My (Fedora 10) gcc 4.3.2 was also generating this warning; it would seem 
 that a fair spread of gcc versions seem to have the problem.
 I added a configure check to stop using -Wlogical-op if the compiler is 
 generating this warning in r46916.
 
 Interestingly the Ubuntu buildbot says it would also get the warning:
 
 checking whether we can add -Wlogical-op to CFLAGS... yes
 checking whether -Wlogical-op generates warnings from strchr()... yes

Which means that

#include string.h
  
int
foo(char *sep, int c)
{
if (strchr (sep, c) != NULL)
return 1;
else
return 0;
}

int
main(int argc, char **argv)
{
return foo(\\, 'a');
}

fails to compile with the CFLAGS value at the time the test is done, plus 
-Werror; it could be failing for some other reason.  To quote the comment when 
I finally got it working for -Wshadow:

Declare foo() before defining it - if we configure with
--enable-extra-gcc-checks, given that we're building with -Werror (so
that we find out whether the compiler issues a warning for a particular
construct), we have to avoid constructs that will provoke *other*
warnings.

so the code in question has to avoid whatever other warnings are being used, 
and the Ubuntu buildbot builds with --enable-extra-gcc-checks, so it warns 
about functions not declared with prototypes before they're defined.  I've 
checked in a change to declare foo() before it's defined; we'll see whether 
that fixes it.
___
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-requ...@wireshark.org?subject=unsubscribe


Re: [Wireshark-dev] error: logical with non-zero constant will always evaluate as true

2012-12-29 Thread Martin Kaiser
Thus wrote Martin Kaiser (li...@kaiser.cx):

 which seems to evaluate on my system (debian squeeze)

more specifically

martin@skogar:~$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8'
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.4 --enable-shared --enable-multiarch
--enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib
--enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-objc-gc --with-arch-32=i586 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8) 

The Ubuntu buildbot does not complain, the behaviour might depend on the
gcc version.
___
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-requ...@wireshark.org?subject=unsubscribe


Re: [Wireshark-dev] error: logical with non-zero constant will always evaluate as true

2012-12-29 Thread Evan Huus
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 li...@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-requ...@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-requ...@wireshark.org?subject=unsubscribe