intel / thermal_daemon

Thermal daemon for IA
GNU General Public License v2.0
550 stars 118 forks source link

scan-build detects issues on static analysis of ThermalMonitor #92

Closed ColinIanKing closed 7 years ago

ColinIanKing commented 8 years ago

Building/static analysis with clang's scan build has found some potential issues with ThermalMonitor:

built using clang 3.8.0-2ubuntu3 (tags/RELEASE_380/final):

scan-build make

qcustomplot/qcustomplot.cpp:2837:31: warning: Division by zero return mElements.at(index / columnCount()).at(index % columnCount());


qcustomplot/qcustomplot.cpp:2837:57: warning: Division by zero
    return mElements.at(index / columnCount()).at(index % columnCount());
                                                  ~~~~~~^~~~~~~~~~~~~~~
qcustomplot/qcustomplot.cpp:2848:21: warning: Division by zero
    mElements[index / columnCount()][index % columnCount()] = 0;
              ~~~~~~^~~~~~~~~~~~~~~
qcustomplot/qcustomplot.cpp:2848:44: warning: Division by zero
    mElements[index / columnCount()][index % columnCount()] = 0;
                                     ~~~~~~^~~~~~~~~~~~~~~
qcustomplot/qcustomplot.cpp:7140:5: warning: Potential memory leak
    return true;
    ^~~~~~~~~~~
qcustomplot/qcustomplot.cpp:18291:39: warning: The left operand of '-' is a garbage value
        result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; // half of center bar
                       ~~~~~~~~~~~~~~~^
qcustomplot/qcustomplot.cpp:19076:59: warning: The right operand of '+' is a garbage value
    keyPixel = mKeyAxis.data()->coordToPixel(range.upper) + upperPixelWidth;
                                                          ^ ~~~~~~~~~~~~~~~
qcustomplot/qcustomplot.cpp:19380:9: warning: Function call argument is an uninitialized value
    if (keyRange.contains(posKey) && valueRange.contains(posValue))
        ^~~~~~~~~~~~~~~~~~~~~~~~~
qcustomplot/qcustomplot.cpp:20310:9: warning: Function call argument is an uninitialized value
    if (mMapData->keyRange().contains(posKey) && mMapData->valueRange().contains(posValue))
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
qcustomplot/qcustomplot.cpp:21365:11: warning: Function call argument is an uninitialized value
      if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
qcustomplot/qcustomplot.cpp:21389:11: warning: Function call argument is an uninitialized value
      if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 warnings generated.
spandruvada commented 8 years ago

qcustomplot.zip

I think it will fix all except potential memory leak, which I don't think is a valid one.

spandruvada commented 8 years ago

Please try the attached file, if it is fine, I will apply.

ColinIanKing commented 8 years ago

Apologies for taking so long to reply, for some reason I missed the notification on your message.

Using the source from the zip I get:

/usr/share/clang/scan-build-3.8/bin/../libexec/c++-analyzer -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_DBUS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtDBus -I/usr/include/qt4 -I. -I. -o qcustomplot.o qcustomplot/qcustomplot.cpp qcustomplot/qcustomplot.cpp:2837:31: warning: Division by zero return mElements.at(index / columnCount()).at(index % columnCount());


qcustomplot/qcustomplot.cpp:2837:57: warning: Division by zero
    return mElements.at(index / columnCount()).at(index % columnCount());
                                                  ~~~~~~^~~~~~~~~~~~~~~
qcustomplot/qcustomplot.cpp:2849:24: warning: Division by zero
       mElements[index / columnCount()][index % columnCount()] = 0;
                 ~~~~~~^~~~~~~~~~~~~~~
qcustomplot/qcustomplot.cpp:2849:47: warning: Division by zero
       mElements[index / columnCount()][index % columnCount()] = 0;
                                        ~~~~~~^~~~~~~~~~~~~~~
qcustomplot/qcustomplot.cpp:7141:5: warning: Potential memory leak
    return true;
    ^~~~~~~~~~~
qcustomplot/qcustomplot.cpp:19077:59: warning: The right operand of '+' is a garbage value
    keyPixel = mKeyAxis.data()->coordToPixel(range.upper) + upperPixelWidth;
                                                          ^ ~~~~~~~~~~~~~~~
6 warnings generated.

However, some of these have been fixed by my latest commits, 1f1b6f4f1ed406c4652253ba3819cc22ae2e18ac, baaee2d0b1196c4e5dd780f7f4c41a083ebd3511