Silence various complaints from Coverity
This commit is contained in:
parent
96b6f8d0d4
commit
de801be529
@ -99,7 +99,7 @@ static PyObject* _error(char* name) {
|
||||
/* Safely downcast from Py_ssize_t to int, setting an
|
||||
* exception and returning -1 on error. */
|
||||
static int
|
||||
_downcast_and_check(Py_ssize_t size, int extra) {
|
||||
_downcast_and_check(Py_ssize_t size, uint8_t extra) {
|
||||
if (size > BSON_MAX_SIZE || ((BSON_MAX_SIZE - extra) < size)) {
|
||||
PyObject* InvalidStringData = _error("InvalidStringData");
|
||||
if (InvalidStringData) {
|
||||
@ -384,6 +384,7 @@ static int _load_python_objects(PyObject* module) {
|
||||
}
|
||||
|
||||
compiled = PyObject_CallFunction(re_compile, "O", empty_string);
|
||||
Py_DECREF(re_compile);
|
||||
if (compiled == NULL) {
|
||||
state->REType = NULL;
|
||||
Py_DECREF(empty_string);
|
||||
@ -478,10 +479,14 @@ int convert_codec_options(PyObject* options_obj, void* p) {
|
||||
* Return 0 on failure.
|
||||
*/
|
||||
int default_codec_options(struct module_state* state, codec_options_t* options) {
|
||||
PyObject* options_obj = NULL;
|
||||
PyObject* codec_options_func = _get_object(
|
||||
state->CodecOptions, "bson.codec_options", "CodecOptions");
|
||||
PyObject* options_obj = PyObject_CallFunctionObjArgs(
|
||||
codec_options_func, NULL);
|
||||
if (codec_options_func == NULL) {
|
||||
return 0;
|
||||
}
|
||||
options_obj = PyObject_CallFunctionObjArgs(codec_options_func, NULL);
|
||||
Py_DECREF(codec_options_func);
|
||||
if (options_obj == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -72,8 +72,8 @@ static int add_last_error(PyObject* self, buffer_t buffer,
|
||||
int document_start;
|
||||
int message_length;
|
||||
int document_length;
|
||||
PyObject* key;
|
||||
PyObject* value;
|
||||
PyObject* key = NULL;
|
||||
PyObject* value = NULL;
|
||||
Py_ssize_t pos = 0;
|
||||
PyObject* one;
|
||||
char *p = strchr(ns, '.');
|
||||
@ -1290,9 +1290,9 @@ PyMODINIT_FUNC
|
||||
init_cmessage(void)
|
||||
#endif
|
||||
{
|
||||
PyObject *_cbson;
|
||||
PyObject *c_api_object;
|
||||
PyObject *m;
|
||||
PyObject *_cbson = NULL;
|
||||
PyObject *c_api_object = NULL;
|
||||
PyObject *m = NULL;
|
||||
struct module_state *state;
|
||||
|
||||
/* Store a reference to the _cbson module since it's needed to call some
|
||||
@ -1300,7 +1300,7 @@ init_cmessage(void)
|
||||
*/
|
||||
_cbson = PyImport_ImportModule("bson._cbson");
|
||||
if (_cbson == NULL) {
|
||||
INITERROR;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Import C API of _cbson
|
||||
@ -1308,8 +1308,7 @@ init_cmessage(void)
|
||||
*/
|
||||
c_api_object = PyObject_GetAttrString(_cbson, "_C_API");
|
||||
if (c_api_object == NULL) {
|
||||
Py_DECREF(_cbson);
|
||||
INITERROR;
|
||||
goto fail;
|
||||
}
|
||||
#if PY_VERSION_HEX >= 0x03010000
|
||||
_cbson_API = (void **)PyCapsule_GetPointer(c_api_object, "_cbson._C_API");
|
||||
@ -1317,28 +1316,39 @@ init_cmessage(void)
|
||||
_cbson_API = (void **)PyCObject_AsVoidPtr(c_api_object);
|
||||
#endif
|
||||
if (_cbson_API == NULL) {
|
||||
Py_DECREF(c_api_object);
|
||||
Py_DECREF(_cbson);
|
||||
INITERROR;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
/* Returns a new reference. */
|
||||
m = PyModule_Create(&moduledef);
|
||||
#else
|
||||
/* Returns a borrowed reference. */
|
||||
m = Py_InitModule("_cmessage", _CMessageMethods);
|
||||
#endif
|
||||
if (m == NULL) {
|
||||
Py_DECREF(c_api_object);
|
||||
Py_DECREF(_cbson);
|
||||
INITERROR;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
state = GETSTATE(m);
|
||||
if (state == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
state->_cbson = _cbson;
|
||||
|
||||
Py_DECREF(c_api_object);
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
|
||||
fail:
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
Py_XDECREF(m);
|
||||
#endif
|
||||
Py_XDECREF(c_api_object);
|
||||
Py_XDECREF(_cbson);
|
||||
INITERROR;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user