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
Closed
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
1 change: 0 additions & 1 deletion Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.

if (fabs(whole_us - leftover_us) == 0.5) {
/* We're exactly halfway between two integers. In order
* to do round-half-to-even, we must determine whether x
Expand Down
1 change: 0 additions & 1 deletion Modules/_sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,6 @@ pattern_subx(PatternObject* self, PyObject* ptemplate, PyObject* string,
int literal;
view.buf = NULL;
ptr = getstring(ptemplate, &n, &isbytes, &charsize, &view);
b = charsize;
if (ptr) {
if (charsize == 1)
literal = memchr(ptr, '\\', n) == NULL;
Expand Down
1 change: 0 additions & 1 deletion Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4176,7 +4176,6 @@ _ssl__SSLContext_load_verify_locations_impl(PySSLContext *self,
r = SSL_CTX_load_verify_locations(self->ctx, cafile_buf, capath_buf);
PySSL_END_ALLOW_THREADS
if (r != 1) {
ok = 0;
if (errno != 0) {
ERR_clear_error();
PyErr_SetFromErrno(PyExc_OSError);
Expand Down
6 changes: 4 additions & 2 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.

}
failure = "unable to encode and copy exception type name";
goto finally;
}

Expand All @@ -237,8 +238,9 @@ _sharedexception_bind(PyObject *exctype, PyObject *exc, PyObject *tb)
if (err->msg == NULL) {
if (PyErr_ExceptionMatches(PyExc_MemoryError)) {
failure = "out of memory copying exception message";
} else {
failure = "unable to encode and copy exception message";
}
failure = "unable to encode and copy exception message";
goto finally;
}
}
Expand Down
1 change: 0 additions & 1 deletion Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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?

if (PyBytes_Check(obj)) {
data->buf = PyBytes_AsString(obj);
len = PyBytes_Size(obj);
Expand Down
2 changes: 1 addition & 1 deletion Python/pathconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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?

while (1) {
p = wcschr(sys_path, delim);
if (p == NULL) {
Expand Down
1 change: 0 additions & 1 deletion Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.

*tstate_p = tstate;

status = pycore_init_types();
Expand Down