From 0cead31d102d8e183037768b95a04b0ac03844a4 Mon Sep 17 00:00:00 2001 From: Sagar Vemuri Date: Wed, 23 Jan 2019 13:26:03 -0800 Subject: [PATCH] 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(rand_num % range_); ~~~~~~~~~^~~~~~~~ 1 warning generated. make: *** [analyze] Error 1 ``` This is from the new code I recently merged in ce8e88d2d7a62e2a08c4109aac84cb9e95ed359b. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4910 Differential Revision: D13788037 Pulled By: sagar0 fbshipit-source-id: f48851dca85047c19fbb1a361e25ce643aa4c7ea --- tools/db_bench_tool.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/db_bench_tool.cc b/tools/db_bench_tool.cc index 7f4d84025..eaae6018e 100644 --- a/tools/db_bench_tool.cc +++ b/tools/db_bench_tool.cc @@ -4647,6 +4647,7 @@ void VerifyDBFromDB(std::string& truth_db_name) { if (rand_num < 0) { rand_num = rand_num * (-1); } + assert(range_ != 0); int pos = static_cast(rand_num % range_); for (int i = 0; i < static_cast(type_.size()); i++) { if (pos < type_[i]) {