Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/board/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ static bool draw_string_walk(Canvas* canvas, const Font* font,
char_params.x = x_offset + p->x;
have_space =
draw_char_impl(canvas, &char_params, &x_offset, NULL, img, measure);
str_write++;
/* A rejected glyph was not drawn. Leave str_write on it so the caller's
* completeness result cannot report that a clipped final glyph fitted. */
if (have_space) {
str_write++;
}
}

if (!measure) {
Expand Down
12 changes: 12 additions & 0 deletions unittests/board/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ TEST_F(BodyFits, ConfirmBodyFits) {
const std::string eighty_w(80, 'W');
EXPECT_TRUE(confirm_body_fits(eighty_w.c_str(), BODY_WIDTH));
EXPECT_FALSE(confirm_body_fits(eighty_w.c_str(), BODY_WIDTH_WITH_ICON));

// Regression: draw_string_walk() advanced str_write unconditionally, so a
// REJECTED final glyph was still consumed and the walk then saw '\0' and
// reported that everything fitted. The failure is exactly one glyph wide,
// which is why the earlier three-way sweep of 3,510 bodies missed it: it only
// shows at the precise boundary. 117 digits fill three rows; the 118th is the
// first glyph that cannot be placed and must be reported as not fitting.
std::string digits;
for (size_t i = 0; i < 118; i++) digits += "0123456789"[i % 10];
EXPECT_TRUE(confirm_body_fits(digits.substr(0, 117).c_str(), BODY_WIDTH));
EXPECT_FALSE(confirm_body_fits(digits.c_str(), BODY_WIDTH))
<< "a body overflowing by exactly one glyph must not report as fitting";
}

// Regression: calc_str_line() accumulated into a uint8_t while returning
Expand Down
Loading