From c63bdba955d19281b5fc8b07c03194c739b40781 Mon Sep 17 00:00:00 2001 From: SeekingBlues Date: Wed, 13 Oct 2021 19:58:48 -0400 Subject: [PATCH] shuf: Fix division by zero when no lines are read --- Userland/Utilities/shuf.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Userland/Utilities/shuf.cpp b/Userland/Utilities/shuf.cpp index 2833f7d383..d1a216c5ca 100644 --- a/Userland/Utilities/shuf.cpp +++ b/Userland/Utilities/shuf.cpp @@ -36,6 +36,9 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) } free(buffer); + if (lines.is_empty()) + return 0; + // Fisher-Yates shuffle String tmp; for (size_t i = lines.size() - 1; i >= 1; --i) {