Skip to content

Commit

Permalink
Check for sufficient buffer space only after clamping
Browse files Browse the repository at this point in the history
The clamping itself has a sanity check when debug mode is active.
  • Loading branch information
BenBE authored and segabor committed Mar 23, 2024
1 parent b7ae5d0 commit 0555427
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Row.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,10 @@ void Row_printLeftAlignedField(RichString* str, int attr, const char* content, u
}

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

if (isNonnegative(val)) {
if (val < 0.05F)
Expand Down

0 comments on commit 0555427

Please sign in to comment.