All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH RESEND 0/3] easy-to-fix clang warnings
@ 2017-03-22 20:48 Philippe Mathieu-Daudé
  2017-03-22 20:48 ` [Qemu-devel] [PATCH RESEND 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers Philippe Mathieu-Daudé
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-03-22 20:48 UTC (permalink / raw)
  To: Michael Roth, Peter Crosthwaite, Alexander Graf, Gerd Hoffmann
  Cc: Philippe Mathieu-Daudé, qemu-devel, qemu-trivial

This patchset fixes three easy-to-fix clang warnings.

Resent adding Marc-André Lureau's Reviewed-by and CC'ing qemu-trivial as
suggested by Markus Armbruster.

Philippe Mathieu-Daudé (3):
  usb-ccid: make ccid_write_data_block() cope with null buffers
  device_tree: fix compiler warnings (clang 5)
  qga: fix compiler warnings (clang 5)

 device_tree.c                 | 1 +
 hw/usb/dev-smartcard-reader.c | 8 +++++++-
 qga/commands-posix.c          | 8 +++++---
 3 files changed, 13 insertions(+), 4 deletions(-)

-- 
2.11.0

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

* [Qemu-devel] [PATCH RESEND 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers
  2017-03-22 20:48 [Qemu-devel] [PATCH RESEND 0/3] easy-to-fix clang warnings Philippe Mathieu-Daudé
@ 2017-03-22 20:48 ` Philippe Mathieu-Daudé
  2017-03-23  6:49   ` Markus Armbruster
  2017-03-22 20:48 ` [Qemu-devel] [PATCH RESEND 2/3] device_tree: fix compiler warnings (clang 5) Philippe Mathieu-Daudé
  2017-03-22 20:48 ` [Qemu-devel] [PATCH RESEND 3/3] qga: " Philippe Mathieu-Daudé
  2 siblings, 1 reply; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-03-22 20:48 UTC (permalink / raw)
  To: Michael Roth, Peter Crosthwaite, Alexander Graf, Gerd Hoffmann
  Cc: Philippe Mathieu-Daudé, qemu-devel, qemu-trivial

static code analyzer complain:

hw/usb/dev-smartcard-reader.c:816:5: warning: Null pointer passed as an argument to a 'nonnull' parameter
    memcpy(p->abData, data, len);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/usb/dev-smartcard-reader.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
index 757b8b3f5a..c38a4e5886 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -799,8 +799,14 @@ static void ccid_write_parameters(USBCCIDState *s, CCID_Header *recv)
 static void ccid_write_data_block(USBCCIDState *s, uint8_t slot, uint8_t seq,
                                   const uint8_t *data, uint32_t len)
 {
-    CCID_DataBlock *p = ccid_reserve_recv_buf(s, sizeof(*p) + len);
+    CCID_DataBlock *p;
 
+    if (len == 0) {
+        return;
+    }
+    g_assert(data != NULL);
+
+    p = ccid_reserve_recv_buf(s, sizeof(*p) + len);
     if (p == NULL) {
         return;
     }
-- 
2.11.0

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

* [Qemu-devel] [PATCH RESEND 2/3] device_tree: fix compiler warnings (clang 5)
  2017-03-22 20:48 [Qemu-devel] [PATCH RESEND 0/3] easy-to-fix clang warnings Philippe Mathieu-Daudé
  2017-03-22 20:48 ` [Qemu-devel] [PATCH RESEND 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers Philippe Mathieu-Daudé
@ 2017-03-22 20:48 ` Philippe Mathieu-Daudé
  2017-03-22 22:35   ` Marc-André Lureau
  2017-03-22 20:48 ` [Qemu-devel] [PATCH RESEND 3/3] qga: " Philippe Mathieu-Daudé
  2 siblings, 1 reply; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-03-22 20:48 UTC (permalink / raw)
  To: Michael Roth, Peter Crosthwaite, Alexander Graf, Gerd Hoffmann
  Cc: Philippe Mathieu-Daudé, qemu-devel, qemu-trivial

static code analyzer complain:

device_tree.c:155:18: warning: Null pointer passed as an argument to a 'nonnull' parameter
    while ((de = readdir(d)) != NULL) {
                 ^~~~~~~~~~

Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 device_tree.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/device_tree.c b/device_tree.c
index 6e06320830..a24ddff02b 100644
--- a/device_tree.c
+++ b/device_tree.c
@@ -148,6 +148,7 @@ static void read_fstree(void *fdt, const char *dirname)
     d = opendir(dirname);
     if (!d) {
         error_setg(&error_fatal, "%s cannot open %s", __func__, dirname);
+        return;
     }
 
     while ((de = readdir(d)) != NULL) {
-- 
2.11.0

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

* [Qemu-devel] [PATCH RESEND 3/3] qga: fix compiler warnings (clang 5)
  2017-03-22 20:48 [Qemu-devel] [PATCH RESEND 0/3] easy-to-fix clang warnings Philippe Mathieu-Daudé
  2017-03-22 20:48 ` [Qemu-devel] [PATCH RESEND 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers Philippe Mathieu-Daudé
  2017-03-22 20:48 ` [Qemu-devel] [PATCH RESEND 2/3] device_tree: fix compiler warnings (clang 5) Philippe Mathieu-Daudé
@ 2017-03-22 20:48 ` Philippe Mathieu-Daudé
  2017-03-22 21:22   ` Michael Roth
  2 siblings, 1 reply; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-03-22 20:48 UTC (permalink / raw)
  To: Michael Roth, Peter Crosthwaite, Alexander Graf, Gerd Hoffmann
  Cc: Philippe Mathieu-Daudé, qemu-devel, qemu-trivial

static code analyzer complain:

qga/commands-posix.c:2127:9: warning: Null pointer passed as an argument to a 'nonnull' parameter
        closedir(dp);
        ^~~~~~~~~~~~

Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 qga/commands-posix.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 73d93eb5ce..8028141534 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -2122,9 +2122,11 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,
          * we think this VM does not support online/offline memory block,
          * any other solution?
          */
-        if (!dp && errno == ENOENT) {
-            result->response =
-                GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
+        if (!dp) {
+            if (errno == ENOENT) {
+                result->response =
+                    GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
+            }
             goto out1;
         }
         closedir(dp);
-- 
2.11.0

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

* Re: [Qemu-devel] [PATCH RESEND 3/3] qga: fix compiler warnings (clang 5)
  2017-03-22 20:48 ` [Qemu-devel] [PATCH RESEND 3/3] qga: " Philippe Mathieu-Daudé
@ 2017-03-22 21:22   ` Michael Roth
  2017-04-07 21:31     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 15+ messages in thread
From: Michael Roth @ 2017-03-22 21:22 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé,
	Peter Crosthwaite, Alexander Graf, Gerd Hoffmann
  Cc: qemu-devel, qemu-trivial

Quoting Philippe Mathieu-Daudé (2017-03-22 15:48:44)
> static code analyzer complain:
> 
> qga/commands-posix.c:2127:9: warning: Null pointer passed as an argument to a 'nonnull' parameter
>         closedir(dp);
>         ^~~~~~~~~~~~
> 
> Reported-by: Clang Static Analyzer
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  qga/commands-posix.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 73d93eb5ce..8028141534 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -2122,9 +2122,11 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,
>           * we think this VM does not support online/offline memory block,
>           * any other solution?
>           */
> -        if (!dp && errno == ENOENT) {
> -            result->response =
> -                GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
> +        if (!dp) {
> +            if (errno == ENOENT) {
> +                result->response =
> +                    GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
> +            }
>              goto out1;
>          }

I think this should be:

    if (!dp) {
        if (errno == ENOENT) {
            result->response =
                GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
        } else {
            result->response =
                GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_FAILED;
        }
        goto out1;
    }

otherwise we might set result->error_code while still indicating
success for the operation. That wasn't handled properly before your
patch either, it's just more apparent now.

>          closedir(dp);
> -- 
> 2.11.0
> 

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

* Re: [Qemu-devel] [PATCH RESEND 2/3] device_tree: fix compiler warnings (clang 5)
  2017-03-22 20:48 ` [Qemu-devel] [PATCH RESEND 2/3] device_tree: fix compiler warnings (clang 5) Philippe Mathieu-Daudé
@ 2017-03-22 22:35   ` Marc-André Lureau
  0 siblings, 0 replies; 15+ messages in thread
From: Marc-André Lureau @ 2017-03-22 22:35 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé,
	Michael Roth, Peter Crosthwaite, Alexander Graf, Gerd Hoffmann
  Cc: qemu-trivial, qemu-devel

On Thu, Mar 23, 2017 at 12:49 AM Philippe Mathieu-Daudé <f4bug@amsat.org>
wrote:

> static code analyzer complain:
>
> device_tree.c:155:18: warning: Null pointer passed as an argument to a
> 'nonnull' parameter
>     while ((de = readdir(d)) != NULL) {
>                  ^~~~~~~~~~
>
> Reported-by: Clang Static Analyzer
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>


Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>



> ---
>  device_tree.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/device_tree.c b/device_tree.c
> index 6e06320830..a24ddff02b 100644
> --- a/device_tree.c
> +++ b/device_tree.c
> @@ -148,6 +148,7 @@ static void read_fstree(void *fdt, const char *dirname)
>      d = opendir(dirname);
>      if (!d) {
>          error_setg(&error_fatal, "%s cannot open %s", __func__, dirname);
> +        return;
>      }
>
>      while ((de = readdir(d)) != NULL) {
> --
> 2.11.0
>
>
> --
Marc-André Lureau

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

* Re: [Qemu-devel] [PATCH RESEND 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers
  2017-03-22 20:48 ` [Qemu-devel] [PATCH RESEND 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers Philippe Mathieu-Daudé
@ 2017-03-23  6:49   ` Markus Armbruster
  2017-03-23  7:43     ` Gerd Hoffmann
  0 siblings, 1 reply; 15+ messages in thread
From: Markus Armbruster @ 2017-03-23  6:49 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Michael Roth, Peter Crosthwaite, Alexander Graf, Gerd Hoffmann,
	qemu-trivial, qemu-devel

Philippe Mathieu-Daudé <f4bug@amsat.org> writes:

> static code analyzer complain:
>
> hw/usb/dev-smartcard-reader.c:816:5: warning: Null pointer passed as an argument to a 'nonnull' parameter
>     memcpy(p->abData, data, len);
>     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Reported-by: Clang Static Analyzer
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  hw/usb/dev-smartcard-reader.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
> index 757b8b3f5a..c38a4e5886 100644
> --- a/hw/usb/dev-smartcard-reader.c
> +++ b/hw/usb/dev-smartcard-reader.c
> @@ -799,8 +799,14 @@ static void ccid_write_parameters(USBCCIDState *s, CCID_Header *recv)
>  static void ccid_write_data_block(USBCCIDState *s, uint8_t slot, uint8_t seq,
>                                    const uint8_t *data, uint32_t len)
>  {
> -    CCID_DataBlock *p = ccid_reserve_recv_buf(s, sizeof(*p) + len);
> +    CCID_DataBlock *p;
>  
> +    if (len == 0) {
> +        return;

Correct only if messages without data always have the same meaning as no
message.  Gerd?

> +    }
> +    g_assert(data != NULL);

The assertion feels like noise to me.

> +
> +    p = ccid_reserve_recv_buf(s, sizeof(*p) + len);
>      if (p == NULL) {
>          return;
>      }

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

* Re: [Qemu-devel] [PATCH RESEND 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers
  2017-03-23  6:49   ` Markus Armbruster
@ 2017-03-23  7:43     ` Gerd Hoffmann
  2017-03-23  8:14       ` Marc-André Lureau
  0 siblings, 1 reply; 15+ messages in thread
From: Gerd Hoffmann @ 2017-03-23  7:43 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Philippe Mathieu-Daudé,
	Michael Roth, Peter Crosthwaite, Alexander Graf, qemu-trivial,
	qemu-devel

  Hi,

> > +    if (len == 0) {
> > +        return;
> 
> Correct only if messages without data always have the same meaning as no
> message.  Gerd?

Not a ccid expert, but looking through the code it seems writing a
(reply) data block with status and without payload (data = NULL and len
= 0) is perfectly fine and can happen in case no (virtual) smartcard is
inserted into the card reader.  Which this patch breaks.  So,

NACK.

cheers,
  Gerd

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

* Re: [Qemu-devel] [PATCH RESEND 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers
  2017-03-23  7:43     ` Gerd Hoffmann
@ 2017-03-23  8:14       ` Marc-André Lureau
  2017-03-23  9:51         ` Gerd Hoffmann
  0 siblings, 1 reply; 15+ messages in thread
From: Marc-André Lureau @ 2017-03-23  8:14 UTC (permalink / raw)
  To: Gerd Hoffmann, Markus Armbruster
  Cc: Michael Roth, Peter Crosthwaite, qemu-trivial, Alexander Graf,
	qemu-devel, Philippe Mathieu-Daudé

Hi

On Thu, Mar 23, 2017 at 11:44 AM Gerd Hoffmann <kraxel@redhat.com> wrote:

>   Hi,
>
> > > +    if (len == 0) {
> > > +        return;
> >
> > Correct only if messages without data always have the same meaning as no
> > message.  Gerd?
>
> Not a ccid expert, but looking through the code it seems writing a
> (reply) data block with status and without payload (data = NULL and len
> = 0) is perfectly fine and can happen in case no (virtual) smartcard is
> inserted into the card reader.  Which this patch breaks.  So,
>
> NACK.
>

 oops, there are hard-coded calls with NULL/0. I suppose to fix clang
warning, it would need to check if data != null for memcpy.
-- 
Marc-André Lureau

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

* Re: [Qemu-devel] [PATCH RESEND 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers
  2017-03-23  8:14       ` Marc-André Lureau
@ 2017-03-23  9:51         ` Gerd Hoffmann
  2017-03-23 12:41           ` Markus Armbruster
  0 siblings, 1 reply; 15+ messages in thread
From: Gerd Hoffmann @ 2017-03-23  9:51 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: Markus Armbruster, Michael Roth, Peter Crosthwaite, qemu-trivial,
	Alexander Graf, qemu-devel, Philippe Mathieu-Daudé

  Hi,

>  oops, there are hard-coded calls with NULL/0. I suppose to fix clang
> warning, it would need to check if data != null for memcpy.

I'd check for len > 0, and in that if branch we can also assert on data
== NULL and thereby check that len and data are consistent.

cheers,
  Gerd

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

* Re: [Qemu-devel] [PATCH RESEND 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers
  2017-03-23  9:51         ` Gerd Hoffmann
@ 2017-03-23 12:41           ` Markus Armbruster
  2017-03-23 13:56             ` Gerd Hoffmann
  0 siblings, 1 reply; 15+ messages in thread
From: Markus Armbruster @ 2017-03-23 12:41 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: Marc-André Lureau, Michael Roth, Peter Crosthwaite,
	qemu-trivial, Alexander Graf, qemu-devel,
	Philippe Mathieu-Daudé

Gerd Hoffmann <kraxel@redhat.com> writes:

>   Hi,
>
>>  oops, there are hard-coded calls with NULL/0. I suppose to fix clang
>> warning, it would need to check if data != null for memcpy.
>
> I'd check for len > 0, and in that if branch we can also assert on data
> == NULL and thereby check that len and data are consistent.

If len is non-zero but data is null, memcpy() will crash just fine by
itself, so why bother asserting.  If len is zero, there's nothing to
assert.

I'd simply protect memcpy() with if (len) and call it a day.

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

* Re: [Qemu-devel] [PATCH RESEND 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers
  2017-03-23 12:41           ` Markus Armbruster
@ 2017-03-23 13:56             ` Gerd Hoffmann
  2017-03-23 14:08               ` Markus Armbruster
  0 siblings, 1 reply; 15+ messages in thread
From: Gerd Hoffmann @ 2017-03-23 13:56 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Marc-André Lureau, Michael Roth, Peter Crosthwaite,
	qemu-trivial, Alexander Graf, qemu-devel,
	Philippe Mathieu-Daudé

On Do, 2017-03-23 at 13:41 +0100, Markus Armbruster wrote:
> Gerd Hoffmann <kraxel@redhat.com> writes:
> 
> >   Hi,
> >
> >>  oops, there are hard-coded calls with NULL/0. I suppose to fix clang
> >> warning, it would need to check if data != null for memcpy.
> >
> > I'd check for len > 0, and in that if branch we can also assert on data
> > == NULL and thereby check that len and data are consistent.
> 
> If len is non-zero but data is null, memcpy() will crash just fine by
> itself, so why bother asserting.

To make clang happy?  But maybe clang is clever enough to figure data
can't be null at that point in case we call memcpy with len != 0
only ...

cheers,
  Gerd

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

* Re: [Qemu-devel] [PATCH RESEND 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers
  2017-03-23 13:56             ` Gerd Hoffmann
@ 2017-03-23 14:08               ` Markus Armbruster
  2017-04-07 21:33                 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 15+ messages in thread
From: Markus Armbruster @ 2017-03-23 14:08 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: Michael Roth, Peter Crosthwaite, qemu-trivial, Alexander Graf,
	qemu-devel, Marc-André Lureau, Philippe Mathieu-Daudé

Gerd Hoffmann <kraxel@redhat.com> writes:

> On Do, 2017-03-23 at 13:41 +0100, Markus Armbruster wrote:
>> Gerd Hoffmann <kraxel@redhat.com> writes:
>> 
>> >   Hi,
>> >
>> >>  oops, there are hard-coded calls with NULL/0. I suppose to fix clang
>> >> warning, it would need to check if data != null for memcpy.
>> >
>> > I'd check for len > 0, and in that if branch we can also assert on data
>> > == NULL and thereby check that len and data are consistent.
>> 
>> If len is non-zero but data is null, memcpy() will crash just fine by
>> itself, so why bother asserting.
>
> To make clang happy?  But maybe clang is clever enough to figure data
> can't be null at that point in case we call memcpy with len != 0
> only ...

If Clang needs another hint to become happy, then an assertion is a fine
way to provide it.

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

* Re: [Qemu-devel] [PATCH RESEND 3/3] qga: fix compiler warnings (clang 5)
  2017-03-22 21:22   ` Michael Roth
@ 2017-04-07 21:31     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-04-07 21:31 UTC (permalink / raw)
  To: Michael Roth
  Cc: Peter Crosthwaite, Alexander Graf, Gerd Hoffmann, qemu-trivial,
	qemu-devel

Hi Michael,

On 03/22/2017 06:22 PM, Michael Roth wrote:
> Quoting Philippe Mathieu-Daudé (2017-03-22 15:48:44)
>> static code analyzer complain:
>>
>> qga/commands-posix.c:2127:9: warning: Null pointer passed as an argument to a 'nonnull' parameter
>>         closedir(dp);
>>         ^~~~~~~~~~~~
>>
>> Reported-by: Clang Static Analyzer
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> ---
>>  qga/commands-posix.c | 8 +++++---
>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
>> index 73d93eb5ce..8028141534 100644
>> --- a/qga/commands-posix.c
>> +++ b/qga/commands-posix.c
>> @@ -2122,9 +2122,11 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,
>>           * we think this VM does not support online/offline memory block,
>>           * any other solution?
>>           */
>> -        if (!dp && errno == ENOENT) {
>> -            result->response =
>> -                GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
>> +        if (!dp) {
>> +            if (errno == ENOENT) {
>> +                result->response =
>> +                    GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
>> +            }
>>              goto out1;
>>          }
>
> I think this should be:
>
>     if (!dp) {
>         if (errno == ENOENT) {
>             result->response =
>                 GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_NOT_SUPPORTED;
>         } else {
>             result->response =
>                 GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_FAILED;
>         }
>         goto out1;
>     }
>
> otherwise we might set result->error_code while still indicating
> success for the operation. That wasn't handled properly before your
> patch either, it's just more apparent now.

Indeed, I'll resend it in 2 patches It seems easier to me to understand.

>
>>          closedir(dp);
>> --
>> 2.11.0
>>
>
>

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

* Re: [Qemu-devel] [PATCH RESEND 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers
  2017-03-23 14:08               ` Markus Armbruster
@ 2017-04-07 21:33                 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 15+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-04-07 21:33 UTC (permalink / raw)
  To: Markus Armbruster, Gerd Hoffmann
  Cc: Michael Roth, Peter Crosthwaite, qemu-trivial, Alexander Graf,
	qemu-devel, Marc-André Lureau

Hi Markus, Gerd.

On 03/23/2017 11:08 AM, Markus Armbruster wrote:
> Gerd Hoffmann <kraxel@redhat.com> writes:
>
>> On Do, 2017-03-23 at 13:41 +0100, Markus Armbruster wrote:
>>> Gerd Hoffmann <kraxel@redhat.com> writes:
>>>
>>>>   Hi,
>>>>
>>>>>  oops, there are hard-coded calls with NULL/0. I suppose to fix clang
>>>>> warning, it would need to check if data != null for memcpy.
>>>>
>>>> I'd check for len > 0, and in that if branch we can also assert on data
>>>> == NULL and thereby check that len and data are consistent.
>>>
>>> If len is non-zero but data is null, memcpy() will crash just fine by
>>> itself, so why bother asserting.
>>
>> To make clang happy?  But maybe clang is clever enough to figure data
>> can't be null at that point in case we call memcpy with len != 0
>> only ...
>
> If Clang needs another hint to become happy, then an assertion is a fine
> way to provide it.

Apparently Clang isn't clever enough using an assertion.

I'll resend checking len.

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

end of thread, other threads:[~2017-04-07 21:33 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-22 20:48 [Qemu-devel] [PATCH RESEND 0/3] easy-to-fix clang warnings Philippe Mathieu-Daudé
2017-03-22 20:48 ` [Qemu-devel] [PATCH RESEND 1/3] usb-ccid: make ccid_write_data_block() cope with null buffers Philippe Mathieu-Daudé
2017-03-23  6:49   ` Markus Armbruster
2017-03-23  7:43     ` Gerd Hoffmann
2017-03-23  8:14       ` Marc-André Lureau
2017-03-23  9:51         ` Gerd Hoffmann
2017-03-23 12:41           ` Markus Armbruster
2017-03-23 13:56             ` Gerd Hoffmann
2017-03-23 14:08               ` Markus Armbruster
2017-04-07 21:33                 ` Philippe Mathieu-Daudé
2017-03-22 20:48 ` [Qemu-devel] [PATCH RESEND 2/3] device_tree: fix compiler warnings (clang 5) Philippe Mathieu-Daudé
2017-03-22 22:35   ` Marc-André Lureau
2017-03-22 20:48 ` [Qemu-devel] [PATCH RESEND 3/3] qga: " Philippe Mathieu-Daudé
2017-03-22 21:22   ` Michael Roth
2017-04-07 21:31     ` Philippe Mathieu-Daudé

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.