From f819b8d6788552263d8e56286fe8135a6b0be0f9 Mon Sep 17 00:00:00 2001 From: Michael Schwarz Date: Wed, 1 Oct 2025 14:03:50 +0200 Subject: [PATCH] Fix conversion from float to quint16 in SunSpecDataPoint::convertFromFloatWithSSF Calling this function with a negative value and DataType::Int16 always gives a 0 result on ARM. Need to convert to qint16 first to avoid undefined behavior (cf. https://embeddeduse.com/2013/08/25/casting-a-negative-float-to-an-unsigned-int/) --- libnymea-sunspec/sunspecdatapoint.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnymea-sunspec/sunspecdatapoint.cpp b/libnymea-sunspec/sunspecdatapoint.cpp index c7bfd34..d45e827 100644 --- a/libnymea-sunspec/sunspecdatapoint.cpp +++ b/libnymea-sunspec/sunspecdatapoint.cpp @@ -714,7 +714,7 @@ QVector SunSpecDataPoint::convertFromFloatWithSSF(float value, qint16 s break; } case Int16: { - quint16 rawValue = static_cast(value * pow(10, -1 * scaleFactor)); + quint16 rawValue = static_cast(value * pow(10, -1 * scaleFactor)); rawData << rawValue; break; }