diff mbox series

[1/4] vmdk: fix maybe uninitialized warnings

Message ID 20200930155859.303148-2-borntraeger@de.ibm.com (mailing list archive)
State New, archived
Headers show
Series assorted gcc 10/fedora32 compile warning fixes | expand

Commit Message

Christian Borntraeger Sept. 30, 2020, 3:58 p.m. UTC
Fedora 32 gcc 10 seems to give false positives:

Compiling C object libblock.fa.p/block_vmdk.c.o
../block/vmdk.c: In function ‘vmdk_parse_extents’:
../block/vmdk.c:587:5: error: ‘extent’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  587 |     g_free(extent->l1_table);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~
../block/vmdk.c:754:17: note: ‘extent’ was declared here
  754 |     VmdkExtent *extent;
      |                 ^~~~~~
../block/vmdk.c:620:11: error: ‘extent’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  620 |     ret = vmdk_init_tables(bs, extent, errp);
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../block/vmdk.c:598:17: note: ‘extent’ was declared here
  598 |     VmdkExtent *extent;
      |                 ^~~~~~
../block/vmdk.c:1178:39: error: ‘extent’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 1178 |             extent->flat_start_offset = flat_offset << 9;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
../block/vmdk.c: In function ‘vmdk_open_vmdk4’:
../block/vmdk.c:581:22: error: ‘extent’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  581 |     extent->l2_cache =
      |     ~~~~~~~~~~~~~~~~~^
  582 |         g_malloc(extent->entry_size * extent->l2_size * L2_CACHE_SIZE);
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../block/vmdk.c:872:17: note: ‘extent’ was declared here
  872 |     VmdkExtent *extent;
      |                 ^~~~~~
../block/vmdk.c: In function ‘vmdk_open’:
../block/vmdk.c:620:11: error: ‘extent’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  620 |     ret = vmdk_init_tables(bs, extent, errp);
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../block/vmdk.c:598:17: note: ‘extent’ was declared here
  598 |     VmdkExtent *extent;
      |                 ^~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile.ninja:884: libblock.fa.p/block_vmdk.c.o] Error 1

