diff mbox

[v2] block: Fix compiler warning (-Werror=uninitialized)

Message ID 1379830750-23801-1-git-send-email-sw@weilnetz.de
State Accepted
Headers show

Commit Message

Stefan Weil Sept. 22, 2013, 6:19 a.m. UTC
The patch fixes a warning from gcc (Debian 4.6.3-14+rpi1) 4.6.3:

block/stream.c:141:22: error:
‘copy’ may be used uninitialized in this function [-Werror=uninitialized]

This is not a real bug - a better compiler would not complain.

Now 'copy' has always a defined value, so the check for ret >= 0
can be removed.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---

v2:

As noted by Andreas Färber, 'copy' must be set to false after the goto label.
Thanks for this hint.

Regards,
Stefan

 block/stream.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Stefan Hajnoczi Sept. 23, 2013, 12:12 p.m. UTC | #1
On Sun, Sep 22, 2013 at 08:19:10AM +0200, Stefan Weil wrote:
> The patch fixes a warning from gcc (Debian 4.6.3-14+rpi1) 4.6.3:
> 
> block/stream.c:141:22: error:
> ‘copy’ may be used uninitialized in this function [-Werror=uninitialized]
> 
> This is not a real bug - a better compiler would not complain.
> 
> Now 'copy' has always a defined value, so the check for ret >= 0
> can be removed.
> 
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
> 
> v2:
> 
> As noted by Andreas Färber, 'copy' must be set to false after the goto label.
> Thanks for this hint.
> 
> Regards,
> Stefan
> 
>  block/stream.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/block/stream.c b/block/stream.c
> index 078ce4a..45837f4 100644
> --- a/block/stream.c
> +++ b/block/stream.c
> @@ -119,11 +119,12 @@ wait:
>              break;
>          }
>  
> +        copy = false;
> +
>          ret = bdrv_is_allocated(bs, sector_num,
>                                  STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n);
>          if (ret == 1) {
>              /* Allocated in the top, no need to copy.  */
> -            copy = false;
>          } else if (ret >= 0) {
>              /* Copy if allocated in the intermediate images.  Limit to the
>               * known-unallocated area [sector_num, sector_num+n).  */
> @@ -138,7 +139,7 @@ wait:
>              copy = (ret == 1);
>          }
>          trace_stream_one_iteration(s, sector_num, n, ret);
> -        if (ret >= 0 && copy) {
> +        if (copy) {
>              if (s->common.speed) {
>                  delay_ns = ratelimit_calculate_delay(&s->limit, n);
>                  if (delay_ns > 0) {
> -- 
> 1.7.10.4

Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Kevin Wolf Sept. 25, 2013, 11:28 a.m. UTC | #2
Am 22.09.2013 um 08:19 hat Stefan Weil geschrieben:
> The patch fixes a warning from gcc (Debian 4.6.3-14+rpi1) 4.6.3:
> 
> block/stream.c:141:22: error:
> ‘copy’ may be used uninitialized in this function [-Werror=uninitialized]
> 
> This is not a real bug - a better compiler would not complain.
> 
> Now 'copy' has always a defined value, so the check for ret >= 0
> can be removed.
> 
> Signed-off-by: Stefan Weil <sw@weilnetz.de>

Thanks, applied to the block branch.

Kevin
diff mbox

Patch

diff --git a/block/stream.c b/block/stream.c
index 078ce4a..45837f4 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -119,11 +119,12 @@  wait:
             break;
         }
 
+        copy = false;
+
         ret = bdrv_is_allocated(bs, sector_num,
                                 STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n);
         if (ret == 1) {
             /* Allocated in the top, no need to copy.  */
-            copy = false;
         } else if (ret >= 0) {
             /* Copy if allocated in the intermediate images.  Limit to the
              * known-unallocated area [sector_num, sector_num+n).  */
@@ -138,7 +139,7 @@  wait:
             copy = (ret == 1);
         }
         trace_stream_one_iteration(s, sector_num, n, ret);
-        if (ret >= 0 && copy) {
+        if (copy) {
             if (s->common.speed) {
                 delay_ns = ratelimit_calculate_delay(&s->limit, n);
                 if (delay_ns > 0) {