Re: Fix warning: ‘startpos’ may be used uninitialized in function ‘results_differ’ - Mailing list pgsql-hackers

From Ewan Young
Subject Re: Fix warning: ‘startpos’ may be used uninitialized in function ‘results_differ’
Date
Msg-id CAON2xHOXZxdwRJRoCPO0W4pf0EKatXonVgjMPno6eH6TBj290g@mail.gmail.com
Whole thread
In response to Re: Fix warning: ‘startpos’ may be used uninitialized in function ‘results_differ’  (m.litsarev@postgrespro.ru)
Responses Re: Fix warning: ‘startpos’ may be used uninitialized in function ‘results_differ’
List pgsql-hackers
Hi Mikhail,

On Thu, Jun 11, 2026 at 11:10 PM <m.litsarev@postgrespro.ru> wrote:
>
> The patch attached

Thanks for the report and patch.

I looked at the data flow and agree this is a false positive. startpos is
assigned at the ftell() call inside the first if (difffile) block, and the
only way to reach the use at fseek() with difffile != NULL is for that same
block to have executed (since difffile is reassigned by the fopen(..., "r")
at the end of it).

I should note I couldn't reproduce the warning here: with gcc 12.2 it stays
silent at every optimization level, including -Og.

The fix looks correct to me. The raw diff looks large, but it's almost entirely
re-indentation — git diff -w shows the actual change is just moving the
braces to nest the read block inside the first one.

For the record, the minimal alternative would be long startpos = 0; at the
declaration, which is a one-line diff. I'd lean toward your version, but
I'll leave the final call to a committer.

Regards,
Ewan



pgsql-hackers by date:

Previous
From: Henson Choi
Date:
Subject: Re: LLVM JIT: any JIT-compiled query crashes (SIGILL) on a libLLVM 19 + ASAN build
Next
From: Michael Paquier
Date:
Subject: Re: t/035_standby_logical_decoding.pl might fail on attempt to read wrong timeline