From 8c35a44b37decd551ecba406bec210807290ba6b Mon Sep 17 00:00:00 2001 From: joncrall Date: Mon, 4 Apr 2022 22:12:59 -0400 Subject: [PATCH] Fix compiler warnings --- lib/ultrajsonenc.c | 2 ++ python/objToJSON.c | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/ultrajsonenc.c b/lib/ultrajsonenc.c index e3389c6e..2fd19fac 100644 --- a/lib/ultrajsonenc.c +++ b/lib/ultrajsonenc.c @@ -551,6 +551,7 @@ static void Buffer_AppendIndentUnchecked(JSONObjectEncoder *enc, JSINT32 value) { int i; if (enc->indent > 0) + { if (enc->indent_chars == NULL) { while (value-- > 0) @@ -563,6 +564,7 @@ static void Buffer_AppendIndentUnchecked(JSONObjectEncoder *enc, JSINT32 value) for (i = 0; i < enc->indent; i++) Buffer_AppendCharUnchecked(enc, enc->indent_chars[i]); } + } } static void Buffer_AppendLongUnchecked(JSONObjectEncoder *enc, JSINT64 value) diff --git a/python/objToJSON.c b/python/objToJSON.c index bd17de3b..ca9266c4 100644 --- a/python/objToJSON.c +++ b/python/objToJSON.c @@ -122,7 +122,7 @@ static void *PyUnicodeToUTF8(JSOBJ _obj, JSONTypeContext *tc, void *outValue, si if (PyUnicode_IS_COMPACT_ASCII(obj)) { Py_ssize_t len; - char *data = PyUnicode_AsUTF8AndSize(obj, &len); + const char *data = PyUnicode_AsUTF8AndSize(obj, &len); *_outLen = len; return data; } @@ -747,7 +747,7 @@ static char *Object_iterGetName(JSOBJ obj, JSONTypeContext *tc, size_t *outLen) } -static void *_PyUnicodeToChars(PyObject *obj, size_t *_outLen) +static const char *_PyUnicodeToChars(PyObject *obj, size_t *_outLen) { // helper for indent only PyObject *newObj; @@ -755,7 +755,7 @@ static void *_PyUnicodeToChars(PyObject *obj, size_t *_outLen) if (PyUnicode_IS_COMPACT_ASCII(obj)) { Py_ssize_t len; - char *data = PyUnicode_AsUTF8AndSize(obj, &len); + const char *data = PyUnicode_AsUTF8AndSize(obj, &len); *_outLen = len; return data; } @@ -859,7 +859,9 @@ PyObject* objToJSON(PyObject* self, PyObject *args, PyObject *kwargs) else if (PyUnicode_Check(oindent)) { // set a custom indent string - encoder.indent_chars = _PyUnicodeToChars(oindent, &encoder.indent); + size_t olen = 0; + encoder.indent_chars = _PyUnicodeToChars(oindent, &olen); + encoder.indent = (int) olen; if(encoder.indent_chars == NULL) { PyErr_SetString(PyExc_ValueError, "indent was malformed");