diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2024-03-20 19:42:32 +0100 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2024-03-20 20:40:14 +0100 |
commit | 59b30d692a8d3fca876ff62875c200546d15a178 (patch) | |
tree | b1fe4373e77ce1a2fa0f5b8be49a5120b9b9bfcb /Row.c | |
parent | 299ca6ed2febc6e51fb164578bbab7aa5b8fd34c (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.
Diffstat (limited to 'Row.c')
-rw-r--r-- | Row.c | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -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]; |