From 0ac6282f0b6a14beda79c9210635c693582c38b3 Mon Sep 17 00:00:00 2001 From: John Paul Adrian Glaubitz Date: Wed, 5 Jun 2024 17:53:16 +0200 Subject: [PATCH 1/4] Fix incorrect format specifiers when calling sprintf() --- source/decoder.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/decoder.c b/source/decoder.c index bd7fa47..fd4d70c 100644 --- a/source/decoder.c +++ b/source/decoder.c @@ -1,6 +1,7 @@ #define PY_SSIZE_T_CLEAN #include #include +#include #include #include #include @@ -694,7 +695,7 @@ decode_bytestring(CBORDecoderObject *self, uint8_t subtype) return NULL; if (length > (uint64_t)PY_SSIZE_T_MAX - (uint64_t)PyBytesObject_SIZE) { - sprintf(length_hex, "%llX", length); + sprintf(length_hex, "%" PRIX64, length); PyErr_Format( _CBOR2_CBORDecodeValueError, "excessive bytestring size 0x%s", length_hex); @@ -894,7 +895,7 @@ decode_string(CBORDecoderObject *self, uint8_t subtype) if (decode_length(self, subtype, &length, &indefinite) == -1) return NULL; if (length > (uint64_t)PY_SSIZE_T_MAX - (uint64_t)PyBytesObject_SIZE) { - sprintf(length_hex, "%llX", length); + sprintf(length_hex, "%" PRIX64, length); PyErr_Format( _CBOR2_CBORDecodeValueError, "excessive string size 0x%s", length_hex); @@ -1057,7 +1058,7 @@ decode_array(CBORDecoderObject *self, uint8_t subtype) if (indefinite) return decode_indefinite_array(self); if (length > (uint64_t)PY_SSIZE_T_MAX) { - sprintf(length_hex, "%llX", length); + sprintf(length_hex, "%" PRIX64, length); PyErr_Format( _CBOR2_CBORDecodeValueError, "excessive array size 0x%s", length_hex); From a8cf73016f0b6eec0e61c430b1212af1bb7521fe Mon Sep 17 00:00:00 2001 From: John Paul Adrian Glaubitz Date: Wed, 5 Jun 2024 18:04:56 +0200 Subject: [PATCH 2/4] Fix potentially uninitialized variable --- source/encoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/encoder.c b/source/encoder.c index f612e5d..68c5730 100644 --- a/source/encoder.c +++ b/source/encoder.c @@ -1120,7 +1120,7 @@ decimal_negative(PyObject *value) static PyObject * encode_decimal_digits(CBOREncoderObject *self, PyObject *value) { - PyObject *tuple, *digits, *exp, *sig, *ten, *tmp, *ret = NULL; + PyObject *tuple, *digits, *exp, *sig, *ten, *tmp = NULL, *ret = NULL; int sign = 0; bool sharing; From c66da6bab83a93f1faefcdd255d27ac7afc8ce99 Mon Sep 17 00:00:00 2001 From: John Paul Adrian Glaubitz Date: Wed, 5 Jun 2024 18:11:50 +0200 Subject: [PATCH 3/4] Remove unused variables --- source/encoder.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/encoder.c b/source/encoder.c index 68c5730..a0670aa 100644 --- a/source/encoder.c +++ b/source/encoder.c @@ -1040,8 +1040,6 @@ CBOREncoder_encode_date(CBOREncoderObject *self, PyObject *value) // semantic type 100 or 1004 PyObject *tmp, *ret = NULL; - const char *buf; - Py_ssize_t length; if (self->date_as_datetime) { tmp = PyDateTimeAPI->DateTime_FromDateAndTime( PyDateTime_GET_YEAR(value), From db836741c14c434926d7f1216fce0532b6c1ecd8 Mon Sep 17 00:00:00 2001 From: John Paul Adrian Glaubitz Date: Thu, 6 Jun 2024 10:20:32 +0200 Subject: [PATCH 4/4] Add changelog entry for compiler warning fixes --- docs/versionhistory.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst index 89c53e7..60439aa 100644 --- a/docs/versionhistory.rst +++ b/docs/versionhistory.rst @@ -8,6 +8,7 @@ This library adheres to `Semantic Versioning `_. **UNRELEASED** - Fixed compilation of C extension failing on GCC 14 +- Fixed compiler warnings when building C extension **5.6.3** (2024-04-11)