Skip to content

Commit 3f687f7

Browse files
authored
PYTHON-3443 Remove redundant code to avoid Coverity warnings (#1228)
1 parent 0bce579 commit 3f687f7

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

bson/_cbsonmodule.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,19 +304,15 @@ static int millis_from_datetime_ms(PyObject* dt, long long* out){
304304
long long millis;
305305

306306
if (!(ll_millis = PyNumber_Long(dt))){
307-
if (PyErr_Occurred()) { // TypeError
308-
return 0;
309-
}
310-
}
311-
312-
if ((millis = PyLong_AsLongLong(ll_millis)) == -1){
313-
if (PyErr_Occurred()) { /* Overflow */
314-
PyErr_SetString(PyExc_OverflowError,
315-
"MongoDB datetimes can only handle up to 8-byte ints");
316-
return 0;
317-
}
307+
return 0;
318308
}
309+
millis = PyLong_AsLongLong(ll_millis);
319310
Py_DECREF(ll_millis);
311+
if (millis == -1 && PyErr_Occurred()) { /* Overflow */
312+
PyErr_SetString(PyExc_OverflowError,
313+
"MongoDB datetimes can only handle up to 8-byte ints");
314+
return 0;
315+
}
320316
*out = millis;
321317
return 1;
322318
}
@@ -2081,7 +2077,7 @@ static PyObject* get_value(PyObject* self, PyObject* name, const char* buffer,
20812077
millis = max_millis;
20822078
}
20832079
// Continues from here to return a datetime.
2084-
} else if (dt_auto) {
2080+
} else { // dt_auto
20852081
if (millis < min_millis || millis > max_millis){
20862082
value = datetime_ms_from_millis(self, millis);
20872083
break; // Out-of-range so done.

0 commit comments

Comments
 (0)