diff options
author | Benny Baumann <BenBE@geshi.org> | 2024-03-22 09:47:34 +0100 |
---|---|---|
committer | Benny Baumann <BenBE@geshi.org> | 2024-03-22 09:47:34 +0100 |
commit | c7bfe749fceb4025f281f05661f9b9d762d8f411 (patch) | |
tree | 43fe0ae1a6faf152573480c3b1bc2004ab5769fc | |
parent | 95f77eb28bbc7afa4c847515cbcb91909d7fa061 (diff) |
Check for sufficient buffer space only after clamping
The clamping itself has a sanity check when debug mode is active.
-rw-r--r-- | Row.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -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) |