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/)
pull/219/head
Michael Schwarz 2025-10-01 14:03:50 +02:00
parent 2904533b05
commit f819b8d678
1 changed files with 1 additions and 1 deletions

View File

@ -714,7 +714,7 @@ QVector<quint16> SunSpecDataPoint::convertFromFloatWithSSF(float value, qint16 s
break; break;
} }
case Int16: { case Int16: {
quint16 rawValue = static_cast<quint16>(value * pow(10, -1 * scaleFactor)); quint16 rawValue = static_cast<qint16>(value * pow(10, -1 * scaleFactor));
rawData << rawValue; rawData << rawValue;
break; break;
} }