Re: [libvirt] [PATCH python] Avoid comparing boolean and integers

2017-08-10 Thread Daniel P. Berrange
On Wed, Aug 09, 2017 at 02:17:10PM -0500, Eric Blake wrote:
> On 08/09/2017 11:07 AM, Daniel P. Berrange wrote:
> > Signed-off-by: Daniel P. Berrange 
> > ---
> >  libvirt-utils.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Did you get a compiler that complained?

Yes, gcc 7 complains.

> > 
> > diff --git a/libvirt-utils.c b/libvirt-utils.c
> > index 727397d..0af13dc 100644
> > --- a/libvirt-utils.c
> > +++ b/libvirt-utils.c
> > @@ -108,7 +108,7 @@ virReallocN(void *ptrptr,
> >  return -1;
> >  }
> >  tmp = realloc(*(void**)ptrptr, size * count);
> > -if (!tmp && (size * count)) {
> > +if (!tmp && ((size * count) != 0)) {
> 
> Do you need the extra (), or will one of these shorter forms also work?
> 
> if (!tmp && size * count != 0)
> if (!tmp && (size * count) != 0)

I feel the extra () aid in readability, because you don't have to
try to remember precedence rules which many people don't remember
accurately.

Regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH python] Avoid comparing boolean and integers

2017-08-09 Thread Eric Blake
On 08/09/2017 11:07 AM, Daniel P. Berrange wrote:
> Signed-off-by: Daniel P. Berrange 
> ---
>  libvirt-utils.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Did you get a compiler that complained?

> 
> diff --git a/libvirt-utils.c b/libvirt-utils.c
> index 727397d..0af13dc 100644
> --- a/libvirt-utils.c
> +++ b/libvirt-utils.c
> @@ -108,7 +108,7 @@ virReallocN(void *ptrptr,
>  return -1;
>  }
>  tmp = realloc(*(void**)ptrptr, size * count);
> -if (!tmp && (size * count)) {
> +if (!tmp && ((size * count) != 0)) {

Do you need the extra (), or will one of these shorter forms also work?

if (!tmp && size * count != 0)
if (!tmp && (size * count) != 0)

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH python] Avoid comparing boolean and integers

2017-08-09 Thread Daniel P. Berrange
Signed-off-by: Daniel P. Berrange 
---
 libvirt-utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libvirt-utils.c b/libvirt-utils.c
index 727397d..0af13dc 100644
--- a/libvirt-utils.c
+++ b/libvirt-utils.c
@@ -108,7 +108,7 @@ virReallocN(void *ptrptr,
 return -1;
 }
 tmp = realloc(*(void**)ptrptr, size * count);
-if (!tmp && (size * count)) {
+if (!tmp && ((size * count) != 0)) {
 return -1;
 }
 *(void**)ptrptr = tmp;
-- 
2.13.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list