* [Qemu-devel] [PATCH] vnc: fix coverity warning
@ 2015-02-11 16:37 Gerd Hoffmann
2015-02-11 16:41 ` Paolo Bonzini
0 siblings, 1 reply; 4+ messages in thread
From: Gerd Hoffmann @ 2015-02-11 16:37 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Gerd Hoffmann, Anthony Liguori
vnc_display_local_addr will not be called with an invalid display id.
Add assert() to silence coverity warning about a null pointer dereference.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
ui/vnc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/ui/vnc.c b/ui/vnc.c
index e291987..25ba340 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -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);
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] vnc: fix coverity warning
2015-02-11 16:37 [Qemu-devel] [PATCH] vnc: fix coverity warning Gerd Hoffmann
@ 2015-02-11 16:41 ` Paolo Bonzini
2015-02-11 16:48 ` Gerd Hoffmann
0 siblings, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2015-02-11 16:41 UTC (permalink / raw)
To: Gerd Hoffmann, qemu-devel; +Cc: Anthony Liguori
On 11/02/2015 17:37, Gerd Hoffmann wrote:
> vnc_display_local_addr will not be called with an invalid display id.
> Add assert() to silence coverity warning about a null pointer dereference.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> ui/vnc.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/ui/vnc.c b/ui/vnc.c
> index e291987..25ba340 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] vnc: fix coverity warning
2015-02-11 16:41 ` Paolo Bonzini
@ 2015-02-11 16:48 ` Gerd Hoffmann
2015-02-12 9:27 ` Markus Armbruster
0 siblings, 1 reply; 4+ messages in thread
From: Gerd Hoffmann @ 2015-02-11 16:48 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel, Anthony Liguori
> > + 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] vnc: fix coverity warning
2015-02-11 16:48 ` Gerd Hoffmann
@ 2015-02-12 9:27 ` Markus Armbruster
0 siblings, 0 replies; 4+ messages in thread
From: Markus Armbruster @ 2015-02-12 9:27 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: Paolo Bonzini, qemu-devel, Anthony Liguori
Gerd Hoffmann <kraxel@redhat.com> writes:
>> > + 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).
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-02-12 9:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-11 16:37 [Qemu-devel] [PATCH] vnc: fix coverity warning Gerd Hoffmann
2015-02-11 16:41 ` Paolo Bonzini
2015-02-11 16:48 ` Gerd Hoffmann
2015-02-12 9:27 ` Markus Armbruster
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).