From a3666e5e399f83b609413a6d0d382bc15ae92e70 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Wed, 13 May 2015 08:02:58 +0200 Subject: QCustomPlot: fix division(or modulo) by zero found by Clang and Coverity (CID 1159170 & 1159171) Try 2 Change-Id: I10c439ccd4b8e5ac24275332e35fb35ad95b8d1b Reviewed-on: https://code.wireshark.org/review/8447 Petri-Dish: Alexis La Goutte Tested-by: Petri Dish Buildbot Reviewed-by: Alexis La Goutte --- ui/qt/qcustomplot.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'ui/qt/qcustomplot.cpp') diff --git a/ui/qt/qcustomplot.cpp b/ui/qt/qcustomplot.cpp index 1573f02920..eab739aa29 100644 --- a/ui/qt/qcustomplot.cpp +++ b/ui/qt/qcustomplot.cpp @@ -2845,8 +2845,9 @@ int QCPLayoutGrid::elementCount() const /* inherits documentation from base class */ QCPLayoutElement *QCPLayoutGrid::elementAt(int index) const { - if (index >= 0 && index < elementCount()) - return mElements.at(index / columnCount()).at(index % columnCount()); + int colC = columnCount(); + if (index >= 0 && colC && index < elementCount()) + return mElements.at(index / colC).at(index % colC); else return 0; } @@ -2854,10 +2855,16 @@ QCPLayoutElement *QCPLayoutGrid::elementAt(int index) const /* inherits documentation from base class */ QCPLayoutElement *QCPLayoutGrid::takeAt(int index) { + + int colC = columnCount(); + if(colC == 0) + return 0; + if (QCPLayoutElement *el = elementAt(index)) { + releaseElement(el); - mElements[index / columnCount()][index % columnCount()] = 0; + mElements[index / colC][index % colC] = 0; return el; } else { -- cgit v1.2.1