From 3e994809a1c00ca52fe45e598323e54db18cb90c Mon Sep 17 00:00:00 2001 From: Zhongyi Xie Date: Fri, 3 May 2019 09:58:12 -0700 Subject: [PATCH] fix implicit conversion error reported by clang check (#5277) Summary: fix the following clang check errors ``` tools/db_stress.cc:3609:30: error: implicit conversion loses integer precision: 'std::vector::size_type' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32] int num_keys = rand_keys.size(); ~~~~~~~~ ~~~~~~~~~~^~~~~~ tools/db_stress.cc:3888:30: error: implicit conversion loses integer precision: 'std::vector::size_type' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32] int num_keys = rand_keys.size(); ~~~~~~~~ ~~~~~~~~~~^~~~~~ 2 errors generated. make: *** [tools/db_stress.o] Error 1 ``` Pull Request resolved: https://github.com/facebook/rocksdb/pull/5277 Differential Revision: D15196620 Pulled By: miasantreble fbshipit-source-id: d56b1420d4a9f1df875fc52877a5fbb342bc7cae --- tools/db_stress.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/db_stress.cc b/tools/db_stress.cc index 97755fe96..4ed66ed6d 100644 --- a/tools/db_stress.cc +++ b/tools/db_stress.cc @@ -3606,7 +3606,7 @@ class BatchedOpsStressTest : public StressTest { const ReadOptions& readoptions, const std::vector& rand_column_families, const std::vector& rand_keys) { - int num_keys = rand_keys.size(); + size_t num_keys = rand_keys.size(); std::vector statuses(num_keys); std::string keys[10] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; for (int key = 0; key < 10; ++key) { @@ -3618,13 +3618,13 @@ class BatchedOpsStressTest : public StressTest { std::string from_db; ColumnFamilyHandle* cfh = column_families_[rand_column_families[0]]; - for (int rand_key = 0; rand_key < num_keys; ++rand_key) { + for (size_t rand_key = 0; rand_key < num_keys; ++rand_key) { key_str.emplace_back(keys[key] + Key(rand_keys[rand_key])); key_slices.emplace_back(key_str.back()); } db_->MultiGet(readoptionscopy, cfh, num_keys, key_slices.data(), values.data(), statuses.data()); - for (int i = 0; i < num_keys; i++) { + for (size_t i = 0; i < num_keys; i++) { Status s = statuses[i]; if (!s.ok() && !s.IsNotFound()) { fprintf(stderr, "get error: %s\n", s.ToString().c_str()); @@ -3651,7 +3651,7 @@ class BatchedOpsStressTest : public StressTest { db_->ReleaseSnapshot(readoptionscopy.snapshot); // Now that we retrieved all values, check that they all match - for (int i = 1; i < num_keys; i++) { + for (size_t i = 1; i < num_keys; i++) { if (values[i] != values[0]) { fprintf(stderr, "error : inconsistent values for key %s: %s, %s\n", key_str[i].c_str(), @@ -3885,14 +3885,14 @@ class AtomicFlushStressTest : public StressTest { const ReadOptions& read_opts, const std::vector& rand_column_families, const std::vector& rand_keys) { - int num_keys = rand_keys.size(); + size_t num_keys = rand_keys.size(); std::vector key_str; std::vector keys; std::vector values(num_keys); std::vector statuses(num_keys); ColumnFamilyHandle* cfh = column_families_[rand_column_families[0]]; - for (int i = 0; i < num_keys; ++i) { + for (size_t i = 0; i < num_keys; ++i) { key_str.emplace_back(Key(rand_keys[i])); keys.emplace_back(key_str.back()); }