From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] tests: unit: add NULL-pointer check
Date: Tue, 06 Sep 2022 07:01:35 +0200 [thread overview]
Message-ID: <87pmg96qq8.fsf@pond.sub.org> (raw)
In-Reply-To: <20220905111038.33324-1-pbonzini@redhat.com> (Paolo Bonzini's message of "Mon, 5 Sep 2022 13:10:38 +0200")
Paolo Bonzini <pbonzini@redhat.com> writes:
> In CID 1432593, Coverity complains that the result of qdict_crumple()
> might leak if it is not a dictionary. This is not a practical concern
> since the test would fail immediately with a NULL pointer dereference
> in qdict_size().
>
> However, it is not nice to depend on qdict_size() crashing, so add an
> explicit assertion that that the crumpled object was indeed a dictionary.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> tests/unit/check-block-qdict.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tests/unit/check-block-qdict.c b/tests/unit/check-block-qdict.c
> index 5a25825093..751c58e737 100644
> --- a/tests/unit/check-block-qdict.c
> +++ b/tests/unit/check-block-qdict.c
> @@ -504,7 +504,7 @@ static void qdict_crumple_test_empty(void)
> src = qdict_new();
>
> dst = qobject_to(QDict, qdict_crumple(src, &error_abort));
> -
> + g_assert(dst);
> g_assert_cmpint(qdict_size(dst), ==, 0);
>
> qobject_unref(src);
First, I'm fine with the patch, so
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Next, permit me a few words on writing tests. For me, a unit test fails
by crashing. Crashing with a nice message is optional. The more likely
the failure, the more useful is niceness. Complete niceness is
impossible --- if we could predict all crashes, we wouldn't need tests.
Trying to push niceness can be overly verbose. Thus, judgement calls,
and matters of taste.
Wanting to mollify Coverity is a valid argument.
next prev parent reply other threads:[~2022-09-06 5:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-05 11:10 [PATCH] tests: unit: add NULL-pointer check Paolo Bonzini
2022-09-05 15:19 ` Alex Bennée
2022-09-06 5:01 ` Markus Armbruster [this message]
2022-09-06 6:07 ` Paolo Bonzini
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=87pmg96qq8.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.