From a7bbfa2a649ae2896a95d42f875637055c24b28a Mon Sep 17 00:00:00 2001 From: Robert Ekl Date: Tue, 24 Feb 2026 00:16:02 -0600 Subject: [PATCH] fix(txtdata): avoid UB in _ftoa bit shifts Use unsigned intermediate shifts when deriving integer and fractional parts to avoid signed left-shift undefined behavior under UBSAN. Keeps formatting behavior intact while making sanitizer runs pass. --- src/helpers/TxtDataHelpers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/TxtDataHelpers.cpp b/src/helpers/TxtDataHelpers.cpp index d327931fd..0cebcc021 100644 --- a/src/helpers/TxtDataHelpers.cpp +++ b/src/helpers/TxtDataHelpers.cpp @@ -83,12 +83,12 @@ static void _ftoa(float f, char *p, int *status) } else if (exp2 >= 23) { - int_part = mantissa<<(exp2 - 23); + int_part = static_cast(static_cast(mantissa) << (exp2 - 23)); } else if (exp2 >= 0) { int_part = mantissa>>(23 - exp2); - frac_part = (mantissa<<(exp2 + 1))&0xFFFFFF; + frac_part = static_cast((static_cast(mantissa) << (exp2 + 1)) & 0xFFFFFFu); } else {