Re: [PATCH] SUNRPC: clean up integer overflow check

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

 



On 6/30/23 15:13, Dan Carpenter wrote:

So here we have:

	if (u32_val > SOMETHING) {

The condition is impossible when the code is compiled on a 64-bit
system

This is exactly what the compilers warns about:

$ cat test.c
#include <stdint.h>

int f (int *p, unsigned n)
{
  return n > SIZE_MAX / sizeof (*p);
}
$ gcc -Wextra -c test.c
test.c: In function ‘f’:
test.c:5:12: warning: comparison is always false due to limited range of data type [-Wtype-limits]
    5 |   return n > SIZE_MAX / sizeof (*p);
      |            ^
$ gcc -m32 -Wextra -c test.c
$ clang -Wextra -c test.c
test.c:5:12: warning: result of comparison of constant 4611686018427387903 with expression of type 'unsigned int' is always false [-Wtautological-constant-out-of-range-compare]
  return n > SIZE_MAX / sizeof (*p);
         ~ ^ ~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
$ clang -m32 -Wextra -c test.c
$

Where is a bug here? What the compiler developers are intended to fix?
How the compilers should behave in this case?

Dmitry






[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux