From 5142b3d1b1929104103a14c1d7e148b8b8bb7896 Mon Sep 17 00:00:00 2001 From: Thomas Kowalski Date: Sat, 18 Apr 2026 16:25:26 -0400 Subject: [PATCH 1/4] fix: check return code in unpack_callback_int64 --- msgpack/unpack.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/msgpack/unpack.h b/msgpack/unpack.h index 58a2f4f5..a6750f88 100644 --- a/msgpack/unpack.h +++ b/msgpack/unpack.h @@ -109,6 +109,8 @@ static inline int unpack_callback_int64(unpack_user* u, int64_t d, msgpack_unpac } else { p = PyLong_FromLong((long)d); } + if (!p) + return -1; *o = p; return 0; } From a85e02d6a69d51a070fb854ae399ae41f2480ae4 Mon Sep 17 00:00:00 2001 From: Thomas Kowalski Date: Mon, 20 Apr 2026 20:08:29 +0200 Subject: [PATCH 2/4] refactor: remove LONG_MAX check --- msgpack/unpack.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/msgpack/unpack.h b/msgpack/unpack.h index a6750f88..7fc14bdd 100644 --- a/msgpack/unpack.h +++ b/msgpack/unpack.h @@ -70,12 +70,7 @@ static inline int unpack_callback_uint32(unpack_user* u, uint32_t d, msgpack_unp static inline int unpack_callback_uint64(unpack_user* u, uint64_t d, msgpack_unpack_object* o) { - PyObject *p; - if (d > LONG_MAX) { - p = PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)d); - } else { - p = PyLong_FromLong((long)d); - } + PyObject *p = PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)d); if (!p) return -1; *o = p; From 1e28db75ba428caf2b391a889d0955d604914444 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 21 Apr 2026 18:08:06 +0900 Subject: [PATCH 3/4] Apply suggestion from @methane --- msgpack/unpack.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msgpack/unpack.h b/msgpack/unpack.h index 7fc14bdd..e7121cae 100644 --- a/msgpack/unpack.h +++ b/msgpack/unpack.h @@ -103,7 +103,7 @@ static inline int unpack_callback_int64(unpack_user* u, int64_t d, msgpack_unpac p = PyLong_FromLongLong((PY_LONG_LONG)d); } else { p = PyLong_FromLong((long)d); - } + PyObject *p = PyLong_FromLongLong((PY_LONG_LONG)d); if (!p) return -1; *o = p; From 77f5a5383435007bfb94f3a7579fc6282ed46ebe Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 21 Apr 2026 18:09:04 +0900 Subject: [PATCH 4/4] Simplify PyObject creation in unpack_callback_int64 Refactor unpack_callback_int64 to simplify PyObject creation. --- msgpack/unpack.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/msgpack/unpack.h b/msgpack/unpack.h index e7121cae..0f9ffc05 100644 --- a/msgpack/unpack.h +++ b/msgpack/unpack.h @@ -98,11 +98,6 @@ static inline int unpack_callback_int8(unpack_user* u, int8_t d, msgpack_unpack_ static inline int unpack_callback_int64(unpack_user* u, int64_t d, msgpack_unpack_object* o) { - PyObject *p; - if (d > LONG_MAX || d < LONG_MIN) { - p = PyLong_FromLongLong((PY_LONG_LONG)d); - } else { - p = PyLong_FromLong((long)d); PyObject *p = PyLong_FromLongLong((PY_LONG_LONG)d); if (!p) return -1;