Skip to contentSkip to conversation

qcow2: Fix signedness bugs

PATCH Applied Kevin Wolf 3 participants 3 messages Feb 2, 2010 – Feb 10, 2010 Block layer

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 qcow2: Fix signedness bugs

Checking for return codes < 0 isn't really going to work with unsigned types. Use signed types instead.

---
 block/qcow2-cluster.c |   12 ++++++------
 block/qcow2.h         |    6 ++----
 2 files changed, 8 insertions(+), 10 deletions(-)
block/qcow2-cluster.c +6 -6
index 4e30d16..3501a94 100644
@@ -219,7 +219,8 @@ static uint64_t *l2_allocate(BlockDriverState *bs, int l1_index)
     BDRVQcowState *s = bs->opaque;
     int min_index;
     uint64_t old_l2_offset;
-    uint64_t *l2_table, l2_offset;
+    uint64_t *l2_table;
+    int64_t l2_offset;
 
     old_l2_offset = s->l1_table[l1_index];
 
@@ -560,7 +561,8 @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
 {
     BDRVQcowState *s = bs->opaque;
     int l2_index, ret;
-    uint64_t l2_offset, *l2_table, cluster_offset;
+    uint64_t l2_offset, *l2_table;
+    int64_t cluster_offset;
     int nb_csectors;
 
     ret = get_cluster_table(bs, offset, &l2_table, &l2_offset, &l2_index);
@@ -704,10 +706,8 @@ err:
  *
  * Return 0 on success and -errno in error cases
  */
-uint64_t qcow2_alloc_cluster_offset(BlockDriverState *bs,
-                                    uint64_t offset,
-                                    int n_start, int n_end,
-                                    int *num, QCowL2Meta *m)
+int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
+    int n_start, int n_end, int *num, QCowL2Meta *m)
 {
     BDRVQcowState *s = bs->opaque;
     int l2_index, ret;
block/qcow2.h +2 -4
index d9ea6ab..de9397a 100644
@@ -192,10 +192,8 @@ void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
 
 uint64_t qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
     int *num);
-uint64_t qcow2_alloc_cluster_offset(BlockDriverState *bs,
-                              uint64_t offset,
-                              int n_start, int n_end,
-                              int *num, QCowL2Meta *m);
+int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
+    int n_start, int n_end, int *num, QCowL2Meta *m);
 uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
                                          uint64_t offset,
                                          int compressed_size);
Signature · 1 line
1.6.5.2
#1 lore raw
Quoted 2 lines · Kevin Wolf

Checking for return codes < 0 isn't really going to work with unsigned types. Use signed types instead.

Makes sense to me.

#2 lore raw
In reply to Kevin Wolf
Quoted 5 lines · Kevin Wolf

Checking for return codes< 0 isn't really going to work with unsigned types. Use signed types instead.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 60 lines
---
  block/qcow2-cluster.c |   12 ++++++------
  block/qcow2.h         |    6 ++----
  2 files changed, 8 insertions(+), 10 deletions(-)
block/qcow2-cluster.c +6 -6
index 4e30d16..3501a94 100644
@@ -219,7 +219,8 @@ static uint64_t *l2_allocate(BlockDriverState *bs, int l1_index)
      BDRVQcowState *s = bs->opaque;
      int min_index;
      uint64_t old_l2_offset;
-    uint64_t *l2_table, l2_offset;
+    uint64_t *l2_table;
+    int64_t l2_offset;
 
      old_l2_offset = s->l1_table[l1_index];
 
@@ -560,7 +561,8 @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
  {
      BDRVQcowState *s = bs->opaque;
      int l2_index, ret;
-    uint64_t l2_offset, *l2_table, cluster_offset;
+    uint64_t l2_offset, *l2_table;
+    int64_t cluster_offset;
      int nb_csectors;
 
      ret = get_cluster_table(bs, offset,&l2_table,&l2_offset,&l2_index);
@@ -704,10 +706,8 @@ err:
   *
   * Return 0 on success and -errno in error cases
   */
-uint64_t qcow2_alloc_cluster_offset(BlockDriverState *bs,
-                                    uint64_t offset,
-                                    int n_start, int n_end,
-                                    int *num, QCowL2Meta *m)
+int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
+    int n_start, int n_end, int *num, QCowL2Meta *m)
  {
      BDRVQcowState *s = bs->opaque;
      int l2_index, ret;
block/qcow2.h +2 -4
index d9ea6ab..de9397a 100644
@@ -192,10 +192,8 @@ void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
 
  uint64_t qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
      int *num);
-uint64_t qcow2_alloc_cluster_offset(BlockDriverState *bs,
-                              uint64_t offset,
-                              int n_start, int n_end,
-                              int *num, QCowL2Meta *m);
+int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
+    int n_start, int n_end, int *num, QCowL2Meta *m);
  uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
                                           uint64_t offset,
                                           int compressed_size);