vnc: fix coverity warning
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
@@ -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
Quoted 14 lines · Gerd Hoffmann
vnc_display_local_addrwill not be called with an invalid display id. Addassert()to silence coverity warning about a null pointer dereference.Signed-off-by Gerd Hoffmann <[email protected]>--- ui/vnc.c | 1 + 1 file changed, 1 insertion(+)ui/vnc.c +0
-0
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
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
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.