fix them by assigning a default value.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 block/vmdk.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Fam Sept. 30, 2020, 4:36 p.m. UTC | #1
On Wed, 2020-09-30 at 17:58 +0200, Christian Borntraeger wrote:
> Fedora 32 gcc 10 seems to give false positives:
> 
> Compiling C object libblock.fa.p/block_vmdk.c.o
> ../block/vmdk.c: In function ‘vmdk_parse_extents’:
> ../block/vmdk.c:587:5: error: ‘extent’ may be used uninitialized in
> this function [-Werror=maybe-uninitialized]
>   587 |     g_free(extent->l1_table);
>       |     ^~~~~~~~~~~~~~~~~~~~~~~~
> ../block/vmdk.c:754:17: note: ‘extent’ was declared here
>   754 |     VmdkExtent *extent;
>       |                 ^~~~~~
> ../block/vmdk.c:620:11: error: ‘extent’ may be used uninitialized in
> this function [-Werror=maybe-uninitialized]
>   620 |     ret = vmdk_init_tables(bs, extent, errp);
>       |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../block/vmdk.c:598:17: note: ‘extent’ was declared here
>   598 |     VmdkExtent *extent;
>       |                 ^~~~~~
> ../block/vmdk.c:1178:39: error: ‘extent’ may be used uninitialized in
> this function [-Werror=maybe-uninitialized]
>  1178 |             extent->flat_start_offset = flat_offset << 9;
>       |             ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
> ../block/vmdk.c: In function ‘vmdk_open_vmdk4’:
> ../block/vmdk.c:581:22: error: ‘extent’ may be used uninitialized in
> this function [-Werror=maybe-uninitialized]
>   581 |     extent->l2_cache =
>       |     ~~~~~~~~~~~~~~~~~^
>   582 |         g_malloc(extent->entry_size * extent->l2_size *
> L2_CACHE_SIZE);
>       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~~~~~~
> ../block/vmdk.c:872:17: note: ‘extent’ was declared here
>   872 |     VmdkExtent *extent;
>       |                 ^~~~~~
> ../block/vmdk.c: In function ‘vmdk_open’:
> ../block/vmdk.c:620:11: error: ‘extent’ may be used uninitialized in
> this function [-Werror=maybe-uninitialized]
>   620 |     ret = vmdk_init_tables(bs, extent, errp);
>       |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../block/vmdk.c:598:17: note: ‘extent’ was declared here
>   598 |     VmdkExtent *extent;
>       |                 ^~~~~~
> cc1: all warnings being treated as errors
> make: *** [Makefile.ninja:884: libblock.fa.p/block_vmdk.c.o] Error 1
> 
> fix them by assigning a default value.
> 
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  block/vmdk.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/block/vmdk.c b/block/vmdk.c
> index 8ec62c7ab798..a00dc00eb47a 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -595,7 +595,7 @@ static int vmdk_open_vmfs_sparse(BlockDriverState
> *bs,
>      int ret;
>      uint32_t magic;
>      VMDK3Header header;
> -    VmdkExtent *extent;
> +    VmdkExtent *extent = NULL;
>  
>      ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header));
>      if (ret < 0) {
> @@ -751,7 +751,7 @@ static int vmdk_open_se_sparse(BlockDriverState
> *bs,
>      int ret;
>      VMDKSESparseConstHeader const_header;
>      VMDKSESparseVolatileHeader volatile_header;
> -    VmdkExtent *extent;
> +    VmdkExtent *extent = NULL;
>  
>      ret = bdrv_apply_auto_read_only(bs,
>              "No write support for seSparse images available", errp);
> @@ -869,7 +869,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
>      uint32_t magic;
>      uint32_t l1_size, l1_entry_sectors;
>      VMDK4Header header;
> -    VmdkExtent *extent;
> +    VmdkExtent *extent = NULL;
>      BDRVVmdkState *s = bs->opaque;
>      int64_t l1_backup_offset = 0;
>      bool compressed;
> @@ -1088,7 +1088,7 @@ static int vmdk_parse_extents(const char *desc,
> BlockDriverState *bs,
>      BdrvChild *extent_file;
>      BdrvChildRole extent_role;
>      BDRVVmdkState *s = bs->opaque;
> -    VmdkExtent *extent;
> +    VmdkExtent *extent = NULL;
>      char extent_opt_prefix[32];
>      Error *local_err = NULL;
>  

Looks trivial, and correct.

Reviewed-by: Fam Zheng <fam@euphon.net>
Christian Borntraeger Oct. 5, 2020, 6:26 a.m. UTC | #2
On 30.09.20 18:36, Fam Zheng wrote:
> On Wed, 2020-09-30 at 17:58 +0200, Christian Borntraeger wrote:
>> Fedora 32 gcc 10 seems to give false positives:
>>
>> Compiling C object libblock.fa.p/block_vmdk.c.o
>> ../block/vmdk.c: In function ‘vmdk_parse_extents’:
>> ../block/vmdk.c:587:5: error: ‘extent’ may be used uninitialized in
>> this function [-Werror=maybe-uninitialized]
>>   587 |     g_free(extent->l1_table);
>>       |     ^~~~~~~~~~~~~~~~~~~~~~~~
>> ../block/vmdk.c:754:17: note: ‘extent’ was declared here
>>   754 |     VmdkExtent *extent;
>>       |                 ^~~~~~
>> ../block/vmdk.c:620:11: error: ‘extent’ may be used uninitialized in
>> this function [-Werror=maybe-uninitialized]
>>   620 |     ret = vmdk_init_tables(bs, extent, errp);
>>       |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> ../block/vmdk.c:598:17: note: ‘extent’ was declared here
>>   598 |     VmdkExtent *extent;
>>       |                 ^~~~~~
>> ../block/vmdk.c:1178:39: error: ‘extent’ may be used uninitialized in
>> this function [-Werror=maybe-uninitialized]
>>  1178 |             extent->flat_start_offset = flat_offset << 9;
>>       |             ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
>> ../block/vmdk.c: In function ‘vmdk_open_vmdk4’:
>> ../block/vmdk.c:581:22: error: ‘extent’ may be used uninitialized in
>> this function [-Werror=maybe-uninitialized]
>>   581 |     extent->l2_cache =
>>       |     ~~~~~~~~~~~~~~~~~^
>>   582 |         g_malloc(extent->entry_size * extent->l2_size *
>> L2_CACHE_SIZE);
>>       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> ~~~~~~~~~
>> ../block/vmdk.c:872:17: note: ‘extent’ was declared here
>>   872 |     VmdkExtent *extent;
>>       |                 ^~~~~~
>> ../block/vmdk.c: In function ‘vmdk_open’:
>> ../block/vmdk.c:620:11: error: ‘extent’ may be used uninitialized in
>> this function [-Werror=maybe-uninitialized]
>>   620 |     ret = vmdk_init_tables(bs, extent, errp);
>>       |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> ../block/vmdk.c:598:17: note: ‘extent’ was declared here
>>   598 |     VmdkExtent *extent;
>>       |                 ^~~~~~
>> cc1: all warnings being treated as errors
>> make: *** [Makefile.ninja:884: libblock.fa.p/block_vmdk.c.o] Error 1
>>
>> fix them by assigning a default value.
>>
>> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
>> ---
>>  block/vmdk.c | 8 ++++----
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/block/vmdk.c b/block/vmdk.c
>> index 8ec62c7ab798..a00dc00eb47a 100644
>> --- a/block/vmdk.c
>> +++ b/block/vmdk.c
>> @@ -595,7 +595,7 @@ static int vmdk_open_vmfs_sparse(BlockDriverState
>> *bs,
>>      int ret;
>>      uint32_t magic;
>>      VMDK3Header header;
>> -    VmdkExtent *extent;
>> +    VmdkExtent *extent = NULL;
>>  
>>      ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header));
>>      if (ret < 0) {
>> @@ -751,7 +751,7 @@ static int vmdk_open_se_sparse(BlockDriverState
>> *bs,
>>      int ret;
>>      VMDKSESparseConstHeader const_header;
>>      VMDKSESparseVolatileHeader volatile_header;
>> -    VmdkExtent *extent;
>> +    VmdkExtent *extent = NULL;
>>  
>>      ret = bdrv_apply_auto_read_only(bs,
>>              "No write support for seSparse images available", errp);
>> @@ -869,7 +869,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
>>      uint32_t magic;
>>      uint32_t l1_size, l1_entry_sectors;
>>      VMDK4Header header;
>> -    VmdkExtent *extent;
>> +    VmdkExtent *extent = NULL;
>>      BDRVVmdkState *s = bs->opaque;
>>      int64_t l1_backup_offset = 0;
>>      bool compressed;
>> @@ -1088,7 +1088,7 @@ static int vmdk_parse_extents(const char *desc,
>> BlockDriverState *bs,
>>      BdrvChild *extent_file;
>>      BdrvChildRole extent_role;
>>      BDRVVmdkState *s = bs->opaque;
>> -    VmdkExtent *extent;
>> +    VmdkExtent *extent = NULL;
>>      char extent_opt_prefix[32];
>>      Error *local_err = NULL;
>>  
> 
> Looks trivial, and correct.
> 
> Reviewed-by: Fam Zheng <fam@euphon.net>


Will this go via the block or trivial tree (cced).
Laurent Vivier Oct. 12, 2020, 2:16 p.m. UTC | #3
Le 05/10/2020 à 08:26, Christian Borntraeger a écrit :
> On 30.09.20 18:36, Fam Zheng wrote:
>> On Wed, 2020-09-30 at 17:58 +0200, Christian Borntraeger wrote:
>>> Fedora 32 gcc 10 seems to give false positives:
>>>
>>> Compiling C object libblock.fa.p/block_vmdk.c.o
>>> ../block/vmdk.c: In function ‘vmdk_parse_extents’:
>>> ../block/vmdk.c:587:5: error: ‘extent’ may be used uninitialized in
>>> this function [-Werror=maybe-uninitialized]
>>>   587 |     g_free(extent->l1_table);
>>>       |     ^~~~~~~~~~~~~~~~~~~~~~~~
>>> ../block/vmdk.c:754:17: note: ‘extent’ was declared here
>>>   754 |     VmdkExtent *extent;
>>>       |                 ^~~~~~
>>> ../block/vmdk.c:620:11: error: ‘extent’ may be used uninitialized in
>>> this function [-Werror=maybe-uninitialized]
>>>   620 |     ret = vmdk_init_tables(bs, extent, errp);
>>>       |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> ../block/vmdk.c:598:17: note: ‘extent’ was declared here
>>>   598 |     VmdkExtent *extent;
>>>       |                 ^~~~~~
>>> ../block/vmdk.c:1178:39: error: ‘extent’ may be used uninitialized in
>>> this function [-Werror=maybe-uninitialized]
>>>  1178 |             extent->flat_start_offset = flat_offset << 9;
>>>       |             ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
>>> ../block/vmdk.c: In function ‘vmdk_open_vmdk4’:
>>> ../block/vmdk.c:581:22: error: ‘extent’ may be used uninitialized in
>>> this function [-Werror=maybe-uninitialized]
>>>   581 |     extent->l2_cache =
>>>       |     ~~~~~~~~~~~~~~~~~^
>>>   582 |         g_malloc(extent->entry_size * extent->l2_size *
>>> L2_CACHE_SIZE);
>>>       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> ~~~~~~~~~
>>> ../block/vmdk.c:872:17: note: ‘extent’ was declared here
>>>   872 |     VmdkExtent *extent;
>>>       |                 ^~~~~~
>>> ../block/vmdk.c: In function ‘vmdk_open’:
>>> ../block/vmdk.c:620:11: error: ‘extent’ may be used uninitialized in
>>> this function [-Werror=maybe-uninitialized]
>>>   620 |     ret = vmdk_init_tables(bs, extent, errp);
>>>       |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> ../block/vmdk.c:598:17: note: ‘extent’ was declared here
>>>   598 |     VmdkExtent *extent;
>>>       |                 ^~~~~~
>>> cc1: all warnings being treated as errors
>>> make: *** [Makefile.ninja:884: libblock.fa.p/block_vmdk.c.o] Error 1
>>>
>>> fix them by assigning a default value.
>>>
>>> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
>>> ---
>>>  block/vmdk.c | 8 ++++----
>>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/block/vmdk.c b/block/vmdk.c
>>> index 8ec62c7ab798..a00dc00eb47a 100644
>>> --- a/block/vmdk.c
>>> +++ b/block/vmdk.c
>>> @@ -595,7 +595,7 @@ static int vmdk_open_vmfs_sparse(BlockDriverState
>>> *bs,
>>>      int ret;
>>>      uint32_t magic;
>>>      VMDK3Header header;
>>> -    VmdkExtent *extent;
>>> +    VmdkExtent *extent = NULL;
>>>  
>>>      ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header));
>>>      if (ret < 0) {
>>> @@ -751,7 +751,7 @@ static int vmdk_open_se_sparse(BlockDriverState
>>> *bs,
>>>      int ret;
>>>      VMDKSESparseConstHeader const_header;
>>>      VMDKSESparseVolatileHeader volatile_header;
>>> -    VmdkExtent *extent;
>>> +    VmdkExtent *extent = NULL;
>>>  
>>>      ret = bdrv_apply_auto_read_only(bs,
>>>              "No write support for seSparse images available", errp);
>>> @@ -869,7 +869,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
>>>      uint32_t magic;
>>>      uint32_t l1_size, l1_entry_sectors;
>>>      VMDK4Header header;
>>> -    VmdkExtent *extent;
>>> +    VmdkExtent *extent = NULL;
>>>      BDRVVmdkState *s = bs->opaque;
>>>      int64_t l1_backup_offset = 0;
>>>      bool compressed;
>>> @@ -1088,7 +1088,7 @@ static int vmdk_parse_extents(const char *desc,
>>> BlockDriverState *bs,
>>>      BdrvChild *extent_file;
>>>      BdrvChildRole extent_role;
>>>      BDRVVmdkState *s = bs->opaque;
>>> -    VmdkExtent *extent;
>>> +    VmdkExtent *extent = NULL;
>>>      char extent_opt_prefix[32];
>>>      Error *local_err = NULL;
>>>  
>>
>> Looks trivial, and correct.
>>
>> Reviewed-by: Fam Zheng <fam@euphon.net>
> 
> 
> Will this go via the block or trivial tree (cced). 
> 

Applied to my trivial-patches branch.

Thanks,
Laurent
diff mbox series

Patch

diff --git a/block/vmdk.c b/block/vmdk.c
index 8ec62c7ab798..a00dc00eb47a 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -595,7 +595,7 @@  static int vmdk_open_vmfs_sparse(BlockDriverState *bs,
     int ret;
     uint32_t magic;
     VMDK3Header header;
-    VmdkExtent *extent;
+    VmdkExtent *extent = NULL;
 
     ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header));
     if (ret < 0) {
@@ -751,7 +751,7 @@  static int vmdk_open_se_sparse(BlockDriverState *bs,
     int ret;
     VMDKSESparseConstHeader const_header;
     VMDKSESparseVolatileHeader volatile_header;
-    VmdkExtent *extent;
+    VmdkExtent *extent = NULL;
 
     ret = bdrv_apply_auto_read_only(bs,
             "No write support for seSparse images available", errp);
@@ -869,7 +869,7 @@  static int vmdk_open_vmdk4(BlockDriverState *bs,
     uint32_t magic;
     uint32_t l1_size, l1_entry_sectors;
     VMDK4Header header;
-    VmdkExtent *extent;
+    VmdkExtent *extent = NULL;
     BDRVVmdkState *s = bs->opaque;
     int64_t l1_backup_offset = 0;
     bool compressed;
@@ -1088,7 +1088,7 @@  static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
     BdrvChild *extent_file;
     BdrvChildRole extent_role;
     BDRVVmdkState *s = bs->opaque;
-    VmdkExtent *extent;
+    VmdkExtent *extent = NULL;
     char extent_opt_prefix[32];
     Error *local_err = NULL;