From 13681d5a0f43ac0c0a86166a7d86bdf25e8a19a8 Mon Sep 17 00:00:00 2001 From: John Paul Adrian Glaubitz Date: Thu, 6 Jun 2024 10:34:02 +0200 Subject: [PATCH] Fixed a number of compiler warnings (#239) * Fixed incorrect format specifiers when calling sprintf() * Fixed potentially uninitialized variable * Removed unused variables --- docs/versionhistory.rst | 1 + source/decoder.c | 7 ++++--- source/encoder.c | 4 +--- 3 files changed, 6 insertions(+), 6 deletions(-) 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) 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); diff --git a/source/encoder.c b/source/encoder.c index f612e5d..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), @@ -1120,7 +1118,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;