Silence -Wmaybe-uninitialized warnings
Hi
When building postgresql with CFLAGS="-Og" gcc emits
'-Wmaybe-uninitialized' warnings at few places. The variables are
initialized on all execution paths but the compiler was not able to
prove it with the additional optimization flag enabled. The patch
initializes the variables with NULL to silence the warnings. No
functional change intended.
```
[646/2085] Compiling C object
src/backend/postgres_lib.a.p/commands_copyfromparse.c.o
../src/backend/commands/copyfromparse.c: In function ‘CopyFromTextOneRow’:
../src/backend/commands/copyfromparse.c:995:39: warning:
‘field_strings’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
995 | string = field_strings[fieldno++];
| ^
../src/backend/commands/copyfromparse.c:961:21: note: ‘field_strings’
was declared here
961 | char **field_strings;
| ^~~~~~~~~~~~~
../src/backend/commands/copyfromparse.c: In function ‘CopyFromCSVOneRow’:
../src/backend/commands/copyfromparse.c:995:39: warning:
‘field_strings’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
995 | string = field_strings[fieldno++];
| ^
../src/backend/commands/copyfromparse.c:961:21: note: ‘field_strings’
was declared here
961 | char **field_strings;
| ^~~~~~~~~~~~~
[889/2085] Compiling C object
src/backend/postgres_lib.a.p/partitioning_partbounds.c.o
../src/backend/partitioning/partbounds.c: In function
‘check_partition_bounds_for_split_range’:
../src/backend/partitioning/partbounds.c:5452:57: warning: ‘datum’ may
be used uninitialized in this function [-Wmaybe-uninitialized]
5452 |
parser_errposition(pstate, exprLocation((Node *) datum)));
|
```
gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0
Regards
Imran Zaheer
Attachments:
v1-0001-Silence-Wmaybe-uninitialized-warnings.patchtext/x-patch; charset=US-ASCII; name=v1-0001-Silence-Wmaybe-uninitialized-warnings.patchDownload+2-4
Hi
I pulled the latest HEAD today and found some more -Wmaybe-uninitialized
warnings.
```
[1/6] Compiling C object
src/interfaces/ecpg/test/pg_regress_ecpg.p/.._.._.._test_regress_pg_regress.c.o
../src/test/regress/pg_regress.c: In function ‘results_differ’:
../src/test/regress/pg_regress.c:1577:17: warning: ‘startpos’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
1577 | fseek(difffile, startpos, SEEK_SET);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[2/6] Compiling C object
src/test/isolation/pg_isolation_regress.p/.._regress_pg_regress.c.o
../src/test/regress/pg_regress.c: In function ‘results_differ’:
../src/test/regress/pg_regress.c:1577:17: warning: ‘startpos’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
1577 | fseek(difffile, startpos, SEEK_SET);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[3/6] Compiling C object src/test/regress/pg_regress.p/pg_regress.c.o
../src/test/regress/pg_regress.c: In function ‘results_differ’:
../src/test/regress/pg_regress.c:1577:17: warning: ‘startpos’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
1577 | fseek(difffile, startpos, SEEK_SET);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Here is the updated v2 patch addressing them.
Regards,
Imran Zaheer
On Thu, Apr 2, 2026 at 2:49 PM Imran Zaheer <imran.zhir@gmail.com> wrote:
Show quoted text
Hi
When building postgresql with CFLAGS="-Og" gcc emits
'-Wmaybe-uninitialized' warnings at few places. The variables are
initialized on all execution paths but the compiler was not able to
prove it with the additional optimization flag enabled. The patch
initializes the variables with NULL to silence the warnings. No
functional change intended.```
[646/2085] Compiling C object
src/backend/postgres_lib.a.p/commands_copyfromparse.c.o
../src/backend/commands/copyfromparse.c: In function ‘CopyFromTextOneRow’:
../src/backend/commands/copyfromparse.c:995:39: warning:
‘field_strings’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
995 | string = field_strings[fieldno++];
| ^
../src/backend/commands/copyfromparse.c:961:21: note: ‘field_strings’
was declared here
961 | char **field_strings;
| ^~~~~~~~~~~~~
../src/backend/commands/copyfromparse.c: In function ‘CopyFromCSVOneRow’:
../src/backend/commands/copyfromparse.c:995:39: warning:
‘field_strings’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
995 | string = field_strings[fieldno++];
| ^
../src/backend/commands/copyfromparse.c:961:21: note: ‘field_strings’
was declared here
961 | char **field_strings;
| ^~~~~~~~~~~~~
[889/2085] Compiling C object
src/backend/postgres_lib.a.p/partitioning_partbounds.c.o
../src/backend/partitioning/partbounds.c: In function
‘check_partition_bounds_for_split_range’:
../src/backend/partitioning/partbounds.c:5452:57: warning: ‘datum’ may
be used uninitialized in this function [-Wmaybe-uninitialized]
5452 |
parser_errposition(pstate, exprLocation((Node *) datum)));
|
```
gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0Regards
Imran Zaheer
Hi,
On Fri, Apr 03, 2026 at 07:14:18PM +0500, Imran Zaheer wrote:
Hi
I pulled the latest HEAD today and found some more -Wmaybe-uninitialized
warnings.```
[1/6] Compiling C object
src/interfaces/ecpg/test/pg_regress_ecpg.p/.._.._.._test_regress_pg_regress.c.o
../src/test/regress/pg_regress.c: In function ‘results_differ’:
../src/test/regress/pg_regress.c:1577:17: warning: ‘startpos’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
1577 | fseek(difffile, startpos, SEEK_SET);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[2/6] Compiling C object
src/test/isolation/pg_isolation_regress.p/.._regress_pg_regress.c.o
../src/test/regress/pg_regress.c: In function ‘results_differ’:
../src/test/regress/pg_regress.c:1577:17: warning: ‘startpos’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
1577 | fseek(difffile, startpos, SEEK_SET);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[3/6] Compiling C object src/test/regress/pg_regress.p/pg_regress.c.o
../src/test/regress/pg_regress.c: In function ‘results_differ’:
../src/test/regress/pg_regress.c:1577:17: warning: ‘startpos’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
1577 | fseek(difffile, startpos, SEEK_SET);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```Here is the updated v2 patch addressing them.
That's an "old" compiler hallucination.
With an "old" one:
$ gcc -Isrc/backend/postgres_lib.a.p -Isrc/include -I../src/include \
-Og -fPIC -pthread -DBUILDING_DLL -Wmaybe-uninitialized \
-o src/backend/postgres_lib.a.p/partitioning_partbounds.c.o \
-c ../src/backend/partitioning/partbounds.c
../src/backend/partitioning/partbounds.c: In function ‘check_partition_bounds_for_split_range’:
../src/backend/partitioning/partbounds.c:5452:57: warning: ‘datum’ may be used uninitialized in this function [-Wmaybe-uninitialized]
5452 | parser_errposition(pstate, exprLocation((Node *) datum)));
$ gcc --version
gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5)
I can see the same warning that you reported.
But with a more recent one:
/usr/bin/gcc14-gcc -Isrc/backend/postgres_lib.a.p -Isrc/include -I../src/include \
-Og -fPIC -pthread -DBUILDING_DLL -Wmaybe-uninitialized \
-o src/backend/postgres_lib.a.p/partitioning_partbounds.c.o \
-c ../src/backend/partitioning/partbounds.c
There are no warnings.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com