Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PYTHON-3959 - NULL Initialize PyObjects #1859

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions bson/_cbsonmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1790,7 +1790,7 @@ static PyObject* _cbson_dict_to_bson(PyObject* self, PyObject* args) {
PyObject* result;
aclark4life marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 17 additions & 17 deletions pymongo/_cmessagemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading