Skip to contentSkip to conversation

build: remove compile warning

PATCH Superseded Wenchao Xia 3 participants 3 messages Jun 6, 2013

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build: remove compile warning

This patch simply remove "variable may be used uninitialized" warning.

---
 libcacard/vscclient.c |    2 +-
 util/iov.c            |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
libcacard/vscclient.c +1 -1
index ac23647..815f453 100644
@@ -641,7 +641,7 @@ main(
     GIOChannel *channel_stdin;
     char *qemu_host;
     char *qemu_port;
-    VSCMsgHeader mhHeader;
+    VSCMsgHeader mhHeader = {0};
 
     VCardEmulOptions *command_line_options = NULL;
 
util/iov.c +1 -1
index cc6e837..b91cfb9 100644
@@ -146,7 +146,7 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,
 {
     ssize_t total = 0;
     ssize_t ret;
-    size_t orig_len, tail;
+    size_t orig_len = 0, tail;
     unsigned niov;
 
     while (bytes > 0) {
Signature · 1 line
1.7.1
#1 lore raw
Quoted 13 lines · Wenchao Xia

This patch simply remove "variable may be used uninitialized" warning.

---
 libcacard/vscclient.c |    2 +-
 util/iov.c            |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
libcacard/vscclient.c +0 -0
index ac23647..815f453 100644

libcacard/vscclient.c main( · line 646

Quoted 7 lines
libcacard/vscclient.c +1 -1
@@ -641,7 +641,7 @@ main(
     GIOChannel *channel_stdin;
     char *qemu_host;
     char *qemu_port;
-    VSCMsgHeader mhHeader;
+    VSCMsgHeader mhHeader = {0};
 
     VCardEmulOptions *command_line_options = NULL;

The code looks broken to me:

main() {
    VSCMsgHeader mhHeader;
    ...
    send_msg(VSC_Init, mhHeader.reader_id, &init, sizeof(init));

This is really an uninitialized use of mhHeader.read_id. But it gets more interesting:

static int
send_msg(
VSCMsgType type,
uint32_t reader_id,
const void *msg,
unsigned int length

) {
    VSCMsgHeader mhHeader;

    qemu_mutex_lock(&socket_to_send_lock);

    if (verbose > 10) {
        printf("sending type=%d id=%u, len =%u (0x%x)\n",
               type, reader_id, length, length);
    }

    mhHeader.type = htonl(type);
    mhHeader.reader_id = 0;
    mhHeader.length = htonl(length);
    g_byte_array_append(socket_to_send, (guint8 *)&mhHeader, sizeof(mhHeader));
    g_byte_array_append(socket_to_send, (guint8 *)msg, length);
    g_idle_add(socket_prepare_sending, NULL);

    qemu_mutex_unlock(&socket_to_send_lock);

    return 0;
}

This function prints reader_id if verbose > 0 but it doesn't use it! mhHeader.read_id is always set to 0.

This should be cleaned up properly. The other issue you silenced looks okay.

Stefan

#2 lore raw
Quoted 16 lines · Stefan Hajnoczi

libcacard/vscclient.c main( · line 646

Quoted 12 lines · Wenchao Xia

This patch simply remove "variable may be used uninitialized" warning.

libcacard/vscclient.c +1 -1
@@ -641,7 +641,7 @@ main(
     GIOChannel *channel_stdin;
     char *qemu_host;
     char *qemu_port;
-    VSCMsgHeader mhHeader;
+    VSCMsgHeader mhHeader = {0};
 
     VCardEmulOptions *command_line_options = NULL;

The code looks broken to me:

Quoted 6 lines
main() {
    VSCMsgHeader mhHeader;
    ...
    send_msg(VSC_Init, mhHeader.reader_id, &init, sizeof(init));

This is really an uninitialized use of mhHeader.read_id.

See the patch already on list (and my review comments on it):
http://patchwork.ozlabs.org/patch/248856/

thanks
-- PMM