Re: [PATCH v2] http API: fix dangling pointer issue noted by GCC 12.0
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Feb 26, 2022, 18:01 UTC
- Message-ID
- <YhprAb1f1WYIktCV@nand.local>
- In-Reply-To
- <patch-v2-1.1-777838267a5-20220225T090816Z-avarab@gmail.com>
On Fri, Feb 25, 2022 at 10:09:11AM +0100, Ævar Arnfjörð Bjarmason wrote:
Show 5 quoted lines
> There's a few possible ways to fix this, but the simplest is to assign > NULL to "slot->finished" at the end of run_active_slot(), it's the > only caller that ever assigns non-NULL to it. It was suggested[2] to > guard that with "if (slot->finished == &finished)", but that'll still > trigger the warning.
I'm not quite sure that I follow this. This isn't the only spot that assigns non-NULL to "slot->finished", see the assignments in http-walker.c:process_alternates_response() and http.c:finish_active_slot().
But even if it were, I'm not sure how this being the only spot that *writes* non-NULL matters from a reader's perspective.
Looking more at process_alternates_response(), it really looks like this variable wants to hold a tri-state value. I wonder if it would be clearer to replace the NULL/(pointer to) 0/(pointer to) 1 with a UNKNOWN/TRUE/FALSE enum.
Thanks, Taylor