From d97c589606814896b75341226d85f14487af3c03 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Mon, 12 Feb 2024 23:06:06 +0200 Subject: [PATCH 1/2] Fix compiler warning --- Objects/longobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/longobject.c b/Objects/longobject.c index 932111f58425f2..0ceca8e1097889 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -1335,7 +1335,7 @@ PyLong_FromLongLong(long long ival) /* Count digits (at least two - smaller cases were handled above). */ abs_ival = ival < 0 ? 0U-(unsigned long long)ival : (unsigned long long)ival; /* Do shift in two steps to avoid possible undefined behavior. */ - t = abs_ival >> PyLong_SHIFT >> PyLong_SHIFT; + t = (Py_ssize_t)(abs_ival >> PyLong_SHIFT >> PyLong_SHIFT); ndigits = 2; while (t) { ++ndigits; From a8491cb44ab63ab00639b97830d5bfc267860413 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Mon, 12 Feb 2024 23:12:59 +0200 Subject: [PATCH 2/2] Another try to fix warning --- Objects/longobject.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Objects/longobject.c b/Objects/longobject.c index 0ceca8e1097889..fe782983334323 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -1135,7 +1135,7 @@ PyLong_AsNativeBytes(PyObject* vv, void* buffer, Py_ssize_t n, int endianness) if (n <= 0) { // nothing to do! } - else if (n <= sizeof(cv.b)) { + else if (n <= (Py_ssize_t)sizeof(cv.b)) { #if PY_LITTLE_ENDIAN if (little_endian) { memcpy(buffer, cv.b, n); @@ -1335,7 +1335,7 @@ PyLong_FromLongLong(long long ival) /* Count digits (at least two - smaller cases were handled above). */ abs_ival = ival < 0 ? 0U-(unsigned long long)ival : (unsigned long long)ival; /* Do shift in two steps to avoid possible undefined behavior. */ - t = (Py_ssize_t)(abs_ival >> PyLong_SHIFT >> PyLong_SHIFT); + t = abs_ival >> PyLong_SHIFT >> PyLong_SHIFT; ndigits = 2; while (t) { ++ndigits;