qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Fix comparisons between implicit booleans and integers.
@ 2015-01-30 11:52 Richard W.M. Jones
  2015-01-30 12:13 ` Paolo Bonzini
  2015-02-10 19:15 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
  0 siblings, 2 replies; 4+ messages in thread
From: Richard W.M. Jones @ 2015-01-30 11:52 UTC (permalink / raw)
  To: qemu-trivial; +Cc: lersek, qemu-devel, dgilbert

In GCC 5 there is a new warning (-Wlogical-not-parentheses) which
prevents you from writing:

  if (<some implicitly boolean expression> == <an int>) ...

A typical error would be:

kvm-all.c: In function ‘kvm_set_migration_log’:
kvm-all.c:383:54: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
         if (!!(mem->flags & KVM_MEM_LOG_DIRTY_PAGES) == enable) {

Fix a few places where the build is now broken in GCC 5.

The warning isn't even consistent, as with the place in
hw/net/virtio-net.c where I had to cast an obviously boolean
expression to bool.

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
---
 hw/net/virtio-net.c | 2 +-
 kvm-all.c           | 2 +-
 qemu-img.c          | 3 ++-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 45da34a..ba6afb8 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -121,7 +121,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
     }
 
     if (!!n->vhost_started ==
-        (virtio_net_started(n, status) && !nc->peer->link_down)) {
+        (bool) (virtio_net_started(n, status) && !nc->peer->link_down)) {
         return;
     }
     if (!n->vhost_started) {
diff --git a/kvm-all.c b/kvm-all.c
index 2f21a4e..b6d4387 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -366,7 +366,7 @@ static void kvm_log_stop(MemoryListener *listener,
     }
 }
 
-static int kvm_set_migration_log(int enable)
+static int kvm_set_migration_log(bool enable)
 {
     KVMState *s = kvm_state;
     KVMSlot *mem;
diff --git a/qemu-img.c b/qemu-img.c
index 4e9a7f5..acf70fa 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -977,7 +977,8 @@ static int is_allocated_sectors_min(const uint8_t *buf, int n, int *pnum,
 static int compare_sectors(const uint8_t *buf1, const uint8_t *buf2, int n,
     int *pnum)
 {
-    int res, i;
+    bool res;
+    int i;
 
     if (n <= 0) {
         *pnum = 0;
-- 
2.2.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Fix comparisons between implicit booleans and integers.
  2015-01-30 11:52 [Qemu-devel] [PATCH] Fix comparisons between implicit booleans and integers Richard W.M. Jones
@ 2015-01-30 12:13 ` Paolo Bonzini
  2015-02-10 19:15 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
  1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2015-01-30 12:13 UTC (permalink / raw)
  To: Richard W.M. Jones, qemu-trivial; +Cc: lersek, qemu-devel, dgilbert



