qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] spapr_vscsi: Set uninitialized variable
@ 2011-04-03 16:21 Stefan Weil
  2011-04-04 15:03 ` [Qemu-devel] " Alexander Graf
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Weil @ 2011-04-03 16:21 UTC (permalink / raw)
  To: Alexander Graf; +Cc: QEMU Developers

cppcheck reports this error:

hw/spapr_vscsi.c:274: error: Uninitialized variable: rc

If llen == 0, rc was indeed used without being initialized.

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 hw/spapr_vscsi.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/spapr_vscsi.c b/hw/spapr_vscsi.c
index e142dae..9928334 100644
--- a/hw/spapr_vscsi.c
+++ b/hw/spapr_vscsi.c
@@ -255,7 +255,7 @@ static int vscsi_srp_direct_data(VSCSIState *s, vscsi_req *req,
 {
     struct srp_direct_buf *md = req->cur_desc;
     uint32_t llen;
-    int rc;
+    int rc = 0;
 
     dprintf("VSCSI: direct segment 0x%x bytes, va=0x%llx desc len=0x%x\n",
             len, (unsigned long long)md->va, md->len);
-- 
1.7.2.5

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

* [Qemu-devel] Re: [PATCH] spapr_vscsi: Set uninitialized variable
  2011-04-03 16:21 [Qemu-devel] [PATCH] spapr_vscsi: Set uninitialized variable Stefan Weil
@ 2011-04-04 15:03 ` Alexander Graf
  2011-04-05  4:14   ` David Gibson
  0 siblings, 1 reply; 5+ messages in thread
From: Alexander Graf @ 2011-04-04 15:03 UTC (permalink / raw)
  To: Stefan Weil; +Cc: QEMU Developers, David Gibson

On 04/03/2011 06:21 PM, Stefan Weil wrote:
> cppcheck reports this error:
>
> hw/spapr_vscsi.c:274: error: Uninitialized variable: rc
>
> If llen == 0, rc was indeed used without being initialized.
>
> Signed-off-by: Stefan Weil<weil@mail.berlios.de>
> ---
>   hw/spapr_vscsi.c |    2 +-
>   1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/hw/spapr_vscsi.c b/hw/spapr_vscsi.c
> index e142dae..9928334 100644
> --- a/hw/spapr_vscsi.c
> +++ b/hw/spapr_vscsi.c
> @@ -255,7 +255,7 @@ static int vscsi_srp_direct_data(VSCSIState *s, vscsi_req *req,
>   {
>       struct srp_direct_buf *md = req->cur_desc;
>       uint32_t llen;
> -    int rc;
> +    int rc = 0;

David, is this correct? Or would rc be -1 when !llen?


Alex

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

* [Qemu-devel] Re: [PATCH] spapr_vscsi: Set uninitialized variable
  2011-04-04 15:03 ` [Qemu-devel] " Alexander Graf
@ 2011-04-05  4:14   ` David Gibson
  2011-04-05  5:04     ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 5+ messages in thread
From: David Gibson @ 2011-04-05  4:14 UTC (permalink / raw)
  To: Alexander Graf; +Cc: QEMU Developers

On Mon, Apr 04, 2011 at 05:03:44PM +0200, Alexander Graf wrote:
> On 04/03/2011 06:21 PM, Stefan Weil wrote:
> >cppcheck reports this error:
> >
> >hw/spapr_vscsi.c:274: error: Uninitialized variable: rc
> >
> >If llen == 0, rc was indeed used without being initialized.
> >
> >Signed-off-by: Stefan Weil<weil@mail.berlios.de>
> >---
> >  hw/spapr_vscsi.c |    2 +-
> >  1 files changed, 1 insertions(+), 1 deletions(-)
> >
> >diff --git a/hw/spapr_vscsi.c b/hw/spapr_vscsi.c
> >index e142dae..9928334 100644
> >--- a/hw/spapr_vscsi.c
> >+++ b/hw/spapr_vscsi.c
> >@@ -255,7 +255,7 @@ static int vscsi_srp_direct_data(VSCSIState *s, vscsi_req *req,
> >  {
> >      struct srp_direct_buf *md = req->cur_desc;
> >      uint32_t llen;
> >-    int rc;
> >+    int rc = 0;
> 
> David, is this correct? Or would rc be -1 when !llen?

I talked to Ben, who wrote this code - apparently his mail server blew
up.  This patch should be correct, AFAWCT.  It's not totally clear
what the right return value should be in thie case, or indeed that
this case ever actually happens, but we think 0 is right.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

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

* [Qemu-devel] Re: [PATCH] spapr_vscsi: Set uninitialized variable
  2011-04-05  4:14   ` David Gibson
@ 2011-04-05  5:04     ` Benjamin Herrenschmidt
  2011-04-05  7:55       ` Alexander Graf
  0 siblings, 1 reply; 5+ messages in thread
From: Benjamin Herrenschmidt @ 2011-04-05  5:04 UTC (permalink / raw)
  To: David Gibson; +Cc: Alexander Graf, QEMU Developers


On Tue, 2011-04-05 at 14:14 +1000, David Gibson wrote:
> > >@@ -255,7 +255,7 @@ static int vscsi_srp_direct_data(VSCSIState *s,
> vscsi_req *req,
> > >  {
> > >      struct srp_direct_buf *md = req->cur_desc;
> > >      uint32_t llen;
> > >-    int rc;
> > >+    int rc = 0;
> > 
> > David, is this correct? Or would rc be -1 when !llen?
> 
> I talked to Ben, who wrote this code - apparently his mail server blew
> up.  This patch should be correct, AFAWCT.  It's not totally clear
> what the right return value should be in thie case, or indeed that
> this case ever actually happens, but we think 0 is right. 

Just double checked and we never call that function if len is 0

Cheers,
Ben.

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

* [Qemu-devel] Re: [PATCH] spapr_vscsi: Set uninitialized variable
  2011-04-05  5:04     ` Benjamin Herrenschmidt
@ 2011-04-05  7:55       ` Alexander Graf
  0 siblings, 0 replies; 5+ messages in thread
From: Alexander Graf @ 2011-04-05  7:55 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: QEMU Developers, David Gibson


On 05.04.2011, at 07:04, Benjamin Herrenschmidt wrote:

> 
> On Tue, 2011-04-05 at 14:14 +1000, David Gibson wrote:
>>>> @@ -255,7 +255,7 @@ static int vscsi_srp_direct_data(VSCSIState *s,
>> vscsi_req *req,
>>>> {
>>>>     struct srp_direct_buf *md = req->cur_desc;
>>>>     uint32_t llen;
>>>> -    int rc;
>>>> +    int rc = 0;
>>> 
>>> David, is this correct? Or would rc be -1 when !llen?
>> 
>> I talked to Ben, who wrote this code - apparently his mail server blew
>> up.  This patch should be correct, AFAWCT.  It's not totally clear
>> what the right return value should be in thie case, or indeed that
>> this case ever actually happens, but we think 0 is right. 
> 
> Just double checked and we never call that function if len is 0

That's probably the reason gcc didn't complain before. So I'll just take Stefan's patch.


Alex

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

end of thread, other threads:[~2011-04-05  7:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-03 16:21 [Qemu-devel] [PATCH] spapr_vscsi: Set uninitialized variable Stefan Weil
2011-04-04 15:03 ` [Qemu-devel] " Alexander Graf
2011-04-05  4:14   ` David Gibson
2011-04-05  5:04     ` Benjamin Herrenschmidt
2011-04-05  7:55       ` Alexander Graf

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