Skip to content

Commit

Permalink
Fixed a number of compiler warnings (#239)
Browse files Browse the repository at this point in the history
* Fixed incorrect format specifiers when calling sprintf()
* Fixed potentially uninitialized variable
* Removed unused variables
  • Loading branch information
glaubitz authored Jun 6, 2024
1 parent 573d520 commit 13681d5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This library adheres to `Semantic Versioning <http://semver.org/>`_.
**UNRELEASED**

- Fixed compilation of C extension failing on GCC 14
- Fixed compiler warnings when building C extension

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

Expand Down
7 changes: 4 additions & 3 deletions source/decoder.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <datetime.h>
#include <inttypes.h>
#include <string.h>
#include <stdbool.h>
#include <limits.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions source/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 13681d5

Please sign in to comment.