Re: [PATCH nft 7/9] expression: cleanup expr_ops_by_type() and handle u32 input

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2023-09-21 at 16:19 +0200, Pablo Neira Ayuso wrote:
> On Wed, Sep 20, 2023 at 09:28:29PM +0200, Thomas Haller wrote:
> 
> 
> > The check "if (value > (uint32_t) EXPR_MAX)" is only here to ensure
> > that nothing is lost while casting the uint32_t "value" to the enum
> > expr_types.
> 
> Is this cast really required? This is to handle the hypothetical case
> where EXPR_MAX ever gets a negative value?
> 

EXPR_MAX is never negative.

If EXPR_MAX is treated as a signed integer, then it will be implicitly
cast to unsigned when comparing with the uint32_t. The behavior will be
correct without a cast.

But won't the compiler warn about comparing integers of different
signedness?

The cast is probably not needed. But it doesn't hurt.


Thomas





[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux