PYTHON-3959 - NULL Initialize PyObjects (#1859)

This commit is contained in:
Jeffrey A. Clark 2024-10-03 13:39:04 -04:00 committed by GitHub
parent af23139b4a
commit 7380097dbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 29 deletions

View File

@ -207,7 +207,7 @@ static PyObject* _test_long_long_to_str(PyObject* self, PyObject* args) {
*
* Returns a new ref */
static PyObject* _error(char* name) {
PyObject* error;
PyObject* error = NULL;
PyObject* errors = PyImport_ImportModule("bson.errors");
if (!errors) {
return NULL;
@ -279,7 +279,7 @@ static PyObject* datetime_from_millis(long long millis) {
* micros = diff * 1000 111000
* Resulting in datetime(1, 1, 1, 1, 1, 1, 111000) -- the expected result
*/
PyObject* datetime;
PyObject* datetime = NULL;
int diff = (int)(((millis % 1000) + 1000) % 1000);
int microseconds = diff * 1000;
Time64_T seconds = (millis - diff) / 1000;
@ -294,7 +294,7 @@ static PyObject* datetime_from_millis(long long millis) {
timeinfo.tm_sec,
microseconds);
if(!datetime) {
PyObject *etype, *evalue, *etrace;
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL;
/*
* Calling _error clears the error state, so fetch it first.
@ -350,8 +350,8 @@ static PyObject* datetime_ms_from_millis(PyObject* self, long long millis){
return NULL;
}
PyObject* dt;
PyObject* ll_millis;
PyObject* dt = NULL;
PyObject* ll_millis = NULL;
if (!(ll_millis = PyLong_FromLongLong(millis))){
return NULL;
@ -1790,7 +1790,7 @@ static PyObject* _cbson_dict_to_bson(PyObject* self, PyObject* args) {
PyObject* result;
unsigned char check_keys;
unsigned char top_level = 1;
PyObject* options_obj;
PyObject* options_obj = NULL;
codec_options_t options;
buffer_t buffer;
PyObject* raw_bson_document_bytes_obj;
@ -2512,8 +2512,8 @@ static PyObject* get_value(PyObject* self, PyObject* name, const char* buffer,
* Wrap any non-InvalidBSON errors in InvalidBSON.
*/
if (PyErr_Occurred()) {
PyObject *etype, *evalue, *etrace;
PyObject *InvalidBSON;
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL;
PyObject *InvalidBSON = NULL;
/*
* Calling _error clears the error state, so fetch it first.
@ -2585,8 +2585,8 @@ static int _element_to_dict(PyObject* self, const char* string,
if (!*name) {
/* If NULL is returned then wrap the UnicodeDecodeError
in an InvalidBSON error */
PyObject *etype, *evalue, *etrace;
PyObject *InvalidBSON;
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL;
PyObject *InvalidBSON = NULL;
PyErr_Fetch(&etype, &evalue, &etrace);
if (PyErr_GivenExceptionMatches(etype, PyExc_Exception)) {
@ -2620,7 +2620,7 @@ static PyObject* _cbson_element_to_dict(PyObject* self, PyObject* args) {
/* TODO: Support buffer protocol */
char* string;
PyObject* bson;
PyObject* options_obj;
PyObject* options_obj = NULL;
codec_options_t options;
unsigned position;
unsigned max;
@ -2732,7 +2732,7 @@ static PyObject* _cbson_bson_to_dict(PyObject* self, PyObject* args) {
int32_t size;
Py_ssize_t total_size;
const char* string;
PyObject* bson;
PyObject* bson = NULL;
codec_options_t options;
PyObject* result = NULL;
PyObject* options_obj;

View File

@ -45,7 +45,7 @@ struct module_state {
*
* Returns a new ref */
static PyObject* _error(char* name) {
PyObject* error;
PyObject* error = NULL;
PyObject* errors = PyImport_ImportModule("pymongo.errors");
if (!errors) {
return NULL;
@ -75,9 +75,9 @@ static PyObject* _cbson_query_message(PyObject* self, PyObject* args) {
int begin, cur_size, max_size = 0;
int num_to_skip;
int num_to_return;
PyObject* query;
PyObject* field_selector;
PyObject* options_obj;
PyObject* query = NULL;
PyObject* field_selector = NULL;
PyObject* options_obj = NULL;
codec_options_t options;
buffer_t buffer = NULL;
int length_location, message_length;
@ -221,12 +221,12 @@ static PyObject* _cbson_op_msg(PyObject* self, PyObject* args) {
/* NOTE just using a random number as the request_id */
int request_id = rand();
unsigned int flags;
PyObject* command;
PyObject* command = NULL;
char* identifier = NULL;
Py_ssize_t identifier_length = 0;
PyObject* docs;
PyObject* doc;
PyObject* options_obj;
PyObject* docs = NULL;
PyObject* doc = NULL;
PyObject* options_obj = NULL;
codec_options_t options;
buffer_t buffer = NULL;
int length_location, message_length;
@ -535,12 +535,12 @@ static PyObject*
_cbson_encode_batched_op_msg(PyObject* self, PyObject* args) {
unsigned char op;
unsigned char ack;
PyObject* command;
PyObject* docs;
PyObject* command = NULL;
PyObject* docs = NULL;
PyObject* ctx = NULL;
PyObject* to_publish = NULL;
PyObject* result = NULL;
PyObject* options_obj;
PyObject* options_obj = NULL;
codec_options_t options;
buffer_t buffer;
struct module_state *state = GETSTATE(self);
@ -592,12 +592,12 @@ _cbson_batched_op_msg(PyObject* self, PyObject* args) {
unsigned char ack;
int request_id;
int position;
PyObject* command;
PyObject* docs;
PyObject* command = NULL;
PyObject* docs = NULL;
PyObject* ctx = NULL;
PyObject* to_publish = NULL;
PyObject* result = NULL;
PyObject* options_obj;
PyObject* options_obj = NULL;
codec_options_t options;
buffer_t buffer;
struct module_state *state = GETSTATE(self);
@ -868,12 +868,12 @@ _cbson_encode_batched_write_command(PyObject* self, PyObject* args) {
char *ns = NULL;
unsigned char op;
Py_ssize_t ns_len;
PyObject* command;
PyObject* docs;
PyObject* command = NULL;
PyObject* docs = NULL;
PyObject* ctx = NULL;
PyObject* to_publish = NULL;
PyObject* result = NULL;
PyObject* options_obj;
PyObject* options_obj = NULL;
codec_options_t options;
buffer_t buffer;
struct module_state *state = GETSTATE(self);