Skip to content

Commit 35dcc58

Browse files
fix buffer overflow on all emphasis flags set (#4498)
1 parent 553ec11 commit 35dcc58

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

include/fmt/color.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ template <typename Char> struct ansi_color_escape {
430430

431431
private:
432432
static constexpr size_t num_emphases = 8;
433-
Char buffer[7u + 3u * num_emphases + 1u];
433+
Char buffer[7u + 4u * num_emphases + 1u];
434434

435435
static FMT_CONSTEXPR void to_esc(uint8_t c, Char* out,
436436
char delimiter) noexcept {

test/color-test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ TEST(color_test, format) {
113113
EXPECT_EQ(fmt::format("{}", fmt::styled("bar", fg(fmt::color::blue) |
114114
fmt::emphasis::underline)),
115115
"\x1b[4m\x1b[38;2;000;000;255mbar\x1b[0m");
116+
EXPECT_EQ(
117+
fmt::format(
118+
"{}", fmt::styled(
119+
"all", fmt::emphasis::bold | fmt::emphasis::faint |
120+
fmt::emphasis::italic |
121+
fmt::emphasis::underline | fmt::emphasis::blink |
122+
fmt::emphasis::reverse | fmt::emphasis::conceal |
123+
fmt::emphasis::strikethrough)),
124+
"\x1b[1m\x1b[2m\x1b[3m\x1b[4m\x1b[5m\x1b[7m\x1b[8m\x1b[9mall\x1b[0m");
116125
}
117126

118127
TEST(color_test, format_to) {

0 commit comments

Comments
 (0)