Re: [PATCH v3 07/25] sequencer: completely revamp the "todo" script parsing
- From
Torsten Bögershausen <tboegi@web.de>
- Date
- Oct 15, 2016, 17:40 UTC
- Message-ID
- <d9f4f658-94fb-cb9e-7da8-3a2fac120a9e@web.de>
- In-Reply-To
- <20161015171926.qgtvrjcaqwb436hx@sigill.intra.peff.net>
On 15.10.16 19:19, Jeff King wrote:
Show 24 quoted lines
> On Sat, Oct 15, 2016 at 07:03:46PM +0200, Torsten Bögershausen wrote: > >> sequencer.c:633:14: warning: comparison of constant 2 with expression of type 'const enum todo_command' is always true [-Wtautological-constant-out-of-range-compare] >> if (command < ARRAY_SIZE(todo_command_strings)) >> ~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> 1 warning generated. >> >> 53f8024e (Johannes Schindelin 2016-10-10 19:25:07 +0200 633) if (command < ARRAY_SIZE(todo_command_strings)) >> > > Interesting. The compiler is right that this _should_ never happen, but > I think the patch is quite reasonable to be defensive in case the enum > happens to get a value outside of its acceptable range (which is > probably undefined behavior, but...). > > I wonder if: > > if ((int)command < ARRAY_SIZE(todo_command_strings)) > > silences the warning (I suppose size_t is probably an even better type, > though obviously it does not matter in practice). > > -Peff >
Both do (silence the warning)
enum may be signed or unsigned, right ? So the size_t variant seams to be a better choice