[Qemu-devel] [PATCH] tests/check-qdict: Fix missing brackets

Dr. David Alan Gilbert (git) posted 1 patch 7 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20170406154107.9178-1-dgilbert@redhat.com
Test checkpatch passed
Test docker passed
Test s390x passed
tests/check-qdict.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[Qemu-devel] [PATCH] tests/check-qdict: Fix missing brackets
Posted by Dr. David Alan Gilbert (git) 7 years ago
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Gcc 7 (on Fedora 26) spotted odd use of integers instead of a
boolean; it's got a point.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 tests/check-qdict.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/check-qdict.c b/tests/check-qdict.c
index 81162ee572..6f3fbcf9c1 100644
--- a/tests/check-qdict.c
+++ b/tests/check-qdict.c
@@ -559,7 +559,7 @@ static void qdict_join_test(void)
         g_assert(qdict_size(dict1) == 2);
         g_assert(qdict_size(dict2) == !overwrite);
 
-        g_assert(qdict_get_int(dict1, "foo") == overwrite ? 84 : 42);
+        g_assert(qdict_get_int(dict1, "foo") == (overwrite ? 84 : 42));
         g_assert(qdict_get_int(dict1, "bar") == 23);
 
         if (!overwrite) {
-- 
2.12.2


Re: [Qemu-devel] [PATCH] tests/check-qdict: Fix missing brackets
Posted by Eric Blake 7 years ago
On 04/06/2017 10:41 AM, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> 
> Gcc 7 (on Fedora 26) spotted odd use of integers instead of a
> boolean; it's got a point.
> 
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
>  tests/check-qdict.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/check-qdict.c b/tests/check-qdict.c
> index 81162ee572..6f3fbcf9c1 100644
> --- a/tests/check-qdict.c
> +++ b/tests/check-qdict.c
> @@ -559,7 +559,7 @@ static void qdict_join_test(void)
>          g_assert(qdict_size(dict1) == 2);
>          g_assert(qdict_size(dict2) == !overwrite);
>  
> -        g_assert(qdict_get_int(dict1, "foo") == overwrite ? 84 : 42);
> +        g_assert(qdict_get_int(dict1, "foo") == (overwrite ? 84 : 42));

How is the test passing pre-patch, and why does it not change the test
post-patch?  Does that mean that overwrite is not doing what we expected?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Re: [Qemu-devel] [PATCH] tests/check-qdict: Fix missing brackets
Posted by Dr. David Alan Gilbert 7 years ago
* Eric Blake (eblake@redhat.com) wrote:
> On 04/06/2017 10:41 AM, Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> > 
> > Gcc 7 (on Fedora 26) spotted odd use of integers instead of a
> > boolean; it's got a point.
> > 
> > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> > ---
> >  tests/check-qdict.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/tests/check-qdict.c b/tests/check-qdict.c
> > index 81162ee572..6f3fbcf9c1 100644
> > --- a/tests/check-qdict.c
> > +++ b/tests/check-qdict.c
> > @@ -559,7 +559,7 @@ static void qdict_join_test(void)
> >          g_assert(qdict_size(dict1) == 2);
> >          g_assert(qdict_size(dict2) == !overwrite);
> >  
> > -        g_assert(qdict_get_int(dict1, "foo") == overwrite ? 84 : 42);
> > +        g_assert(qdict_get_int(dict1, "foo") == (overwrite ? 84 : 42));
> 
> How is the test passing pre-patch, and why does it not change the test
> post-patch?  Does that mean that overwrite is not doing what we expected?

Pre-patch it passes because either 84 or 42  are valid 'true' values into g_assert.
Post patch it ends up as either:
    qdict_get_int(dict1, "foo") == 42
or
    qdict_get_int(dict1, "foo") == 84

which is what's intended.

Dave

> -- 
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
> 



--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK