Skip to content

Commit 13681d5

Browse files
authored
Fixed a number of compiler warnings (#239)
* Fixed incorrect format specifiers when calling sprintf() * Fixed potentially uninitialized variable * Removed unused variables
1 parent 573d520 commit 13681d5

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

docs/versionhistory.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This library adheres to `Semantic Versioning <http://semver.org/>`_.
88
**UNRELEASED**
99

1010
- Fixed compilation of C extension failing on GCC 14
11+
- Fixed compiler warnings when building C extension
1112

1213
**5.6.3** (2024-04-11)
1314

source/decoder.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#define PY_SSIZE_T_CLEAN
22
#include <Python.h>
33
#include <datetime.h>
4+
#include <inttypes.h>
45
#include <string.h>
56
#include <stdbool.h>
67
#include <limits.h>
@@ -694,7 +695,7 @@ decode_bytestring(CBORDecoderObject *self, uint8_t subtype)
694695
return NULL;
695696

696697
if (length > (uint64_t)PY_SSIZE_T_MAX - (uint64_t)PyBytesObject_SIZE) {
697-
sprintf(length_hex, "%llX", length);
698+
sprintf(length_hex, "%" PRIX64, length);
698699
PyErr_Format(
699700
_CBOR2_CBORDecodeValueError,
700701
"excessive bytestring size 0x%s", length_hex);
@@ -894,7 +895,7 @@ decode_string(CBORDecoderObject *self, uint8_t subtype)
894895
if (decode_length(self, subtype, &length, &indefinite) == -1)
895896
return NULL;
896897
if (length > (uint64_t)PY_SSIZE_T_MAX - (uint64_t)PyBytesObject_SIZE) {
897-
sprintf(length_hex, "%llX", length);
898+
sprintf(length_hex, "%" PRIX64, length);
898899
PyErr_Format(
899900
_CBOR2_CBORDecodeValueError,
900901
"excessive string size 0x%s", length_hex);
@@ -1057,7 +1058,7 @@ decode_array(CBORDecoderObject *self, uint8_t subtype)
10571058
if (indefinite)
10581059
return decode_indefinite_array(self);
10591060
if (length > (uint64_t)PY_SSIZE_T_MAX) {
1060-
sprintf(length_hex, "%llX", length);
1061+
sprintf(length_hex, "%" PRIX64, length);
10611062
PyErr_Format(
10621063
_CBOR2_CBORDecodeValueError,
10631064
"excessive array size 0x%s", length_hex);

source/encoder.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,8 +1040,6 @@ CBOREncoder_encode_date(CBOREncoderObject *self, PyObject *value)
10401040
// semantic type 100 or 1004
10411041

10421042
PyObject *tmp, *ret = NULL;
1043-
const char *buf;
1044-
Py_ssize_t length;
10451043
if (self->date_as_datetime) {
10461044
tmp = PyDateTimeAPI->DateTime_FromDateAndTime(
10471045
PyDateTime_GET_YEAR(value),
@@ -1120,7 +1118,7 @@ decimal_negative(PyObject *value)
11201118
static PyObject *
11211119
encode_decimal_digits(CBOREncoderObject *self, PyObject *value)
11221120
{
1123-
PyObject *tuple, *digits, *exp, *sig, *ten, *tmp, *ret = NULL;
1121+
PyObject *tuple, *digits, *exp, *sig, *ten, *tmp = NULL, *ret = NULL;
11241122
int sign = 0;
11251123
bool sharing;
11261124

0 commit comments

Comments
 (0)