public inbox for [email protected]
help / color / mirror / Atom feedSilence -Wmaybe-uninitialized warnings
3+ messages / 2 participants
[nested] [flat]
* Silence -Wmaybe-uninitialized warnings
@ 2026-04-02 09:49 Imran Zaheer <[email protected]>
0 siblings, 1 reply; 3+ messages in thread
From: Imran Zaheer @ 2026-04-02 09:49 UTC (permalink / raw)
To: pgsql-hackers
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:
[text/x-patch] v1-0001-Silence-Wmaybe-uninitialized-warnings.patch (1.5K, 2-v1-0001-Silence-Wmaybe-uninitialized-warnings.patch)
download | inline diff:
From 58ec322de2f210355e6ec1a16df4988be63e5acb Mon Sep 17 00:00:00 2001
From: Imran Zaheer <[email protected]>
Date: Thu, 2 Apr 2026 14:02:47 +0500
Subject: [PATCH v1] Silence -Wmaybe-uninitialized warnings
When building with CFLAGS="-Og", GCC was emitting
-Wmaybe-uninitialized warnings for some variables.
Initialize variables to NULL to silence the warnings.
---
src/backend/commands/copyfromparse.c | 2 +-
src/backend/partitioning/partbounds.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index 65fd5a0ab4f..cb2aac54a34 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -958,7 +958,7 @@ CopyFromTextLikeOneRow(CopyFromState cstate, ExprContext *econtext,
FmgrInfo *in_functions = cstate->in_functions;
Oid *typioparams = cstate->typioparams;
ExprState **defexprs = cstate->defexprs;
- char **field_strings;
+ char **field_strings = NULL;
ListCell *cur;
int fldct;
int fieldno;
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index f867d1b75a5..3e608d6f217 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -5375,7 +5375,7 @@ check_partition_bounds_for_split_range(Relation parent,
if (first || last)
{
PartitionBoundSpec *split_spec = get_partition_bound_spec(splitPartOid);
- PartitionRangeDatum *datum;
+ PartitionRangeDatum *datum = NULL;
if (first)
{
--
2.34.1
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Silence -Wmaybe-uninitialized warnings
@ 2026-04-03 14:14 Imran Zaheer <[email protected]>
parent: Imran Zaheer <[email protected]>
0 siblings, 1 reply; 3+ messages in thread
From: Imran Zaheer @ 2026-04-03 14:14 UTC (permalink / raw)
To: pgsql-hackers
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 <[email protected]> wrote:
> 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:
[text/x-patch] v2-0001-Silence-Wmaybe-uninitialized-warnings.patch (2.0K, 3-v2-0001-Silence-Wmaybe-uninitialized-warnings.patch)
download | inline diff:
From 2c8cdbfbc8cde6476b65a95ffb63d1b7252f7e8c Mon Sep 17 00:00:00 2001
From: Imran Zaheer <[email protected]>
Date: Fri, 3 Apr 2026 19:07:31 +0500
Subject: [PATCH v2] Silence -Wmaybe-uninitialized warnings
When building with CFLAGS="-Og", GCC was emitting -Wmaybe-uninitialized
warnings at some places.
Initialize variables to silence the warnings.
---
src/backend/commands/copyfromparse.c | 2 +-
src/backend/partitioning/partbounds.c | 2 +-
src/test/regress/pg_regress.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index 65fd5a0ab4f..cb2aac54a34 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -958,7 +958,7 @@ CopyFromTextLikeOneRow(CopyFromState cstate, ExprContext *econtext,
FmgrInfo *in_functions = cstate->in_functions;
Oid *typioparams = cstate->typioparams;
ExprState **defexprs = cstate->defexprs;
- char **field_strings;
+ char **field_strings = NULL;
ListCell *cur;
int fldct;
int fieldno;
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index f867d1b75a5..3e608d6f217 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -5375,7 +5375,7 @@ check_partition_bounds_for_split_range(Relation parent,
if (first || last)
{
PartitionBoundSpec *split_spec = get_partition_bound_spec(splitPartOid);
- PartitionRangeDatum *datum;
+ PartitionRangeDatum *datum = NULL;
if (first)
{
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index 9a918156437..467bd79068c 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -1425,7 +1425,7 @@ results_differ(const char *testname, const char *resultsfile, const char *defaul
int best_line_count;
int i;
int l;
- long startpos;
+ long startpos = 0;
const char *platform_expectfile;
/*
--
2.34.1
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Silence -Wmaybe-uninitialized warnings
@ 2026-04-03 14:47 Bertrand Drouvot <[email protected]>
parent: Imran Zaheer <[email protected]>
0 siblings, 0 replies; 3+ messages in thread
From: Bertrand Drouvot @ 2026-04-03 14:47 UTC (permalink / raw)
To: Imran Zaheer <[email protected]>; +Cc: pgsql-hackers
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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2026-04-03 14:47 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-04-02 09:49 Silence -Wmaybe-uninitialized warnings Imran Zaheer <[email protected]>
2026-04-03 14:14 ` Imran Zaheer <[email protected]>
2026-04-03 14:47 ` Bertrand Drouvot <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox