Skip to content

Commit 0555427

Browse files
BenBEsegabor
authored andcommitted
Check for sufficient buffer space only after clamping
The clamping itself has a sanity check when debug mode is active.
1 parent b7ae5d0 commit 0555427

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Row.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,10 @@ void Row_printLeftAlignedField(RichString* str, int attr, const char* content, u
442442
}
443443

444444
int Row_printPercentage(float val, char* buffer, size_t n, uint8_t width, int* attr) {
445-
assert(width >= 4 && width < n && "Invalid width in Row_printPercentage()");
445+
assert(n >= 6 && width >= 4 && "Invalid width in Row_printPercentage()");
446446
// truncate in favour of abort in xSnprintf()
447-
width = (uint8_t)CLAMP(width, 4, n - 1);
447+
width = (uint8_t)CLAMP(width, 4, n - 2);
448+
assert(width < n - 1 && "Insuficient space to print column");
448449

449450
if (isNonnegative(val)) {
450451
if (val < 0.05F)

0 commit comments

Comments
 (0)