[Spice-devel] [PATCH] Silence gcc false positive with -Wuninitialized

Christophe Fergeau cfergeau at redhat.com
Fri Oct 18 14:53:08 CEST 2013


Some versions of gcc warn about:
red_channel.c: In function 'red_channel_client_wait_outgoing_item':
red_channel.c:2331: error: 'end_time' may be used uninitialized in this function [-Wuninitialized]
red_channel.c: In function 'red_channel_client_wait_pipe_item_sent':
red_channel.c:2363: error: 'end_time' may be used uninitialized in this function [-Wuninitialized]
red_channel.c: In function 'red_channel_wait_all_sent':
red_channel.c:2401: error: 'end_time' may be used uninitialized in this function [-Wuninitialized]

This is a false positive as end_time is unitialized when timeout is -1, and
we will only try to use end_time if timeout is not -1.

This commit initializes end_time to UINT64_MAX to avoid that warning. As
the test involving end_time will never be reached, we ensure it's always
TRUE so that it would be a noop even if it was reached.
---
 server/red_channel.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/server/red_channel.c b/server/red_channel.c
index 2cef2be..f2d1cca 100644
--- a/server/red_channel.c
+++ b/server/red_channel.c
@@ -2336,6 +2336,8 @@ int red_channel_client_wait_outgoing_item(RedChannelClient *rcc,
     }
     if (timeout != -1) {
         end_time = red_now() + timeout;
+    } else {
+        end_time = UINT64_MAX;
     }
     spice_info("blocked");
 
@@ -2367,8 +2369,11 @@ int red_channel_client_wait_pipe_item_sent(RedChannelClient *rcc,
 
     if (timeout != -1) {
         end_time = red_now() + timeout;
+    } else {
+        end_time = UINT64_MAX;
     }
 
+
     rcc->channel->channel_cbs.hold_item(rcc, item);
 
     if (red_channel_client_blocked(rcc)) {
@@ -2404,6 +2409,8 @@ int red_channel_wait_all_sent(RedChannel *channel,
 
     if (timeout != -1) {
         end_time = red_now() + timeout;
+    } else {
+        end_time = UINT64_MAX;
     }
 
     red_channel_push(channel);
-- 
1.8.3.1



More information about the Spice-devel mailing list