From fdaf2670da2243cbb57a1bf0ed9df6ee72b75990 Mon Sep 17 00:00:00 2001 From: mrambacher Date: Tue, 14 Feb 2023 17:47:55 -0500 Subject: [PATCH] Add back accidental revert in DropRandomUnsyncedData Code was accidentally dropped during recent PR --- utilities/fault_injection_fs.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utilities/fault_injection_fs.cc b/utilities/fault_injection_fs.cc index 2bd2384060..343b68bec6 100644 --- a/utilities/fault_injection_fs.cc +++ b/utilities/fault_injection_fs.cc @@ -83,9 +83,11 @@ IOStatus FSFileState::DropUnsyncedData() { } IOStatus FSFileState::DropRandomUnsyncedData(Random* rand) { - int range = static_cast(buffer_.size()); - size_t truncated_size = static_cast(rand->Uniform(range)); - buffer_.resize(truncated_size); + const int range = static_cast(buffer_.size()); + if (range > 0) { + size_t truncated_size = static_cast(rand->Uniform(range)); + buffer_.resize(truncated_size); + } return IOStatus::OK(); }