Skip to content

Commit

Permalink
Merge pull request #17 from speedb-io/15-fault_injection_fs-avoid-div…
Browse files Browse the repository at this point in the history
…ision-by-zero-in-droprandomunsynceddata

#15 SPDB-720: fault_injection_fs: avoid division by zero in DropRandomUns…
  • Loading branch information
Yuval-Ariel authored Jun 23, 2022
2 parents 1525822 + e225fd1 commit 7a5089d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions utilities/fault_injection_fs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ IOStatus FSFileState::DropUnsyncedData() {
}

IOStatus FSFileState::DropRandomUnsyncedData(Random* rand) {
int range = static_cast<int>(buffer_.size());
size_t truncated_size = static_cast<size_t>(rand->Uniform(range));
buffer_.resize(truncated_size);
const int range = static_cast<int>(buffer_.size());
if (range > 0) {
size_t truncated_size = static_cast<size_t>(rand->Uniform(range));
buffer_.resize(truncated_size);
}
return IOStatus::OK();
}

Expand Down

0 comments on commit 7a5089d

Please sign in to comment.