[PATCH] lib/fib: remove warning about implicit 64-bit conversion

Andre Muezerie andremue at linux.microsoft.com
Thu Dec 5 16:34:23 CET 2024


On Wed, Dec 04, 2024 at 02:59:40PM -0800, Stephen Hemminger wrote:
> On Tue,  3 Dec 2024 18:56:50 -0800
> Andre Muezerie <andremue at linux.microsoft.com> wrote:
> 
> > MSVC issues the warning below:
> > 
> > ../lib/fib/trie.c(341): warning C4334: '<<':
> > result of 32-bit shift implicitly converted to 64 bits
> > (was 64-bit shift intended?)
> > 
> > The fix is to cast the result explicitly to ptrdiff_t since it is used
> > in pointer arithmetic.
> > 
> > Signed-off-by: Andre Muezerie <andremue at linux.microsoft.com>
> > ---
> >  lib/fib/trie.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/lib/fib/trie.c b/lib/fib/trie.c
> > index 4893f6c636..997b7cc338 100644
> > --- a/lib/fib/trie.c
> > +++ b/lib/fib/trie.c
> > @@ -338,7 +338,7 @@ write_edge(struct rte_trie_tbl *dp, const uint8_t *ip_part, uint64_t next_hop,
> >  		if (ret < 0)
> >  			return ret;
> >  		if (edge == LEDGE) {
> > -			write_to_dp((uint8_t *)p + (1 << dp->nh_sz),
> > +			write_to_dp((uint8_t *)p + (ptrdiff_t)(1 << dp->nh_sz),
> >  				next_hop << 1, dp->nh_sz, UINT8_MAX - *ip_part);
> 
> You would be better to use a 64 bit shift or RTE_BIT64 for this.
> 
> 			write_to_dp((uint8_t *)p + ((uintptr_t)1 << dp->nh_sz),

Thanks for the suggestion. I'll update the patch.


More information about the dev mailing list