qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
	Juan Quintela <quintela@redhat.com>,
	peter.maydell@linaro.org,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	Fam Zheng <famz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] migration: Appease coverity, skip empty block trees
Date: Fri, 29 Jun 2018 17:36:25 -0400	[thread overview]
Message-ID: <4a80026d-b7bf-a656-4216-bab491ca69c1@redhat.com> (raw)
In-Reply-To: <20180629170709.GD16547@stefanha-x1.localdomain>



On 06/29/2018 01:07 PM, Stefan Hajnoczi wrote:
> On Fri, Jun 22, 2018 at 04:11:22PM -0400, John Snow wrote:
>> If a tree consists exclusively of implicit filter nodes, we might crash
>> QEMU. This configuration should not exist in practice, but if it did,
>> skipping it would be fine.
>>
>> For the purposes of debug builds, throw an assert to remind us that
>> this configuration is truly unexpected, but if it's compiled out we
>> will cope just fine.
>>
>> Signed-off-by: John Snow <jsnow@redhat.com>
>> ---
>>  migration/block-dirty-bitmap.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c
>> index 3bafbbdc4c..02725293dd 100644
>> --- a/migration/block-dirty-bitmap.c
>> +++ b/migration/block-dirty-bitmap.c
>> @@ -287,6 +287,10 @@ static int init_dirty_bitmap_migration(void)
>>          while (bs && bs->drv && bs->implicit) {
>>              bs = backing_bs(bs);
>>          }
>> +        if (!bs) {
>> +            g_assert_not_reached();
>> +            continue;
>> +        }
> 
> If bs can never be NULL, why test that it is non-NULL in the while loop
> condition?
> 
> Try:
> 
>   /* Precondition: bs != NULL thanks to the for loop */
>   while (bs->drv && bs->implicit) {
>       bs = backing_bs(bs);
>   }
>   /* Postcondition: bs != NULL due to implicit node layout assumption */
> 
> Does this silence Coverity?  ISTR it looks for cues like the bs check in
> the while loop condition to decide whether it's likely that a variable
> could be NULL.
> 

I'll give this a go, but mechanically it looks suspect without an
assert(bs) in the loop body, but that would definitely silence Coverity.

--js

      reply	other threads:[~2018-06-29 21:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-22 20:11 [Qemu-devel] [PATCH] migration: Appease coverity, skip empty block trees John Snow
2018-06-22 20:24 ` Philippe Mathieu-Daudé
2018-06-22 20:35   ` John Snow
2018-06-22 20:58     ` Philippe Mathieu-Daudé
2018-06-29 17:07 ` Stefan Hajnoczi
2018-06-29 21:36   ` John Snow [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4a80026d-b7bf-a656-4216-bab491ca69c1@redhat.com \
    --to=jsnow@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=famz@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).