https://bugs.kde.org/show_bug.cgi?id=497977

--- Comment #4 from Vincent Lefèvre <vincent-...@vinc17.net> ---
The GCC output is helpful in the sense that it shows that the value is huge;
the exact value really does not matter: malloc will fail to allocate the memory
for any size of this order of magnitude. The "it most likely is a small
negative value (cast to an unsigned type)" may be true only if it is actually a
small negative value (in magnitude). But with

#include <stdlib.h>
int main (void)
{
  void *p = malloc ((size_t) 0x8000000000000000);
  return p != NULL;
}

valgrind currently outputs

Argument 'size' of function malloc has a fishy (possibly negative) value:
-9223372036854775808

while in this case, I do not see a cast of a negative value to an unsigned type
as being the probable cause.

I would tend to say that something wrong occurring with negative values is
likely only when the width of the value converted to signed is roughly at most
the width of the size_t type divided by 2. For instance, on a machine with a
64-bit size_t, if an internal computation of the size is done with signed
32-bit arithmetic and overflows, one may get a 32-bit negative value, and after
it is converted to the unsigned 64-bit type size_t, one gets a huge positive
value instead of the expected 32-bit positive value.

So, perhaps output the corresponding negative value in addition to the positive
value, but IMHO, only when the negative value is small enough in magnitude.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to