Skip to contentSkip to conversation

vnc: fix coverity warning

PATCH In review Gerd Hoffmann 3 participants 4 messages Feb 11, 2015 – Feb 12, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vnc: fix coverity warning

vnc_display_local_addr will not be called with an invalid display id. Add assert() to silence coverity warning about a null pointer dereference.

---
 ui/vnc.c | 1 +
 1 file changed, 1 insertion(+)
ui/vnc.c +1 -0
index e291987..25ba340 100644
@@ -3252,6 +3252,7 @@ char *vnc_display_local_addr(const char *id)
 {
     VncDisplay *vs = vnc_display_find(id);
 
+    assert(vs);
     return vnc_socket_local_addr("%s:%s", vs->lsock);
 }
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 14 lines · Gerd Hoffmann

vnc_display_local_addr will not be called with an invalid display id. Add assert() to silence coverity warning about a null pointer dereference.

---
 ui/vnc.c | 1 +
 1 file changed, 1 insertion(+)
ui/vnc.c +0 -0
index e291987..25ba340 100644

ui/vnc.c char *vnc_display_local_addr(const char *id) · line 3258

Quoted 7 lines
ui/vnc.c +1 -0
@@ -3252,6 +3252,7 @@ char *vnc_display_local_addr(const char *id)
 {
     VncDisplay *vs = vnc_display_find(id);
 
+    assert(vs);
     return vnc_socket_local_addr("%s:%s", vs->lsock);
 }
 

If you want, I can just silence the warning in Coverity.

Paolo

#2 lore raw
Quoted 7 lines
Quoted 5 lines
+    assert(vs);
     return vnc_socket_local_addr("%s:%s", vs->lsock);

}

If you want, I can just silence the warning in Coverity.

I think in the source code is better, human readers might wonder too.

And in case the calling code ever changes behavior the assert will trap it (even though it is highly unlikely in this specific case).

cheers,
Gerd

#3 lore raw
Quoted 6 lines · Gerd Hoffmann
Quoted 6 lines
Quoted 5 lines
+    assert(vs);
     return vnc_socket_local_addr("%s:%s", vs->lsock);

}

Quoted 6 lines
Quoted 1 line

If you want, I can just silence the warning in Coverity.

I think in the source code is better, human readers might wonder too.

And in case the calling code ever changes behavior the assert will trap it (even though it is highly unlikely in this specific case).

I'm very much in favor of using assertions to guide Coverity. Besides human readers, they may also help other static analyzers, including optimizers.

Speaking of silencing defects: we could also explore use of code annotations. Example given in the manual:

    x = NULL;
    ...
    // coverity[var_deref_op]
    *x = 0;

The comment automatically classifies the FORWARD_NULL as intentional.