public inbox for [email protected]  
help / color / mirror / Atom feed
From: Ranier Vilela <[email protected]>
To: Pg Hackers <[email protected]>
Subject: Silence using uninitialized value
Date: Tue, 15 Apr 2025 08:53:43 -0300
Message-ID: <CAEudQApZnTYftuM-opLARSFOQ2uivxcu894xH+KXj2t4H-eouw@mail.gmail.com> (raw)

Hi.

Per Coverity.

Coverity has new report about tablecmds.c and tablespace.c

tablecmds.c:
CID 1608920: (#1 of 1): Uninitialized scalar variable (UNINIT)
6. uninit_use_in_call: Using uninitialized value *repl_val when calling
heap_modify_tuple.

CID 1608899: (#1 of 1): Uninitialized scalar variable (UNINIT)
16. uninit_use_in_call: Using uninitialized value *repl_val when calling
heap_modify_tuple.

tablespace.c:
CID 1608898: (#1 of 1): Uninitialized scalar variable (UNINIT)
6. uninit_use_in_call: Using uninitialized value *repl_val when calling
heap_modify_tuple.

I don't think that is a bug.
But really the uninitialized value is read here:
(src/backend/access/common/heaptuple.c )

3. read_value: Reading value replValues[attoff].
1242                        values[attoff] = replValues[attoff];
1243                        isnull[attoff] = replIsnull[attoff];
1244                }

There a common pattern in the source code:

value = (Datum) 0;
null = true;

So I believe it is worth changing to the standard used.

patch attached.

best regards,
Ranier Vilela


Attachments:

  [application/octet-stream] fix_read_unitialized_variable_tablecmds.patch (1.1K, ../CAEudQApZnTYftuM-opLARSFOQ2uivxcu894xH+KXj2t4H-eouw@mail.gmail.com/3-fix_read_unitialized_variable_tablecmds.patch)
  download | inline diff:
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 686f1850ca..1dcf6abd42 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -8987,7 +8987,10 @@ ATExecSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newVa
 	if (!newtarget_default)
 		repl_val[Anum_pg_attribute_attstattarget - 1] = newtarget;
 	else
+	{
+		repl_val[Anum_pg_attribute_attstattarget - 1] = (Datum) 0;
 		repl_null[Anum_pg_attribute_attstattarget - 1] = true;
+	}
 	repl_repl[Anum_pg_attribute_attstattarget - 1] = true;
 	newtuple = heap_modify_tuple(tuple, RelationGetDescr(attrelation),
 								 repl_val, repl_null, repl_repl);
@@ -9061,7 +9064,10 @@ ATExecSetOptions(Relation rel, const char *colName, Node *options,
 	if (newOptions != (Datum) 0)
 		repl_val[Anum_pg_attribute_attoptions - 1] = newOptions;
 	else
+	{
+		repl_val[Anum_pg_attribute_attoptions - 1] = (Datum) 0;
 		repl_null[Anum_pg_attribute_attoptions - 1] = true;
+	}
 	repl_repl[Anum_pg_attribute_attoptions - 1] = true;
 	newtuple = heap_modify_tuple(tuple, RelationGetDescr(attrelation),
 								 repl_val, repl_null, repl_repl);


  [application/octet-stream] fix-uninitialized-read-variable-tablespace.patch (659B, ../CAEudQApZnTYftuM-opLARSFOQ2uivxcu894xH+KXj2t4H-eouw@mail.gmail.com/4-fix-uninitialized-read-variable-tablespace.patch)
  download | inline diff:
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index a9005cc721..c5024b1614 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -1063,7 +1063,10 @@ AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
 	if (newOptions != (Datum) 0)
 		repl_val[Anum_pg_tablespace_spcoptions - 1] = newOptions;
 	else
+	{
+		repl_val[Anum_pg_tablespace_spcoptions - 1] = (Datum) 0;
 		repl_null[Anum_pg_tablespace_spcoptions - 1] = true;
+	}
 	repl_repl[Anum_pg_tablespace_spcoptions - 1] = true;
 	newtuple = heap_modify_tuple(tup, RelationGetDescr(rel), repl_val,
 								 repl_null, repl_repl);


view thread (2+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: Silence using uninitialized value
  In-Reply-To: <CAEudQApZnTYftuM-opLARSFOQ2uivxcu894xH+KXj2t4H-eouw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox