Fix or remove dead assignments identified by scan-build#16267
Fix or remove dead assignments identified by scan-build#16267alexhenrie wants to merge 1 commit into
Conversation
| int x_is_odd; | ||
| PyObject *temp; | ||
|
|
||
| whole_us = round(leftover_us); |
There was a problem hiding this comment.
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 (_PyStatus_EXCEPTION(status)) { | ||
| return status; | ||
| } | ||
| config = &tstate->interp->config; |
There was a problem hiding this comment.
Hm, this one I'm having trouble understanding how it happened and if it was actually intended to have some effect.
There was a problem hiding this comment.
This change is correct. I wrote the config, but it's no longer needed to update the config variable.
| return 1; | ||
| } | ||
| data->obj = NULL; | ||
| len = -1; |
There was a problem hiding this comment.
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 (PyErr_ExceptionMatches(PyExc_MemoryError)) { | ||
| failure = "out of memory copying exception type name"; | ||
| } else { | ||
| failure = "unable to encode and copy exception type name"; |
There was a problem hiding this comment.
This appears to be an actual bugfix.
eamanu
left a comment
There was a problem hiding this comment.
Hmm interest PR. Seems to be good. But I can make a depth review
|
@alexhenrie, please open a ticket on the bug tracker for this issue and update the title to include the ticket number. Thank you! |
|
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. |
| const wchar_t *sys_path = pathconfig->module_search_path; | ||
| const wchar_t delim = DELIM; | ||
| const wchar_t *p = sys_path; | ||
| const wchar_t *p; |
There was a problem hiding this comment.
Would you mind to move the variable declaration inside the loop to even show better its scope?
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.