From 1455ae67ce7b10d1935ff7fefffc4bb0b309bdf2 Mon Sep 17 00:00:00 2001 From: Leander Schulten Date: Mon, 13 Nov 2023 03:12:22 +0100 Subject: [PATCH] create_github_issue: Fix div by zero --- src/vcpkg-test/issue_body.cpp | 5 +++++ src/vcpkg/commands.build.cpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/vcpkg-test/issue_body.cpp b/src/vcpkg-test/issue_body.cpp index a68d33d928..686e93df66 100644 --- a/src/vcpkg-test/issue_body.cpp +++ b/src/vcpkg-test/issue_body.cpp @@ -52,6 +52,11 @@ TEST_CASE ("Testing append_log", "[github-issue-body]") TEST_CASE ("Testing append_log extra_size", "[github-issue-body]") { using namespace vcpkg; + { + std::string out; + append_logs({}, 500, out); + CHECK(out == ""); + } { std::string out; std::vector> logs{ diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index 87a0d7e3f9..94ea38118a 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -1533,6 +1533,10 @@ namespace vcpkg void append_logs(std::vector>&& logs, size_t max_size, std::string& out) { + if (logs.empty()) + { + return; + } Util::sort(logs, [](const auto& left, const auto& right) { return left.second.size() < right.second.size(); }); auto size_per_log = max_size / logs.size(); size_t maximum = out.size();