diff mbox

[13/13] qapi: Add missing null check to opts_start_struct()

Message ID 1392042045-31525-14-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster Feb. 10, 2014, 2:20 p.m. UTC
Argument is null when visiting an unboxed struct.  I can't see such a
visit in the current code.  Fix it anyway.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 qapi/opts-visitor.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Eric Blake Feb. 10, 2014, 3:28 p.m. UTC | #1
On 02/10/2014 07:20 AM, Markus Armbruster wrote:
> Argument is null when visiting an unboxed struct.  I can't see such a
> visit in the current code.  Fix it anyway.

Is this a sign of missing testsuite coverage?

> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  qapi/opts-visitor.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

> 
> diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
> index 96ed858..5d830a2 100644
> --- a/qapi/opts-visitor.c
> +++ b/qapi/opts-visitor.c
> @@ -124,7 +124,9 @@ opts_start_struct(Visitor *v, void **obj, const char *kind,
>      OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v);
>      const QemuOpt *opt;
>  
> -    *obj = g_malloc0(size > 0 ? size : 1);
> +    if (obj) {
> +        *obj = g_malloc0(size > 0 ? size : 1);
> +    }
>      if (ov->depth++ > 0) {
>          return;
>      }
>
Paolo Bonzini Feb. 13, 2014, 9:30 a.m. UTC | #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Il 10/02/2014 16:28, Eric Blake ha scritto:
| On 02/10/2014 07:20 AM, Markus Armbruster wrote:
|> Argument is null when visiting an unboxed struct.  I can't see
|> such a visit in the current code.  Fix it anyway.
|
| Is this a sign of missing testsuite coverage?

Yes, likely.

Paolo

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJS/JDBAAoJEBvWZb6bTYbyAq4QAIH0kuK64lI9F0QeSYdC7vXZ
UFbccRz3sZXl7VBZXPpJNUOtEYsw/UXYYxEKXWedVUTWF7YWORe6fzd377Eti2w1
O8roausYt6J1czWnoufp8hsjBQJz72ydxEIDRWK1ip+8V0ZEqlbO4TSRRkZXNz1b
dFn5A3TsW0nKGLyZiD8LxA5mdI3WLAuUDV3zWXQstovLFrG4/cqQv4zyyIRh7zG6
bDzPx4zmswRynedwcet2i8atZFhgdWvjx1OouuKLqMK/9aRVuThwiKPwWjyrwhkr
o4QKEdHlNZZbCvbrqB+4XizRyqhW61uf3JylPcH/SGgLGXHxLyutciC4FosJE5js
CPpsq5edPWJM07eKYiisBwt4CU6P+8hrhMtJ+Yo1P3WyMgdwGTQHyqDk/ZDUq+pM
3Hmwi36DALBSnIfmeTndgzVXbPtJe4W87ndBmx9UpXNnUDzgkVd0Kfje+NU7lsLv
tgROyQmhhoc/e5VuClV6C/2tILsx8gEGEacbSS/FTnZGUlnoTSlpenGrSLLcCHpy
alkmNDP/D+reYE7BV9zvSojBJOPNNKS0qQ1Y5528+sr8XsbuaaL3UQCE0oQHjCAK
iPYyfkzCyTgB3iFHVxunEQ+j6oaMkbY28YJTnIUsr6jOWpWlT3pW3VMEekmjcZi2
CF0f7RztKQtHglYyuFgW
=IAMx
-----END PGP SIGNATURE-----
diff mbox

Patch

diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
index 96ed858..5d830a2 100644
--- a/qapi/opts-visitor.c
+++ b/qapi/opts-visitor.c
@@ -124,7 +124,9 @@  opts_start_struct(Visitor *v, void **obj, const char *kind,
     OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v);
     const QemuOpt *opt;
 
-    *obj = g_malloc0(size > 0 ? size : 1);
+    if (obj) {
+        *obj = g_malloc0(size > 0 ? size : 1);
+    }
     if (ov->depth++ > 0) {
         return;
     }