Skip to content

Commit

Permalink
fixed several static code analysis warnings and security vulnerabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
jkriege2 committed Jan 10, 2024
1 parent 7cf2990 commit f096aa9
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 200 deletions.
2 changes: 1 addition & 1 deletion lib/jkqtcommon/jkqtpbasicimagetools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,7 @@ QImage JKQTPImageTools::GetPaletteImage(int i, int width)
QImage JKQTPImageTools::GetPaletteImage(int i, int width, int height)
{
QImage img;
const long NPixels=static_cast<int>(jkqtp_bounded<long>(0, width*height, std::numeric_limits<int>::max()));
const int NPixels=jkqtp_bounded<int>(width*height);

QVector<double> pic(NPixels,0);
for (int j=0; j<NPixels; j++) {
Expand Down
2 changes: 1 addition & 1 deletion lib/jkqtcommon/jkqtpbasicimagetools.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ struct JKQTPImageTools {
if (!dbl_in || width<=0 || height<=0)
return;

const long NPixels= width*height;
const int NPixels= jkqtp_bounded<int>(width*height);
double min = *dbl_in;
double max = *dbl_in;
if (jkqtp_approximatelyEqual(minColor, maxColor, JKQTP_DOUBLE_EPSILON)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/jkqtcommon/jkqtpdrawingtools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ QString JKQTPGraphSymbols2String(JKQTPGraphSymbols pos) {
case JKQTPFemale: return "symbol_female";
case JKQTPMale: return "symbol_male";
case JKQTPCirclePeace: return "symbol_circle_peace";
case JKQTPSymbolCount: JKQTPGraphSymbols2String(JKQTPMaxSymbolID);
case JKQTPSymbolCount: return JKQTPGraphSymbols2String(JKQTPMaxSymbolID);
case JKQTPCharacterSymbol:
case JKQTPFilledCharacterSymbol:
case JKQTPFirstCustomSymbol:
Expand Down Expand Up @@ -179,7 +179,7 @@ QString JKQTPGraphSymbols2NameString(JKQTPGraphSymbols pos) {
case JKQTPFemale: return QObject::tr("female");
case JKQTPMale: return QObject::tr("male");
case JKQTPCirclePeace: return QObject::tr("circled peace");
case JKQTPSymbolCount: JKQTPGraphSymbols2NameString(JKQTPMaxSymbolID);
case JKQTPSymbolCount: return JKQTPGraphSymbols2NameString(JKQTPMaxSymbolID);
case JKQTPCharacterSymbol:
case JKQTPFilledCharacterSymbol:
case JKQTPFirstCustomSymbol:
Expand Down
28 changes: 26 additions & 2 deletions lib/jkqtmath/jkqtpmathparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <iostream>
#include <float.h>
#include <ctime>
#include <array>
#include "jkqtcommon/jkqtpstringtools.h"


Expand Down Expand Up @@ -1784,14 +1785,14 @@ JKQTPMathParser::jkmpFunctionNode::jkmpFunctionNode(const std::string& name, JKQ
}

JKQTPMathParser::jkmpResult JKQTPMathParser::jkmpFunctionNode::evaluate() {
JKQTPMathParser::jkmpResult data[257];
std::array<JKQTPMathParser::jkmpResult,257> data;
if (n>0) {
for (int i=0; i<n; i++) {
data[i]=child[i]->evaluate();
}
}
// JKQTPMathParser::jkmpResult r= getParser()->evaluateFunction(fun, data,n);
return function(data,n, parser);
return function(data.data(),n, parser);
}


Expand Down Expand Up @@ -1885,10 +1886,33 @@ const char *JKQTPMathParser::jkmpException::what() const noexcept {
return errormessage.c_str();
}

JKQTPMathParser::jkmpNode::jkmpNode(JKQTPMathParser *parser_, jkmpNode *parent_):
parser(parser_), parent(parent_)
{

}

JKQTPMathParser *JKQTPMathParser::jkmpNode::getParser(){ return parser; }

void JKQTPMathParser::jkmpNode::setParser(JKQTPMathParser *mp){ parser=mp; }

JKQTPMathParser::jkmpNode *JKQTPMathParser::jkmpNode::getParent(){ return parent; }

void JKQTPMathParser::jkmpNode::setParent(JKQTPMathParser::jkmpNode *par) { parent=par; }

JKQTPMathParser::jkmpFunctionDescriptor::jkmpFunctionDescriptor(jkmpEvaluateFunc function_):
function(function_)
{

}

JKQTPMathParser::jkmpTempVariable::jkmpTempVariable()
{
type=jkmpDouble;
name="";
internal=false;
str=nullptr;
num=nullptr;
boolean=nullptr;

}
7 changes: 5 additions & 2 deletions lib/jkqtmath/jkqtpmathparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class jkqtmath_LIB_EXPORT JKQTPMathParser

/** \brief This struct is for managing temporary variables. It is generally like jkmpVariable. */
struct jkqtmath_LIB_EXPORT jkmpTempVariable {
jkmpTempVariable();
std::string name; /*!< \brief name of the variable */
jkmpResultType type; /*!< \brief type of the variable */
bool internal; /*!< \brief this is an internal variable */
Expand Down Expand Up @@ -298,8 +299,9 @@ class jkqtmath_LIB_EXPORT JKQTPMathParser

/** \brief description of a user registered function */
struct jkqtmath_LIB_EXPORT jkmpFunctionDescriptor {
jkmpEvaluateFunc function; /*!< \brief a pointer to the function implementation */
std::string name; /*!< \brief name of the function */
jkmpFunctionDescriptor(jkmpEvaluateFunc function_=nullptr);
jkmpEvaluateFunc function; /*!< \brief a pointer to the function implementation */
std::string name; /*!< \brief name of the function */
};


Expand All @@ -316,6 +318,7 @@ class jkqtmath_LIB_EXPORT JKQTPMathParser
JKQTPMathParser* parser; /*!< \brief points to the parser object that is used to evaluate this node */
jkmpNode* parent; /*!< \brief points to the parent node */
public:
jkmpNode(JKQTPMathParser* parser_=nullptr, jkmpNode* parent_=nullptr);
/** \brief virtual class destructor */
virtual ~jkmpNode();

Expand Down
2 changes: 1 addition & 1 deletion lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ void JKQTMathTextMatrixNode::parseColumnSpec(const QString &columnSpec)


JKQTMathTextMatrixNode::LayoutInfo::LayoutInfo():
JKQTMathTextNodeSize(), colwidth(), rowheight()
JKQTMathTextNodeSize(), colwidth(), rowheight(), leftPadding(0), rightPadding(0), topPadding(0), bottomPadding(0)
{

}
Expand Down
12 changes: 7 additions & 5 deletions lib/jkqtplotter/graphs/jkqtpcontour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
# include <QVector3D>

JKQTPContourPlot::JKQTPContourPlot(JKQTBasePlotter *parent) :
JKQTPMathImage(parent)
JKQTPMathImage(parent),
ignoreOnPlane(false),
contourColoringMode(ColorContoursFromPaletteByValue),
relativeLevels(false),
contourLinesCachedForChecksum(0)
{
ignoreOnPlane=false;
contourColoringMode=ColorContoursFromPaletteByValue;
relativeLevels=false;

initLineStyle(parent, parentPlotStyle, JKQTPPlotStyleType::Default);
}
Expand Down Expand Up @@ -428,7 +429,8 @@ void JKQTPContourPlot::calcContourLines(QList<QVector<QLineF> > &ContourLines)


JKQTPColumnContourPlot::JKQTPColumnContourPlot(JKQTBasePlotter *parent):
JKQTPContourPlot(parent)
JKQTPContourPlot(parent),
imageColumn(-1)
{
this->datatype=JKQTPMathImageDataType::DoubleArray;
}
Expand Down
Loading

0 comments on commit f096aa9

Please sign in to comment.