]> arthur.barton.de Git - bup.git/commitdiff
bitmatch: avoid signed/unsigned comparison
authorRob Browning <rlb@defaultvalue.org>
Sat, 30 Oct 2021 18:23:45 +0000 (13:23 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 30 Oct 2021 18:30:36 +0000 (13:30 -0500)
Thanks to Brian Minton for reporting the problem:

  I'm using gcc version 8.3.0 (Debian 8.3.0-6). The system is x86_64
  with 8 GB ram. When I try to build the source, with make, I get the
  following error:

    ...

    In file included from lib/bup/_helpers.c:69:
    lib/bup/_helpers.c: In function 'bitmatch':
    .../src/bup/src/bup/intprops.h:626:22: error: comparison of
    integer expressions of different signedness: 'long long unsigned int' and
    'Py_ssize_t' {aka 'long int'} [-Werror=sign-compare]
    : (tmax) / (b) < (a)))
    ^
    .../src/bup/src/bup/intprops.h:427:10: note: in expansion of
    macro '_GL_INT_MULTIPLY_RANGE_OVERFLOW'
    && _GL_INT_MULTIPLY_RANGE_OVERFLOW (a, b, 0, (__typeof__ (*(r))) -1)) \
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    .../src/bup/src/bup/intprops.h:655:36: note: in expansion of
    macro 'INT_MULTIPLY_WRAPV'
    #define INT_MULTIPLY_OK(a, b, r) ! INT_MULTIPLY_WRAPV (a, b, r)
    ^~~~~~~~~~~~~~~~~~
    lib/bup/_helpers.c:624:10: note: in expansion of macro 'INT_MULTIPLY_OK'
    if (!INT_MULTIPLY_OK(byte, 8, &result)
    ^~~~~~~~~~~~~~~

And to Mark J Hewitt for reporting the issue on a 32-bit Raspberry Pi
system.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/_helpers.c

index 330187cb82c6dabb291c00a727bcfc9d54194f87..6fe8d6abc735d49ec625bc52d207c1ea4cf91b9a 100644 (file)
@@ -620,14 +620,14 @@ static PyObject *bitmatch(PyObject *self, PyObject *args)
        }
     }
     
-    unsigned long long result;
+    Py_ssize_t result;
     if (!INT_MULTIPLY_OK(byte, 8, &result)
         || !INT_ADD_OK(result, bit, &result))
     {
         PyErr_Format(PyExc_OverflowError, "bitmatch bit count too large");
         return NULL;
     }
-    return PyLong_FromUnsignedLongLong(result);
+    return PyLong_FromSsize_t(result);
 }