From 98b9459535681a0c3a4739f208a32dfc50c9bfea Mon Sep 17 00:00:00 2001 From: gatecat Date: Tue, 12 Sep 2023 18:12:07 +0200 Subject: [PATCH] fmt: Fix C++ string assertion when buf is empty Signed-off-by: gatecat --- kernel/fmt.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/fmt.cc b/kernel/fmt.cc index 69bdbb013b0..965e58ebce4 100644 --- a/kernel/fmt.cc +++ b/kernel/fmt.cc @@ -740,7 +740,7 @@ std::string Fmt::render() const log_assert(part.width == 0 || part.padding != '\0'); if (part.justify == FmtPart::RIGHT && buf.size() < part.width) { size_t pad_width = part.width - buf.size(); - if (part.padding == '0' && (buf.front() == '+' || buf.front() == '-')) { + if (part.padding == '0' && (!buf.empty() && (buf.front() == '+' || buf.front() == '-'))) { str += buf.front(); buf.erase(0, 1); }