]> granicus.if.org Git - python/commitdiff
Fix overflow test for multiply to catch some cases it missed.
authorGuido van Rossum <guido@python.org>
Mon, 6 Jan 1997 22:53:20 +0000 (22:53 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 6 Jan 1997 22:53:20 +0000 (22:53 +0000)
Added warning about dependency of float/complex hash on int hash.

Objects/intobject.c

index 62649209bfc2513ea4792846dee8123d6b409bc7..3598c90e8ebd83fe681673f76986a9bbb20d3f60 100644 (file)
@@ -237,6 +237,8 @@ static long
 int_hash(v)
        intobject *v;
 {
+       /* XXX If this is changed, you also need to change the way
+          Python's long, float and complex types are hashed. */
        long x = v -> ob_ival;
        if (x == -1)
                x = -2;
@@ -385,13 +387,13 @@ int_mul(v, w)
                        (NB b == bl in this case, and we make a = al) */
 
        y = ah*b;
-       if (y >= (1L << (LONG_BIT/2)))
+       if (y >= (1L << (LONG_BIT/2 - 1)))
                goto bad;
        a &= (1L << (LONG_BIT/2)) - 1;
        x = a*b;
        if (x < 0)
                goto bad;
-       x += y << LONG_BIT/2;
+       x += y << (LONG_BIT/2);
        if (x < 0)
                goto bad;
  ok: