]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: always initialize variable
authorKefu Chai <kchai@redhat.com>
Fri, 30 Jul 2021 09:31:46 +0000 (17:31 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 30 Jul 2021 10:53:09 +0000 (18:53 +0800)
actually, target_size is always initialized as `id` should be
`BlueFS::BDEV_NEWWAL` or `BlueFS::BDEV_NEWDB`. and it is ensured by

ceph_assert(id == BlueFS::BDEV_NEWWAL || id == BlueFS::BDEV_NEWDB)

at the beginning of `BlueStore::migrate_to_new_bluefs_device()`.

but apparently, GCC is not able to figure this out:

../src/os/bluestore/BlueStore.cc: In member function ‘int BlueStore::migrate_to_new_bluefs_device(const std::set<int>&, int, const string&)’:
../src/os/bluestore/BlueStore.cc:6876:35: warning: ‘target_size’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 6876 |   r = _setup_block_symlink_or_file(
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
 6877 |     target_name,
      |     ~~~~~~~~~~~~
 6878 |     dev_path,
      |     ~~~~~~~~~
 6879 |     target_size,
      |     ~~~~~~~~~~~~
 6880 |     true);
      |     ~~~~~

in this change, target_size is always initialized to a known value to
silence the warning.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/os/bluestore/BlueStore.cc

index cd3d33329ff7d3356d3020c2ec5484c30f9212d9..28db74787fcfc1285508675c40b2585d15c6dfc6 100644 (file)
@@ -6814,7 +6814,7 @@ int BlueStore::migrate_to_new_bluefs_device(const set<int>& devs_source,
     bluefs_layout.dedicated_wal = false;
   }
 
-  size_t target_size;
+  size_t target_size = 0;
   string target_name;
   if (id == BlueFS::BDEV_NEWWAL) {
     target_name = "block.wal";