summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenny Baumann <BenBE@geshi.org>2024-03-22 09:47:34 +0100
committerBenny Baumann <BenBE@geshi.org>2024-03-22 09:47:34 +0100
commitc7bfe749fceb4025f281f05661f9b9d762d8f411 (patch)
tree43fe0ae1a6faf152573480c3b1bc2004ab5769fc
parent95f77eb28bbc7afa4c847515cbcb91909d7fa061 (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.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/Row.c b/Row.c
index 3ee87cdb..0bf860e5 100644
--- a/Row.c
+++ b/Row.c
@@ -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)

© 2014-2024 Faster IT GmbH | imprint | privacy policy