[PATCH] Fix warnings if !ALL_STATE: address of gmtmem always, evaluates as true

Hello, fixes some compiler warnings: If ALL_STATE is not defined, the address of gmtcheck always evaluates to true. Andreas -- Andreas Stieger <astieger@suse.com> Project Manager Security SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)

On 02/28/2017 07:59 AM, Andreas Stieger wrote:
If ALL_STATE is not defined, the address of gmtcheck always evaluates to true.
It's valid C code and does the right thing, so this warning is a false positive. To compile without warnings with a recent GCC, you can use: make CFLAGS='$(GCC_DEBUG_FLAGS)' Other compilers (and older versions of GCC) may need other options. In general the code doesn't bother trying to silence all the warnings generated by all the world's C compilers, as the job would be endless and we might even have dueling compilers. Of course we should continue to fix real bugs and obvious howlers found by clever new compilers.

Hello, On 02/28/2017 05:27 PM, Paul Eggert wrote:
On 02/28/2017 07:59 AM, Andreas Stieger wrote:
If ALL_STATE is not defined, the address of gmtcheck always evaluates to true.
It's valid C code and does the right thing, so this warning is a false positive.
It is valid C code and does the right thing, so is the proposal. But would you not say that less warnings would make the real ones stand out better?
Other compilers (and older versions of GCC) may need other options. In general the code doesn't bother trying to silence all the warnings generated by all the world's C compilers, as the job would be endless and we might even have dueling compilers.
Are you aware of any compilers that would object to the patch? Andreas

On 02/28/2017 11:34 AM, Andreas Stieger wrote:
would you not say that less warnings would make the real ones stand out better?
Sure, but using appropriate compiler options should also generate less warnings, and that should be a better solution. The idea is to avoid contorting C code merely to pacify a compiler that's configured to be too picky. The proposed code: #ifdef ALL_STATE gmtptr = malloc(sizeof *gmtptr); if (gmtptr) #endif gmtload(gmtptr); is hard to read, since the C preprocessor nesting is not consistent with the preprocessed nesting. Readability is more important than silencing false positives.
participants (2)
-
Andreas Stieger
-
Paul Eggert