Skip to content

Fix or remove dead assignments identified by scan-build #16267

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

Closed
wants to merge 1 commit into from

Conversation

alexhenrie
Copy link
Contributor

scan-build identified several variable assignments that are overwritten before they can be used. To make the code easier to understand and to ensure that it is fully optimized, let's fix or get rid of these dead assignments.

@@ -2489,7 +2489,6 @@ delta_new(PyTypeObject *type, PyObject *args, PyObject *kw)
int x_is_odd;
PyObject *temp;

whole_us = round(leftover_us);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anyone else reading, the way this diff is displayed is a bit misleading - line 2488 is not shown, but the same value is assigned when whole_us is declared, then overwritten here.

An alternative would be to delete 2488 and change this into a declaration, or to keep the declaration and assignment lines separate, but I'm indifferent between the three.

@@ -680,7 +680,6 @@ pyinit_config(_PyRuntimeState *runtime,
if (_PyStatus_EXCEPTION(status)) {
return status;
}
config = &tstate->interp->config;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this one I'm having trouble understanding how it happened and if it was actually intended to have some effect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is correct. I wrote the config, but it's no longer needed to update the config variable.

@@ -1639,7 +1639,6 @@ idna_converter(PyObject *obj, struct maybe_idna *data)
return 1;
}
data->obj = NULL;
len = -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dead code now, but len gets set in a bunch of different conditional branches. I am mildly worried that something might change in the future where someone forgets to set len in one of those branches and we end up using uninitialized memory.

Doesn't look terribly dangerous, but maybe it would make sense to leave it as len = -1 and then add assert(len >= 0) directly before len is used?

@@ -221,8 +221,9 @@ _sharedexception_bind(PyObject *exctype, PyObject *exc, PyObject *tb)
if (err->name == NULL) {
if (PyErr_ExceptionMatches(PyExc_MemoryError)) {
failure = "out of memory copying exception type name";
} else {
failure = "unable to encode and copy exception type name";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be an actual bugfix.

Copy link
Contributor

@eamanu eamanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm interest PR. Seems to be good. But I can make a depth review

@csabella
Copy link
Contributor

csabella commented Jan 5, 2020

@alexhenrie, please open a ticket on the bug tracker for this issue and update the title to include the ticket number. Thank you!

@alexhenrie
Copy link
Contributor Author

This patch cleans up various totally unrelated functions, so it'd probably be best to split it up and open a bug report for each function that needs changes.

@@ -265,7 +265,7 @@ config_init_module_search_paths(PyConfig *config, _PyPathConfig *pathconfig)

const wchar_t *sys_path = pathconfig->module_search_path;
const wchar_t delim = DELIM;
const wchar_t *p = sys_path;
const wchar_t *p;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind to move the variable declaration inside the loop to even show better its scope?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants