Silence using uninitialized value

Started by Ranier Vilela9 months ago1 messages
#1Ranier Vilela
ranier.vf@gmail.com
2 attachment(s)

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:

fix_read_unitialized_variable_tablecmds.patchapplication/octet-stream; name=fix_read_unitialized_variable_tablecmds.patchDownload
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);
fix-uninitialized-read-variable-tablespace.patchapplication/octet-stream; name=fix-uninitialized-read-variable-tablespace.patchDownload
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);