intel / thermal_daemon

Thermal daemon for IA
GNU General Public License v2.0
539 stars 117 forks source link

memset of zero bytes of a struct elements that are double precision floating point values is probably incorrect. #408

Closed ColinIanKing closed 1 year ago

ColinIanKing commented 1 year ago

pid_param_t has 3 double precision values:

typedef struct
{
        int valid;
        double kp;
        double ki;
        double kd;
}pid_param_t;

Zero'ing these using memset is not portable, we cannot rely on a zero'd mantissa and zero'd exponent to necessarily represent 0.0.

detected by static analysis with cppcheck:

src/thd_parse.cpp:229:5: portability: Using memset() on struct which contains a floating point number. [memsetClassFloat]
    memset(&trip_cdev.pid_param, 0, sizeof(pid_param_t));
spandruvada commented 1 year ago

Fixed. Thanks for reporting.