Skip to content

Commit 3504130

Browse files
authored
PYTHON-4663 Fix coverity warnings in datetime decoding change (#1835)
1 parent 2742a00 commit 3504130

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

bson/_cbsonmodule.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,11 @@ static int millis_from_datetime_ms(PyObject* dt, long long* out){
383383
static PyObject* decode_datetime(PyObject* self, long long millis, const codec_options_t* options){
384384
PyObject* naive = NULL;
385385
PyObject* replace = NULL;
386-
PyObject* args = NULL;
387-
PyObject* kwargs = NULL;
388386
PyObject* value = NULL;
389387
struct module_state *state = GETSTATE(self);
388+
if (!state) {
389+
goto invalid;
390+
}
390391
if (options->datetime_conversion == DATETIME_MS){
391392
return datetime_ms_from_millis(self, millis);
392393
}
@@ -414,8 +415,8 @@ static PyObject* decode_datetime(PyObject* self, long long millis, const codec_o
414415
Py_DECREF(utcoffset);
415416
return 0;
416417
}
417-
min_millis_offset = (PyDateTime_DELTA_GET_DAYS(utcoffset) * 86400 +
418-
PyDateTime_DELTA_GET_SECONDS(utcoffset)) * 1000 +
418+
min_millis_offset = (PyDateTime_DELTA_GET_DAYS(utcoffset) * (int64_t)86400 +
419+
PyDateTime_DELTA_GET_SECONDS(utcoffset)) * (int64_t)1000 +
419420
(PyDateTime_DELTA_GET_MICROSECONDS(utcoffset) / 1000);
420421
}
421422
Py_DECREF(utcoffset);
@@ -433,8 +434,8 @@ static PyObject* decode_datetime(PyObject* self, long long millis, const codec_o
433434
Py_DECREF(utcoffset);
434435
return 0;
435436
}
436-
max_millis_offset = (PyDateTime_DELTA_GET_DAYS(utcoffset) * 86400 +
437-
PyDateTime_DELTA_GET_SECONDS(utcoffset)) * 1000 +
437+
max_millis_offset = (PyDateTime_DELTA_GET_DAYS(utcoffset) * (int64_t)86400 +
438+
PyDateTime_DELTA_GET_SECONDS(utcoffset)) * (int64_t)1000 +
438439
(PyDateTime_DELTA_GET_MICROSECONDS(utcoffset) / 1000);
439440
}
440441
Py_DECREF(utcoffset);
@@ -487,8 +488,6 @@ static PyObject* decode_datetime(PyObject* self, long long millis, const codec_o
487488
invalid:
488489
Py_XDECREF(naive);
489490
Py_XDECREF(replace);
490-
Py_XDECREF(args);
491-
Py_XDECREF(kwargs);
492491
return value;
493492
}
494493

0 commit comments

Comments
 (0)