On 30/01/2015 12:52, Richard W.M. Jones wrote:
> In GCC 5 there is a new warning (-Wlogical-not-parentheses) which
> prevents you from writing:
> 
>   if (<some implicitly boolean expression> == <an int>) ...
> 
> A typical error would be:
> 
> kvm-all.c: In function ‘kvm_set_migration_log’:
> kvm-all.c:383:54: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
>          if (!!(mem->flags & KVM_MEM_LOG_DIRTY_PAGES) == enable) {
> 
> Fix a few places where the build is now broken in GCC 5.
> 
> The warning isn't even consistent, as with the place in
> hw/net/virtio-net.c where I had to cast an obviously boolean
> expression to bool.

The other two places are fine cleanups, but really I would just suppress
the warning in configure...

Paolo

> Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
> ---
>  hw/net/virtio-net.c | 2 +-
>  kvm-all.c           | 2 +-
>  qemu-img.c          | 3 ++-
>  3 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index 45da34a..ba6afb8 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -121,7 +121,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
>      }
>  
>      if (!!n->vhost_started ==
> -        (virtio_net_started(n, status) && !nc->peer->link_down)) {
> +        (bool) (virtio_net_started(n, status) && !nc->peer->link_down)) {
>          return;
>      }
>      if (!n->vhost_started) {
> diff --git a/kvm-all.c b/kvm-all.c
> index 2f21a4e..b6d4387 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -366,7 +366,7 @@ static void kvm_log_stop(MemoryListener *listener,
>      }
>  }
>  
> -static int kvm_set_migration_log(int enable)
> +static int kvm_set_migration_log(bool enable)
>  {
>      KVMState *s = kvm_state;
>      KVMSlot *mem;
> diff --git a/qemu-img.c b/qemu-img.c
> index 4e9a7f5..acf70fa 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -977,7 +977,8 @@ static int is_allocated_sectors_min(const uint8_t *buf, int n, int *pnum,
>  static int compare_sectors(const uint8_t *buf1, const uint8_t *buf2, int n,
>      int *pnum)
>  {
> -    int res, i;
> +    bool res;
> +    int i;
>  
>      if (n <= 0) {
>          *pnum = 0;
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH] Fix comparisons between implicit booleans and integers.
  2015-01-30 11:52 [Qemu-devel] [PATCH] Fix comparisons between implicit booleans and integers Richard W.M. Jones
  2015-01-30 12:13 ` Paolo Bonzini
@ 2015-02-10 19:15 ` Michael Tokarev
  2015-02-10 19:33   ` Richard W.M. Jones
  1 sibling, 1 reply; 4+ messages in thread
From: Michael Tokarev @ 2015-02-10 19:15 UTC (permalink / raw)
  To: Richard W.M. Jones, qemu-trivial; +Cc: lersek, qemu-devel, dgilbert

30.01.2015 14:52, Richard W.M. Jones wrote:
> In GCC 5 there is a new warning (-Wlogical-not-parentheses) which
> prevents you from writing:
> 
>   if (<some implicitly boolean expression> == <an int>) ...
> 
> A typical error would be:
> 
> kvm-all.c: In function ‘kvm_set_migration_log’:
> kvm-all.c:383:54: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
>          if (!!(mem->flags & KVM_MEM_LOG_DIRTY_PAGES) == enable) {
> 
> Fix a few places where the build is now broken in GCC 5.
> 
> The warning isn't even consistent, as with the place in
> hw/net/virtio-net.c where I had to cast an obviously boolean
> expression to bool.

Richard, I'd like to apply hunks 2 and 3, but leave out hunk 1
for now.  As a start, the hunk 1 looks a bit, well, ugly, don't
you think?  But if I just drop hunk 1, the commit message will
be a bit misleading, since it describes exactly the hunk1 change...

Thanks,

/mjt

> Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
> ---
>  hw/net/virtio-net.c | 2 +-
>  kvm-all.c           | 2 +-
>  qemu-img.c          | 3 ++-
>  3 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index 45da34a..ba6afb8 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -121,7 +121,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status)
>      }
>  
>      if (!!n->vhost_started ==
> -        (virtio_net_started(n, status) && !nc->peer->link_down)) {
> +        (bool) (virtio_net_started(n, status) && !nc->peer->link_down)) {
>          return;
>      }
>      if (!n->vhost_started) {
> diff --git a/kvm-all.c b/kvm-all.c
> index 2f21a4e..b6d4387 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -366,7 +366,7 @@ static void kvm_log_stop(MemoryListener *listener,
>      }
>  }
>  
> -static int kvm_set_migration_log(int enable)
> +static int kvm_set_migration_log(bool enable)
>  {
>      KVMState *s = kvm_state;
>      KVMSlot *mem;
> diff --git a/qemu-img.c b/qemu-img.c
> index 4e9a7f5..acf70fa 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -977,7 +977,8 @@ static int is_allocated_sectors_min(const uint8_t *buf, int n, int *pnum,
>  static int compare_sectors(const uint8_t *buf1, const uint8_t *buf2, int n,
>      int *pnum)
>  {
> -    int res, i;
> +    bool res;
> +    int i;
>  
>      if (n <= 0) {
>          *pnum = 0;
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH] Fix comparisons between implicit booleans and integers.
  2015-02-10 19:15 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
@ 2015-02-10 19:33   ` Richard W.M. Jones
  0 siblings, 0 replies; 4+ messages in thread
From: Richard W.M. Jones @ 2015-02-10 19:33 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: qemu-trivial, lersek, qemu-devel, dgilbert

On Tue, Feb 10, 2015 at 10:15:35PM +0300, Michael Tokarev wrote:
> 30.01.2015 14:52, Richard W.M. Jones wrote:
> > In GCC 5 there is a new warning (-Wlogical-not-parentheses) which
> > prevents you from writing:
> > 
> >   if (<some implicitly boolean expression> == <an int>) ...
> > 
> > A typical error would be:
> > 
> > kvm-all.c: In function ‘kvm_set_migration_log’:
> > kvm-all.c:383:54: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
> >          if (!!(mem->flags & KVM_MEM_LOG_DIRTY_PAGES) == enable) {
> > 
> > Fix a few places where the build is now broken in GCC 5.
> > 
> > The warning isn't even consistent, as with the place in
> > hw/net/virtio-net.c where I had to cast an obviously boolean
> > expression to bool.
> 
> Richard, I'd like to apply hunks 2 and 3, but leave out hunk 1
> for now.  As a start, the hunk 1 looks a bit, well, ugly, don't
> you think?  But if I just drop hunk 1, the commit message will
> be a bit misleading, since it describes exactly the hunk1 change...

Please feel free to apply and bits and modify the commit message as
you wish.  I just want qemu to be fixed on gcc 5, I don't care how we
get there :-)

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-02-10 19:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-30 11:52 [Qemu-devel] [PATCH] Fix comparisons between implicit booleans and integers Richard W.M. Jones
2015-01-30 12:13 ` Paolo Bonzini
2015-02-10 19:15 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2015-02-10 19:33   ` Richard W.M. Jones

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).