xloginsert.c hole_length warning on gcc 4.8.3

Started by Tomas Vondraalmost 11 years ago2 messages
#1Tomas Vondra
tomas.vondra@2ndquadrant.com
1 attachment(s)

Hi there,

with gcc 4.8.3, I'm getting this warning in xloginsert.c:

-------------------------
xloginsert.c: In function ‘XLogInsert’:
xloginsert.c:668:20: warning: ‘hole_length’ may be used uninitialized in
this function [-Wmaybe-uninitialized]
if (hole_length != 0 && is_compressed)
^
xloginsert.c:497:10: note: ‘hole_length’ was declared here
uint16 hole_length;
-------------------------

The compiler seems to be confused probably because the code is
structured like this:

{
uint16 hole_length;
uint16 hole_offset;

if (needs_backup)
{
... initialize hole_length/hole_offset ...
}

if (needs_data)
{
...
}

if (needs_backup)
{
... use hole_length/hole_offset ...
}
}

and does not realize the two blocks referencing the variables use the
same condition.

Initializing the variables at the very beginning (and simplifying the
first block a bit) seems like a good fix - patch attached.

--
Tomas Vondra http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

xloginsert-hole.patchtext/x-diff; name=xloginsert-hole.patchDownload
diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c
index fb39e70..3f56d14 100644
--- a/src/backend/access/transam/xloginsert.c
+++ b/src/backend/access/transam/xloginsert.c
@@ -494,8 +494,8 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
 		XLogRecordBlockCompressHeader cbimg;
 		bool		samerel;
 		bool		is_compressed = false;
-		uint16	hole_length;
-		uint16	hole_offset;
+		uint16	hole_length = 0;
+		uint16	hole_offset = 0;
 
 		if (!regbuf->in_use)
 			continue;
@@ -546,7 +546,8 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
 
 			/*
 			 * The page needs to be backed up, so calculate its hole length
-			 * and offset.
+			 * and offset, but only if it's a standard page header, and if
+			 * there actually is a hole to compress out.
 			 */
 			if (regbuf->flags & REGBUF_STANDARD)
 			{
@@ -561,18 +562,6 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
 					hole_offset = lower;
 					hole_length = upper - lower;
 				}
-				else
-				{
-					/* No "hole" to compress out */
-					hole_offset = 0;
-					hole_length = 0;
-				}
-			}
-			else
-			{
-				/* Not a standard page header, don't try to eliminate "hole" */
-				hole_offset = 0;
-				hole_length = 0;
 			}
 
 			/*
#2Fujii Masao
masao.fujii@gmail.com
In reply to: Tomas Vondra (#1)
Re: xloginsert.c hole_length warning on gcc 4.8.3

On Sat, Mar 14, 2015 at 8:39 AM, Tomas Vondra
<tomas.vondra@2ndquadrant.com> wrote:

Hi there,

with gcc 4.8.3, I'm getting this warning in xloginsert.c:

Thanks for the report! I fixed this problem at the commit cd6c45c.

Regards,

--
Fujii Masao

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers