summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2024-03-20 19:42:32 +0100
committerBenBE <BenBE@geshi.org>2024-03-20 20:40:14 +0100
commit59b30d692a8d3fca876ff62875c200546d15a178 (patch)
treeb1fe4373e77ce1a2fa0f5b8be49a5120b9b9bfcb
parent299ca6ed2febc6e51fb164578bbab7aa5b8fd34c (diff)
Check width in Row_printPercentage()
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.
-rw-r--r--Row.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/Row.c b/Row.c
index 9ea3f073..3ee87cdb 100644
--- a/Row.c
+++ b/Row.c
@@ -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];

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