Skip to contentSkip to conversation

chardev-socket: remove useless if

PATCH In review Paolo Bonzini 3 participants 5 messages Mar 20, 2018 – Mar 21, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 chardev-socket: remove useless if

This trips Coverity, which believes the subsequent qio_channel_create_watch can dereference a NULL pointer. In reality, tcp_chr_connect's callers all have s->ioc properly initialized, since they are all rooted at tcp_chr_new_client.

---
 chardev/char-socket.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
chardev/char-socket.c +4 -6
index d057192ced..159e69c3b1 100644
@@ -550,12 +550,10 @@ static void tcp_chr_connect(void *opaque)
         s->is_listen, s->is_telnet);
 
     s->connected = 1;
-    if (s->ioc) {
-        chr->gsource = io_add_watch_poll(chr, s->ioc,
-                                           tcp_chr_read_poll,
-                                           tcp_chr_read,
-                                           chr, chr->gcontext);
-    }
+    chr->gsource = io_add_watch_poll(chr, s->ioc,
+                                       tcp_chr_read_poll,
+                                       tcp_chr_read,
+                                       chr, chr->gcontext);
 
     s->hup_source = qio_channel_create_watch(s->ioc, G_IO_HUP);
     g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup,
Signature · 1 line
2.16.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Paolo Bonzini

This trips Coverity, which believes the subsequent qio_channel_create_watch can dereference a NULL pointer. In reality, tcp_chr_connect's callers all have s->ioc properly initialized, since they are all rooted at tcp_chr_new_client.

---

Quoted 28 lines
 chardev/char-socket.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
chardev/char-socket.c +4 -7
index d057192ced..159e69c3b1 100644
@@ -550,12 +550,10 @@ static void tcp_chr_connect(void *opaque)
         s->is_listen, s->is_telnet);
 
     s->connected = 1;
-    if (s->ioc) {
-        chr->gsource = io_add_watch_poll(chr, s->ioc,
-                                           tcp_chr_read_poll,
-                                           tcp_chr_read,
-                                           chr, chr->gcontext);
-    }
+    chr->gsource = io_add_watch_poll(chr, s->ioc,
+                                       tcp_chr_read_poll,
+                                       tcp_chr_read,
+                                       chr, chr->gcontext);
 
     s->hup_source = qio_channel_create_watch(s->ioc, G_IO_HUP);
     g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup,
--

2.16.2

Signature · 1 line
Marc-André Lureau
Reviewed-by on v1 1/1
#2 lore raw
In reply to Paolo Bonzini
Quoted 6 lines · Paolo Bonzini

This trips Coverity, which believes the subsequent qio_channel_create_watch can dereference a NULL pointer. In reality, tcp_chr_connect's callers all have s->ioc properly initialized, since they are all rooted at tcp_chr_new_client.

(maybe replacing with an assertion would be nicer? No big deal.)

Signature · 1 line
Peter Xu
#3 lore raw
Quoted 9 lines · Peter Xu
Quoted 6 lines · Paolo Bonzini

This trips Coverity, which believes the subsequent qio_channel_create_watch can dereference a NULL pointer. In reality, tcp_chr_connect's callers all have s->ioc properly initialized, since they are all rooted at tcp_chr_new_client.

(maybe replacing with an assertion would be nicer? No big deal.)

It's already asserting, it just raises SIGSEGV instead of SIGABRT. :)

Paolo

#4 lore raw
Quoted 7 lines · Paolo Bonzini
Quoted 6 lines · Peter Xu
Quoted 5 lines · Paolo Bonzini

This trips Coverity, which believes the subsequent qio_channel_create_watch can dereference a NULL pointer. In reality, tcp_chr_connect's callers all have s->ioc properly initialized, since they are all rooted at tcp_chr_new_client.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

(maybe replacing with an assertion would be nicer? No big deal.)

It's already asserting, it just raises SIGSEGV instead of SIGABRT. :)

Ah yes it's in the next qio_channel_create_watch(). :)

Signature · 1 line
Peter Xu