Title: Dead assignment in Py_UniversalNewlineFgets
Type: enhancement Stage: patch review
Components: IO Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: alex.henrie, serhiy.storchaka, terry.reedy, vstinner
Priority: normal Keywords: patch

Created on 2021-03-02 02:16 by alex.henrie, last changed 2021-03-08 19:49 by vstinner.

Pull Requests
URL Status Linked Edit
PR 24699 open alex.henrie, 2021-03-02 02:17
Messages (5)
msg387894 - (view) Author: Alex Henrie (alex.henrie) * Date: 2021-03-02 02:16
The function Py_UniversalNewlineFgets currently initializes the variable c to 'x' and then overwrites it without ever reading that value back. There used to be code that read back c's initial value, but it was commented out by commit b94767ff44edf5d461d7cb1c8eb5160f83886358 (bpo-8914) in 2011. So at this point, removing the dead initialization will not trigger a compiler warning or cause any other undesired behavior.

Defect identified by scan-build <>
msg388170 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-03-05 22:30
Victor and/or Serhiy: This and #43360 and #43361 are similar 1-line changes, suggested by scan-build, to eliminate dead or duplicate initializations in C code.  Can either of you either handle these or suggest someone else?  Would we have preferred 1 issue and PR?  Do we backport such changes?

All 3 diffs have a bunch of github beta check annotation warnings for an otherwise unchanged C file.  Fix?  Suppress somehow?
msg388282 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-03-08 18:54
>     c = 'x'; /* Shut up gcc warning */

IMHO this code is fine and should be kept. I hate fighting against stupid false alarms of compiler warnings. This code is harmless. It doesn't affect performances or anything.

I suggest to close this issue and its PR.
msg388284 - (view) Author: Alex Henrie (alex.henrie) * Date: 2021-03-08 19:08
Hi Victor, just so we're all on the same page, removing the line does not trigger a compiler warning. The comment on this line is misleading.
msg388291 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-03-08 19:49
> Hi Victor, just so we're all on the same page, removing the line does not trigger a compiler warning. The comment on this line is misleading.

I wrote the opposite. IMO the line and its commment should be kept.

> Defect identified by scan-build <>

Just tell your tool that the line is there on purpose.
Date User Action Args
2021-03-08 19:49:06vstinnersetmessages: + msg388291
2021-03-08 19:08:52alex.henriesetmessages: + msg388284
2021-03-08 18:54:23vstinnersetmessages: + msg388282
2021-03-05 22:30:57terry.reedysetnosy: + serhiy.storchaka, terry.reedy, vstinner
messages: + msg388170
2021-03-02 02:17:20alex.henriesetkeywords: + patch
stage: patch review
pull_requests: + pull_request23476
2021-03-02 02:16:27alex.henriecreate