Fix Clang static analyzer warning in db_bench (#4910)

Summary:
Fixed clang static analyzer warning about division by 0.
```
ar: creating librocksdb_debug.a
tools/db_bench_tool.cc:4650:43: warning: Division by zero
      int pos = static_cast<int>(rand_num % range_);
                                 ~~~~~~~~~^~~~~~~~
1 warning generated.
make: *** [analyze] Error 1
```

This is from the new code I recently merged in ce8e88d2d7.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4910

Differential Revision: D13788037

Pulled By: sagar0

fbshipit-source-id: f48851dca85047c19fbb1a361e25ce643aa4c7ea
main
Sagar Vemuri 6 years ago committed by Facebook Github Bot
parent 5bf941966b
commit 0cead31d10
  1. 1
      tools/db_bench_tool.cc

@ -4647,6 +4647,7 @@ void VerifyDBFromDB(std::string& truth_db_name) {
if (rand_num < 0) { if (rand_num < 0) {
rand_num = rand_num * (-1); rand_num = rand_num * (-1);
} }
assert(range_ != 0);
int pos = static_cast<int>(rand_num % range_); int pos = static_cast<int>(rand_num % range_);
for (int i = 0; i < static_cast<int>(type_.size()); i++) { for (int i = 0; i < static_cast<int>(type_.size()); i++) {
if (pos < type_[i]) { if (pos < type_[i]) {

Loading…
Cancel
Save