Subject: Re: a libssh2 release soon

Re: a libssh2 release soon

From: Simon Josefsson <simon_at_josefsson.org>
Date: Tue, 28 Jul 2009 12:53:40 +0200

Here is another -Wall problem:

packet.c: In function ‘_libssh2_packet_add’:
packet.c:126: warning: ‘channel’ may be used uninitialized in this function
packet.c:126: note: ‘channel’ was declared here
packet.c:291: warning: ‘channel’ may be used uninitialized in this function
packet.c:291: note: ‘channel’ was declared here
transport.c: In function ‘_libssh2_transport_read’:
transport.c:266: warning: ‘rc’ may be used uninitialized in this function

In both places the function code is very long and takes time to read, so
it isn't immediately obvious that the use is safe (it probably is). But
setting the variable to NULL at initialization silence the warning and
appears safer to me. Objections to pushing this?

/Simon

diff --git a/src/packet.c b/src/packet.c
index 888786d..6785dcd 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -123,7 +123,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data,
                  (listen->host, listen_state->host,
                   listen_state->host_len) == 0)) {
                 /* This is our listener */
- LIBSSH2_CHANNEL *channel, *last_queued = listen->queue;
+ LIBSSH2_CHANNEL *channel = NULL, *last_queued = listen->queue;
 
                 last_queued = listen->queue;
                 if (listen_state->state == libssh2_NB_state_allocated) {
@@ -288,7 +288,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
     /* 17 = packet_type(1) + channel(4) + reason(4) + descr(4) + lang(4) */
     unsigned long packet_len = 17 + (sizeof(X11FwdUnAvil) - 1);
     unsigned char *p;
- LIBSSH2_CHANNEL *channel;
+ LIBSSH2_CHANNEL *channel = NULL;
     int rc;
 
     (void) datalen;
diff --git a/src/transport.c b/src/transport.c
index 19083f9..4c11f9a 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -263,7 +263,7 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ )
 libssh2pack_t
 _libssh2_transport_read(LIBSSH2_SESSION * session)
 {
- libssh2pack_t rc;
+ libssh2pack_t rc = -1;
     struct transportpacket *p = &session->packet;
     int remainbuf;
     int remainpack;
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2009-07-28