Skip to content

Commit

Permalink
Check width in Row_printPercentage()
Browse files Browse the repository at this point in the history
The passed width should always be at least 4, otherwise printing will
always truncate and lead to an abort().

The passed should not be greater or equal to the available buffer size,
otherwise printing will always truncate and lead to an abort().

Add fallback for non debug builds.
  • Loading branch information
cgzones authored and segabor committed Mar 23, 2024
1 parent c30bd34 commit 205486b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Row.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +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()");
// truncate in favour of abort in xSnprintf()
width = (uint8_t)CLAMP(width, 4, n - 1);

if (isNonnegative(val)) {
if (val < 0.05F)
*attr = CRT_colors[PROCESS_SHADOW];
Expand Down

0 comments on commit 205486b

Please sign in to comment.