From: Rob Browning Date: Sat, 30 Oct 2021 18:23:45 +0000 (-0500) Subject: bitmatch: avoid signed/unsigned comparison X-Git-Url: https://arthur.barton.de/gitweb/?p=bup.git;a=commitdiff_plain;h=7e054ad95acda596469c40159867f936c1a8f851 bitmatch: avoid signed/unsigned comparison 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 Tested-by: Rob Browning --- diff --git a/lib/bup/_helpers.c b/lib/bup/_helpers.c index 330187c..6fe8d6a 100644 --- a/lib/bup/_helpers.c +++ b/lib/bup/_helpers.c @@ -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); }