From 2cbe559e4abd0f1488ffb6d24371034860fa551e Mon Sep 17 00:00:00 2001 From: autoantwort <41973254+autoantwort@users.noreply.github.com> Date: Tue, 14 Nov 2023 21:22:46 +0100 Subject: [PATCH] create_github_issue: Fix div by zero (#1275) --- 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();