hash-functions: Avoid signed integer overflow.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 14 Oct 2018 19:31:52 +0000 (12:31 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 14 Oct 2018 19:33:26 +0000 (12:33 -0700)
cppcheck reported that 0xdeadbeef + 8 yielded signed integer overflow.
This is probably harmless, as long as the compiler doesn't do something
really strange, but it's even better if we just ensure that this
arithmetic is done as unsigned.

Reported by John Darrington.

src/libpspp/hash-functions.c

index 7a8d8162ecaa5f364c984c1a42827994a7cdfd64..4de7f777912ac7a1240c1d2abf4a699e05f7a8e1 100644 (file)
@@ -125,7 +125,7 @@ hash_double (double d, unsigned int basis)
       uint32_t tmp[2];
       uint32_t a, b, c;
 
-      a = b = c = 0xdeadbeef + 8 + basis;
+      a = b = c = 0xdeadbeefU + 8 + basis;
 
       memcpy (tmp, &d, 8);
       a += tmp[0];