Skip to contentSkip to conversation

eliminate compiler warning for xpc_channel.c

PATCH In review Dean Nelson 3 participants 6 messages Apr 4, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eliminate compiler warning for xpc_channel.c

Placate a compiler warning that 'msg' may be used uninitialized in function xpc_initiate_allocate().

Index: linux-2.6/arch/ia64/sn/kernel/xpc_channel.c
=================================--- linux-2.6.orig/arch/ia64/sn/kernel/xpc_channel.c 2006-04-03 08:26:22.000000000 -0500
+++ linux-2.6/arch/ia64/sn/kernel/xpc_channel.c 2006-04-04 08:25:51.691831163 -0500
@@ -1831,7 +1831,7 @@
{
struct xpc_partition *part = &xpc_partitions[partid]; enum xpc_retval ret = xpcUnknownReason;
- struct xpc_msg *msg;
+ struct xpc_msg *msg = msg;

DBUG_ON(partid <= 0 || partid >= XP_MAX_PARTITIONS);

#1 lore raw
Quoted 2 lines

Placate a compiler warning that 'msg' may be used uninitialized in function xpc_initiate_allocate().

Which version of which compiler ... at first glance the code looks trivially OK (&msg is passed to xpc_allocate_msg() before it is used). On closer inspection I assume that the compiler must have inlined xpc_allocate_msg() in order to detect this, and there are four "return" statements in there that can return w/o doing the initialization. So the warning is real, and we are not just "placating" the compiler.

- struct xpc_msg *msg;
+ struct xpc_msg *msg = msg;

Did you mean to say "*msg = NULL"?

-Tony

#2 lore raw
In reply to Dean Nelson
Quoted 4 lines · Tony
(quoted diff) +1 -1
-	struct xpc_msg *msg;
+	struct xpc_msg *msg = msg;

Did you mean to say "*msg = NULL"?

this is actually an ANSI-permitted idiom for shutting up compiler warnings while not actually initialising the variable.

#3 lore raw
In reply to Dean Nelson
Quoted 4 lines
Quoted 1 line

Did you mean to say "*msg = NULL"?

this is actually an ANSI-permitted idiom for shutting up compiler warnings while not actually initialising the variable.

So I learned something new today!

But then this patch is wrong ... it shuts the compiler up and leaves 4 ways that xpc_allocate_msg() can return without doing the initialization, so that msg will be used uninitialized.

-Tony

#4 lore raw
In reply to Dean Nelson
Quoted 10 lines · Tony
Quoted 4 lines
Quoted 1 line

Did you mean to say "*msg = NULL"?

this is actually an ANSI-permitted idiom for shutting up compiler warnings while not actually initialising the variable.

So I learned something new today!

But then this patch is wrong ... it shuts the compiler up and leaves 4 ways that xpc_allocate_msg() can return without doing the initialization, so that msg will be used uninitialized.

You are correct: "*msg = NULL" is the right answer.

The compiler being used is: "gcc (GCC) 4.1.0 (SUSE Linux)".

In the past when I've seen complier warnings of this nature, it usually (but not always) turned out that the compiler was unable to 'see' that things were really okay. In this particular case, I hadn't seen this warning until just yesterday (my build machine was just updated a few days ago), and since nothing in this area of the code had changed for some time now, I just assumed that the compiler was not seeing things properly. It didn't occur to me that xpc_allocate_msg() was possibly being inlined and thus the compiler was giving a correct warning that should not be ignored.

Do you want a new patch, or are you comfortable with switching the 'msg' to a 'NULL'?

Thanks for looking more closely than I obviously did.

Dean