From 2fe8d7cf692e125b3805c088f803a92f11bb2be5 Mon Sep 17 00:00:00 2001 From: Bernie Hackett Date: Mon, 27 Feb 2017 12:13:29 -0800 Subject: [PATCH] PYTHON-1244 - Fix signed/unsigned comparison --- bson/_cbsonmodule.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bson/_cbsonmodule.c b/bson/_cbsonmodule.c index eaabc7f77..31d1f4918 100644 --- a/bson/_cbsonmodule.c +++ b/bson/_cbsonmodule.c @@ -2666,7 +2666,7 @@ static PyObject* _cbson_element_to_dict(PyObject* self, PyObject* args) { static PyObject* _elements_to_dict(PyObject* self, const char* string, unsigned max, const codec_options_t* options) { - int position = 0; + unsigned position = 0; PyObject* dict = PyObject_CallObject(options->document_class, NULL); if (!dict) { return NULL; @@ -2674,12 +2674,15 @@ static PyObject* _elements_to_dict(PyObject* self, const char* string, while (position < max) { PyObject* name; PyObject* value; + int new_position; - position = _element_to_dict(self, string, position, max, - options, &name, &value); - if (position < 0) { + new_position = _element_to_dict( + self, string, position, max, options, &name, &value); + if (new_position < 0) { Py_DECREF(dict); return NULL; + } else { + position = (unsigned)new_position; } PyObject_SetItem(dict, name, value);