Skip to content

Commit

Permalink
fmt: Fix C++ string assertion when buf is empty
Browse files Browse the repository at this point in the history
Signed-off-by: gatecat <gatecat@ds0.me>
  • Loading branch information
gatecat committed Sep 12, 2023
1 parent 88ce47e commit 98b9459
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion kernel/fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 98b9459

Please sign in to comment.