From f096aa9602659026e2a3395e4b58c43f06ed0576 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Wed, 10 Jan 2024 10:35:43 +0100 Subject: [PATCH] fixed several static code analysis warnings and security vulnerabilities --- lib/jkqtcommon/jkqtpbasicimagetools.cpp | 2 +- lib/jkqtcommon/jkqtpbasicimagetools.h | 2 +- lib/jkqtcommon/jkqtpdrawingtools.cpp | 4 +- lib/jkqtmath/jkqtpmathparser.cpp | 28 +++- lib/jkqtmath/jkqtpmathparser.h | 7 +- .../nodes/jkqtmathtextmatrixnode.cpp | 2 +- lib/jkqtplotter/graphs/jkqtpcontour.cpp | 12 +- lib/jkqtplotter/graphs/jkqtpimage.cpp | 153 ++++++++--------- lib/jkqtplotter/graphs/jkqtpimagergb.cpp | 10 ++ lib/jkqtplotter/graphs/jkqtpparsedfunction.h | 1 + .../graphs/jkqtpsinglecolumnsymbols.cpp | 5 +- lib/jkqtplotter/graphs/jkqtpviolinplot.cpp | 22 +-- lib/jkqtplotter/jkqtpbaseplotter.cpp | 9 + lib/jkqtplotter/jkqtpdatastorage.h | 33 ++-- lib/jkqtplotter/jkqtpimagetools.cpp | 157 +++++++++--------- 15 files changed, 248 insertions(+), 199 deletions(-) diff --git a/lib/jkqtcommon/jkqtpbasicimagetools.cpp b/lib/jkqtcommon/jkqtpbasicimagetools.cpp index 7b5a47f257..a19d1e3d4e 100644 --- a/lib/jkqtcommon/jkqtpbasicimagetools.cpp +++ b/lib/jkqtcommon/jkqtpbasicimagetools.cpp @@ -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(jkqtp_bounded(0, width*height, std::numeric_limits::max())); + const int NPixels=jkqtp_bounded(width*height); QVector pic(NPixels,0); for (int j=0; j(width*height); double min = *dbl_in; double max = *dbl_in; if (jkqtp_approximatelyEqual(minColor, maxColor, JKQTP_DOUBLE_EPSILON)) { diff --git a/lib/jkqtcommon/jkqtpdrawingtools.cpp b/lib/jkqtcommon/jkqtpdrawingtools.cpp index 0de9c43d4d..b12ddf69fc 100644 --- a/lib/jkqtcommon/jkqtpdrawingtools.cpp +++ b/lib/jkqtcommon/jkqtpdrawingtools.cpp @@ -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: @@ -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: diff --git a/lib/jkqtmath/jkqtpmathparser.cpp b/lib/jkqtmath/jkqtpmathparser.cpp index 3335e09b97..b2baa40378 100644 --- a/lib/jkqtmath/jkqtpmathparser.cpp +++ b/lib/jkqtmath/jkqtpmathparser.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "jkqtcommon/jkqtpstringtools.h" @@ -1784,14 +1785,14 @@ JKQTPMathParser::jkmpFunctionNode::jkmpFunctionNode(const std::string& name, JKQ } JKQTPMathParser::jkmpResult JKQTPMathParser::jkmpFunctionNode::evaluate() { - JKQTPMathParser::jkmpResult data[257]; + std::array data; if (n>0) { for (int i=0; ievaluate(); } } // JKQTPMathParser::jkmpResult r= getParser()->evaluateFunction(fun, data,n); - return function(data,n, parser); + return function(data.data(),n, parser); } @@ -1885,6 +1886,12 @@ 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; } @@ -1892,3 +1899,20 @@ 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; + +} diff --git a/lib/jkqtmath/jkqtpmathparser.h b/lib/jkqtmath/jkqtpmathparser.h index 255d7e8dac..7d74e5681e 100644 --- a/lib/jkqtmath/jkqtpmathparser.h +++ b/lib/jkqtmath/jkqtpmathparser.h @@ -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 */ @@ -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 */ }; @@ -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(); diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.cpp index 763c8395e7..1567342396 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.cpp @@ -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) { } diff --git a/lib/jkqtplotter/graphs/jkqtpcontour.cpp b/lib/jkqtplotter/graphs/jkqtpcontour.cpp index 09941ba60a..3d93312efc 100644 --- a/lib/jkqtplotter/graphs/jkqtpcontour.cpp +++ b/lib/jkqtplotter/graphs/jkqtpcontour.cpp @@ -35,11 +35,12 @@ # include 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); } @@ -428,7 +429,8 @@ void JKQTPContourPlot::calcContourLines(QList > &ContourLines) JKQTPColumnContourPlot::JKQTPColumnContourPlot(JKQTBasePlotter *parent): - JKQTPContourPlot(parent) + JKQTPContourPlot(parent), + imageColumn(-1) { this->datatype=JKQTPMathImageDataType::DoubleArray; } diff --git a/lib/jkqtplotter/graphs/jkqtpimage.cpp b/lib/jkqtplotter/graphs/jkqtpimage.cpp index 03b665ad22..48439782a4 100644 --- a/lib/jkqtplotter/graphs/jkqtpimage.cpp +++ b/lib/jkqtplotter/graphs/jkqtpimage.cpp @@ -382,8 +382,42 @@ void JKQTPImage::copyImagePlotAsImage() +JKQTPMathImageBase::JKQTPMathImageBase(JKQTBasePlotter *parent): + JKQTPImageBase(parent), + data(nullptr), + datatype(JKQTPMathImageDataType::DoubleArray), + Nx(0), Ny(0), + dataModifier(nullptr), datatypeModifier(JKQTPMathImageDataType::DoubleArray), + internalDataMin(0.0), internalDataMax(0.0), + internalModifierMin(0.0), internalModifierMax(0.0) +{ + +} + +JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double height, JKQTBasePlotter *parent): + JKQTPImageBase(x,y,width,height,parent), + data(nullptr), + datatype(JKQTPMathImageDataType::DoubleArray), + Nx(0), Ny(0), + dataModifier(nullptr), datatypeModifier(JKQTPMathImageDataType::DoubleArray), + internalDataMin(0.0), internalDataMax(0.0), + internalModifierMin(0.0), internalModifierMax(0.0) +{ + +} + +JKQTPMathImageBase::JKQTPMathImageBase(JKQTPlotter *parent): + JKQTPMathImageBase(parent->getPlotter()) +{ +} + +JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double height, JKQTPlotter *parent): + JKQTPMathImageBase(x,y,width,height,parent->getPlotter()) +{ +} + JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double height, JKQTPMathImageDataType datatype, const void* data, int Nx, int Ny, JKQTBasePlotter* parent): - JKQTPImageBase(x, y, width, height, parent) + JKQTPMathImageBase(x, y, width, height, parent) { this->data=data; this->datatype=datatype; @@ -395,14 +429,9 @@ JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double height, JKQTPMathImageDataType datatype, const void* data, int Nx, int Ny, JKQTPlotter* parent): - JKQTPImageBase(x, y, width, height, parent) + JKQTPMathImageBase(x, y, width, height, datatype, data, Nx, Ny, parent->getPlotter()) { - this->data=data; - this->datatype=datatype; - this->Nx=Nx; - this->Ny=Ny; - dataModifier=nullptr; - datatypeModifier=JKQTPMathImageDataType::DoubleArray; + } void JKQTPMathImageBase::drawKeyMarker(JKQTPEnhancedPainter &/*painter*/, const QRectF &/*rect*/) { @@ -411,138 +440,94 @@ void JKQTPMathImageBase::drawKeyMarker(JKQTPEnhancedPainter &/*painter*/, const void JKQTPMathImageBase::setNx(int __value) { - this->Nx = __value; + Nx = __value; } void JKQTPMathImageBase::setNx(size_t __value) { - this->Nx = static_cast(__value); + Nx = static_cast(__value); } int JKQTPMathImageBase::getNx() const { - return this->Nx; + return Nx; } void JKQTPMathImageBase::setNy(int __value) { - this->Ny = __value; + Ny = __value; } void JKQTPMathImageBase::setNy(size_t __value) { - this->Ny = static_cast(__value); + Ny = static_cast(__value); } int JKQTPMathImageBase::getNy() const { - return this->Ny; + return Ny; } void JKQTPMathImageBase::setData(const void *__value) { - this->data = __value; + data = __value; } const void *JKQTPMathImageBase::getData() const { - return this->data; + return data; } void JKQTPMathImageBase::setDatatype(JKQTPMathImageDataType __value) { - this->datatype = __value; + datatype = __value; } JKQTPMathImageDataType JKQTPMathImageBase::getDatatype() const { - return this->datatype; + return datatype; } void JKQTPMathImageBase::setDataModifier(const void *__value) { - this->dataModifier = __value; + dataModifier = __value; } const void *JKQTPMathImageBase::getDataModifier() const { - return this->dataModifier; + return dataModifier; } void JKQTPMathImageBase::setDatatypeModifier(JKQTPMathImageDataType __value) { - this->datatypeModifier = __value; + datatypeModifier = __value; } JKQTPMathImageDataType JKQTPMathImageBase::getDatatypeModifier() const { - return this->datatypeModifier; + return datatypeModifier; } -JKQTPMathImageBase::JKQTPMathImageBase(JKQTBasePlotter *parent): - JKQTPImageBase(parent) -{ - this->data=nullptr; - this->Nx=0; - this->Ny=0; - this->datatype=JKQTPMathImageDataType::DoubleArray; - dataModifier=nullptr; - datatypeModifier=JKQTPMathImageDataType::DoubleArray; +void JKQTPMathImageBase::setData(const void *data_, int Nx_, int Ny_, JKQTPMathImageDataType datatype_) { + data=data_; + datatype=datatype_; + Nx=Nx_; + Ny=Ny_; } -JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double height, JKQTBasePlotter *parent): - JKQTPImageBase(x,y,width,height,parent) -{ - this->data=nullptr; - this->Nx=0; - this->Ny=0; - this->datatype=JKQTPMathImageDataType::DoubleArray; - dataModifier=nullptr; - datatypeModifier=JKQTPMathImageDataType::DoubleArray; -} - -JKQTPMathImageBase::JKQTPMathImageBase(JKQTPlotter *parent): - JKQTPImageBase(parent) -{ - this->data=nullptr; - this->Nx=0; - this->Ny=0; - this->datatype=JKQTPMathImageDataType::DoubleArray; - dataModifier=nullptr; - datatypeModifier=JKQTPMathImageDataType::DoubleArray; -} - -JKQTPMathImageBase::JKQTPMathImageBase(double x, double y, double width, double height, JKQTPlotter *parent): - JKQTPImageBase(x,y,width,height,parent) -{ - this->data=nullptr; - this->Nx=0; - this->Ny=0; - this->datatype=JKQTPMathImageDataType::DoubleArray; - dataModifier=nullptr; - datatypeModifier=JKQTPMathImageDataType::DoubleArray; -} - -void JKQTPMathImageBase::setData(const void *data, int Nx, int Ny, JKQTPMathImageDataType datatype) { - this->data=data; - this->datatype=datatype; - this->Nx=Nx; - this->Ny=Ny; -} - -void JKQTPMathImageBase::setData(const void* data, int Nx, int Ny) { - this->data=data; - this->Nx=Nx; - this->Ny=Ny; +void JKQTPMathImageBase::setData(const void *data_, int Nx_, int Ny_) { + data=data_; + Nx=Nx_; + Ny=Ny_; } void JKQTPMathImageBase::setDataModifier(const void *data, JKQTPMathImageDataType datatype) { - this->dataModifier=data; - this->datatypeModifier=datatype; + dataModifier=data; + datatypeModifier=datatype; } @@ -731,23 +716,25 @@ void JKQTPMathImage::initJKQTPMathImage() { - this->palette=JKQTPMathImageGRAY; - this->autoModifierRange=true; + palette=JKQTPMathImageGRAY; + autoModifierRange=true; } JKQTPMathImage::JKQTPMathImage(double x, double y, double width, double height, JKQTPMathImageDataType datatype, const void* data, int Nx, int Ny, JKQTPMathImageColorPalette palette, JKQTBasePlotter* parent): JKQTPMathImageBase(x, y, width, height, datatype, data, Nx, Ny, parent), - JKQTPColorPaletteWithModifierStyleAndToolsMixin(parent) + JKQTPColorPaletteWithModifierStyleAndToolsMixin(parent), + actCopyImage(nullptr), + actSaveImage(nullptr), + actCopyPalette(nullptr), + actSavePalette(nullptr) { initJKQTPMathImage(); this->palette=palette; } JKQTPMathImage::JKQTPMathImage(JKQTBasePlotter *parent): - JKQTPMathImageBase(0, 0, 1, 1, JKQTPMathImageDataType::UInt8Array, nullptr, 0, 0, parent), - JKQTPColorPaletteWithModifierStyleAndToolsMixin(parent) + JKQTPMathImage(0, 0, 1, 1, JKQTPMathImageDataType::UInt8Array, nullptr, 0, 0, JKQTPMathImageGRAY, parent) { - initJKQTPMathImage(); if (parent) this->palette=parent->getCurrentPlotterStyle().graphsStyle.defaultPalette; } diff --git a/lib/jkqtplotter/graphs/jkqtpimagergb.cpp b/lib/jkqtplotter/graphs/jkqtpimagergb.cpp index 36c5537c30..e9ec576280 100644 --- a/lib/jkqtplotter/graphs/jkqtpimagergb.cpp +++ b/lib/jkqtplotter/graphs/jkqtpimagergb.cpp @@ -218,6 +218,16 @@ void JKQTPRGBMathImage::getOutsideSize(JKQTPEnhancedPainter& painter, int& leftS } struct RGBOutsizeData { + RGBOutsizeData(): + internalDataMin(0), + internalDataMax(0), + data(nullptr), + colorBarRightAxis(nullptr), + colorBarTopAxis(nullptr), + name(), + palette(JKQTPMathImageMATLAB), + paletteImage() + {} double internalDataMin; double internalDataMax; const void* data; diff --git a/lib/jkqtplotter/graphs/jkqtpparsedfunction.h b/lib/jkqtplotter/graphs/jkqtpparsedfunction.h index 77bb4e5ca2..e895569119 100644 --- a/lib/jkqtplotter/graphs/jkqtpparsedfunction.h +++ b/lib/jkqtplotter/graphs/jkqtpparsedfunction.h @@ -78,6 +78,7 @@ protected: /** \brief INTERNAL data structure combining a JKQTPMathParser and a JKQTPMathParser::jkmpNode */ struct ParsedFunctionLineGraphFunctionData { + inline ParsedFunctionLineGraphFunctionData(): varcount(0) {}; std::shared_ptr parser; std::shared_ptr node; int varcount; diff --git a/lib/jkqtplotter/graphs/jkqtpsinglecolumnsymbols.cpp b/lib/jkqtplotter/graphs/jkqtpsinglecolumnsymbols.cpp index ebd0d94bc7..d120775752 100644 --- a/lib/jkqtplotter/graphs/jkqtpsinglecolumnsymbols.cpp +++ b/lib/jkqtplotter/graphs/jkqtpsinglecolumnsymbols.cpp @@ -36,12 +36,11 @@ JKQTPSingleColumnSymbolsGraph::JKQTPSingleColumnSymbolsGraph(JKQTBasePlotter *parent): - JKQTPSingleColumnGraph(parent), seedValue(123456) + JKQTPSingleColumnGraph(parent), seedValue(123456), positionScatterStyle(NoScatter), position(0), width(1) + { parentPlotStyle=-1; dataDirection=DataDirection::Y; - position=0; - width=1; initSymbolStyle(parent, parentPlotStyle, JKQTPPlotStyleType::Default); } diff --git a/lib/jkqtplotter/graphs/jkqtpviolinplot.cpp b/lib/jkqtplotter/graphs/jkqtpviolinplot.cpp index f267d790b3..cca531ba66 100644 --- a/lib/jkqtplotter/graphs/jkqtpviolinplot.cpp +++ b/lib/jkqtplotter/graphs/jkqtpviolinplot.cpp @@ -36,17 +36,19 @@ JKQTPViolinplotElementBase::JKQTPViolinplotElementBase(JKQTBasePlotter* parent): - JKQTPPlotElement(parent) + JKQTPPlotElement(parent), + pos(JKQTP_NAN), + median(JKQTP_NAN), + mean(JKQTP_NAN), + min(JKQTP_NAN), + max(JKQTP_NAN), + drawMean(false), + drawMinMax(false), + drawMedian(false), + violinPositionColumn(-1), + violinFrequencyColumn(-1) { - pos=JKQTP_NAN; - median=JKQTP_NAN; - mean=JKQTP_NAN; - min=JKQTP_NAN; - max=JKQTP_NAN; - drawMean=false; - drawMinMax=false; - violinPositionColumn=-1; - violinFrequencyColumn=-1; + initViolinplotStyle(parent, parentPlotStyle); setMeanSymbolType(JKQTPPlus); diff --git a/lib/jkqtplotter/jkqtpbaseplotter.cpp b/lib/jkqtplotter/jkqtpbaseplotter.cpp index 936dbdc80b..54ed5fa1c1 100644 --- a/lib/jkqtplotter/jkqtpbaseplotter.cpp +++ b/lib/jkqtplotter/jkqtpbaseplotter.cpp @@ -1520,6 +1520,10 @@ void JKQTBasePlotter::print(QPrinter* printer, bool displayPreview) { bool JKQTBasePlotter::printpreviewNew(QPaintDevice* paintDevice, bool setAbsolutePaperSize, double printsizeX_inMM, double printsizeY_inMM, bool displayPreview) { + + JKQTPASSERT_M(paintDevice, "INTERNAL ERROR: no QPaintDevice given to JKQTBasePlotter::printpreviewNew()!"); + + #ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT QPrinter *printer=dynamic_cast(paintDevice); QSvgGenerator* svg=dynamic_cast(paintDevice); @@ -1939,6 +1943,8 @@ void JKQTBasePlotter::updatePreviewLabel() { #ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT void JKQTBasePlotter::printpreviewPaintRequested(QPrinter* printer) { + JKQTPASSERT_M(printer, "INTERNAL ERROR: no QPrinter given to JKQTBasePlotter::printpreviewPaintRequested()!"); + double lw=lineWidthMultiplier; double fs=fontSizeMultiplier; QBrush bc=plotterStyle.widgetBackgroundBrush; @@ -2016,6 +2022,7 @@ void JKQTBasePlotter::printpreviewPaintRequested(QPrinter* printer) { void JKQTBasePlotter::printpreviewPaintRequestedNewPrinter(QPrinter* printer) { + JKQTPASSERT_M(printer, "INTERNAL ERROR: no QPrinter given to JKQTBasePlotter::printpreviewPaintRequestedNewPrinter()!"); QPaintDevice* paintDevice=dynamic_cast(printer); printpreviewPaintRequestedNewPaintDevice(paintDevice); @@ -2024,6 +2031,8 @@ void JKQTBasePlotter::printpreviewPaintRequestedNewPrinter(QPrinter* printer) { void JKQTBasePlotter::printpreviewPaintRequestedNewPaintDevice(QPaintDevice *paintDevice) { + JKQTPASSERT_M(paintDevice, "INTERNAL ERROR: no QPaintDevice given to JKQTBasePlotter::printpreviewPaintRequestedNewPaintDevice()!"); + //QPaintDevice* paintDevice=dynamic_cast(printer); #ifndef JKQTPLOTTER_COMPILE_WITHOUT_PRINTSUPPORT QPrinter* printer=dynamic_cast(paintDevice); diff --git a/lib/jkqtplotter/jkqtpdatastorage.h b/lib/jkqtplotter/jkqtpdatastorage.h index 2d99682e13..90860eb84e 100644 --- a/lib/jkqtplotter/jkqtpdatastorage.h +++ b/lib/jkqtplotter/jkqtpdatastorage.h @@ -947,13 +947,17 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPDatastore{ template size_t addCopiedColumn(const T* data, size_t rows, const QString& name=QString("")){ double* d=static_cast(malloc(static_cast(rows)*sizeof(double))); - if (data) { - for (size_t r=0; r size_t addCopiedColumn(const T* data, size_t rows, size_t stride, int start, const QString& name) { double* d=static_cast(malloc(static_cast(rows)*sizeof(double))); - if (data) { - for (size_t r=0; r(start+static_cast(r*stride))]); + if (d) { + if (data) { + for (size_t r=0; r(start+static_cast(r*stride))]); + } } + size_t itemid=addInternalItem(d, rows); + return addColumnForItem(itemid, 0, name); + } else { + throw std::runtime_error("could not allocate memory in JKQTPDataStore::addCopiedColumn()"); } - size_t itemid=addInternalItem(d, rows); - return addColumnForItem(itemid, 0, name); } /** \brief copy an external column to the datastore. It contains \a rows rows. The external data is copied to an internal array, so @@ -1761,7 +1769,7 @@ class JKQTPColumnIterator { /** \brief dereferences the iterator, throws an exception if the iterator is invalid (see isValid() ) or the value does not exist in the column */ inline reference operator*() const { - JKQTPASSERT(col_!=nullptr && pos_>=0 && pos_(col_->getRows())); + JKQTPASSERT((col_!=nullptr) && (pos_>=0) && (pos_(col_->getRows()))); return col_->at(pos_); } inline reference operator[](difference_type off) const @@ -1769,7 +1777,7 @@ class JKQTPColumnIterator { if (!isValid() && off<0) { return col_->at(static_cast(col_->getRows())+off); } - JKQTPASSERT(col_!=nullptr && pos_+off>=0 && pos_+off(col_->getRows())); + JKQTPASSERT((col_!=nullptr) && (pos_+off>=0) && (pos_+off(col_->getRows()))); return col_->at(pos_+off); } /** \brief comparison operator (less than) @@ -2092,6 +2100,7 @@ class JKQTPColumnConstIterator { inline reference operator[](difference_type off) const { if (!isValid() && off<0) { + JKQTPASSERT(col_!=nullptr); return col_->at(static_cast(col_->getRows())+off); } JKQTPASSERT(col_!=nullptr && pos_+off>=0 && pos_+off(col_->getRows())); diff --git a/lib/jkqtplotter/jkqtpimagetools.cpp b/lib/jkqtplotter/jkqtpimagetools.cpp index d912e7a06b..cacc329b63 100644 --- a/lib/jkqtplotter/jkqtpimagetools.cpp +++ b/lib/jkqtplotter/jkqtpimagetools.cpp @@ -43,27 +43,27 @@ JKQTPColorPaletteStyleAndToolsMixin::JKQTPColorPaletteStyleAndToolsMixin(JKQTBas colorBarTopAxis->setAxisLabel(""); - this->palette=JKQTPMathImageMATLAB; - this->imageNameFontName=parent->getDefaultTextFontName(); - this->imageNameFontSize=parent->getDefaultTextSize(); - this->imageName=""; - this->showColorBar=true; - this->colorBarWidth=14; - this->colorBarRelativeHeight=0.75; - this->autoImageRange=true; - this->imageMin=0; - this->imageMax=1; - this->colorBarOffset=4; - this->rangeMinFailAction=JKQTPMathImageLastPaletteColor; - this->rangeMaxFailAction=JKQTPMathImageLastPaletteColor; - this->rangeMinFailColor=QColor("black"); - this->rangeMaxFailColor=QColor("black"); - this->nanColor=QColor("black"); - this->infColor=QColor("black"); - this->colorBarTopVisible=false; - this->colorBarRightVisible=true; + palette=JKQTPMathImageMATLAB; + imageNameFontName=parent->getDefaultTextFontName(); + imageNameFontSize=parent->getDefaultTextSize(); + imageName=""; + showColorBar=true; + colorBarWidth=14; + colorBarRelativeHeight=0.75; + autoImageRange=true; + imageMin=0; + imageMax=1; + colorBarOffset=4; + rangeMinFailAction=JKQTPMathImageLastPaletteColor; + rangeMaxFailAction=JKQTPMathImageLastPaletteColor; + rangeMinFailColor=QColor("black"); + rangeMaxFailColor=QColor("black"); + nanColor=QColor("black"); + infColor=QColor("black"); + colorBarTopVisible=false; + colorBarRightVisible=true; - if (parent) this->palette=parent->getCurrentPlotterStyle().graphsStyle.defaultPalette; + if (parent) palette=parent->getCurrentPlotterStyle().graphsStyle.defaultPalette; } @@ -328,208 +328,208 @@ void JKQTPColorPaletteStyleAndToolsMixin::cbSetParent(JKQTBasePlotter* parent) { void JKQTPColorPaletteStyleAndToolsMixin::setColorPalette(const JKQTPMathImageColorPalette &__value) { - this->palette = __value; + palette = __value; } JKQTPMathImageColorPalette JKQTPColorPaletteStyleAndToolsMixin::getColorPalette() const { - return this->palette; + return palette; } void JKQTPColorPaletteStyleAndToolsMixin::setRangeMinFailAction(const JKQTPMathImageColorRangeFailAction &__value) { - this->rangeMinFailAction = __value; + rangeMinFailAction = __value; } JKQTPMathImageColorRangeFailAction JKQTPColorPaletteStyleAndToolsMixin::getActionRangeMinFail() const { - return this->rangeMinFailAction; + return rangeMinFailAction; } void JKQTPColorPaletteStyleAndToolsMixin::setRangeMaxFailAction(const JKQTPMathImageColorRangeFailAction &__value) { - this->rangeMaxFailAction = __value; + rangeMaxFailAction = __value; } JKQTPMathImageColorRangeFailAction JKQTPColorPaletteStyleAndToolsMixin::getActionRangeMaxFail() const { - return this->rangeMaxFailAction; + return rangeMaxFailAction; } void JKQTPColorPaletteStyleAndToolsMixin::setRangeMinFailColor(const QColor &__value) { - this->rangeMinFailColor = __value; + rangeMinFailColor = __value; } QColor JKQTPColorPaletteStyleAndToolsMixin::getRangeMinFailColor() const { - return this->rangeMinFailColor; + return rangeMinFailColor; } void JKQTPColorPaletteStyleAndToolsMixin::setRangeMaxFailColor(const QColor &__value) { - this->rangeMaxFailColor = __value; + rangeMaxFailColor = __value; } QColor JKQTPColorPaletteStyleAndToolsMixin::getRangeMaxFailColor() const { - return this->rangeMaxFailColor; + return rangeMaxFailColor; } void JKQTPColorPaletteStyleAndToolsMixin::setNanColor(const QColor &__value) { - this->nanColor = __value; + nanColor = __value; } QColor JKQTPColorPaletteStyleAndToolsMixin::getNanColor() const { - return this->nanColor; + return nanColor; } void JKQTPColorPaletteStyleAndToolsMixin::setInfColor(const QColor &__value) { - this->infColor = __value; + infColor = __value; } QColor JKQTPColorPaletteStyleAndToolsMixin::getInfColor() const { - return this->infColor; + return infColor; } void JKQTPColorPaletteStyleAndToolsMixin::setShowColorBar(bool __value) { - this->showColorBar = __value; + showColorBar = __value; } bool JKQTPColorPaletteStyleAndToolsMixin::getShowColorBar() const { - return this->showColorBar; + return showColorBar; } void JKQTPColorPaletteStyleAndToolsMixin::setColorBarWidth(int __value) { - this->colorBarWidth = __value; + colorBarWidth = __value; } int JKQTPColorPaletteStyleAndToolsMixin::getColorBarWidth() const { - return this->colorBarWidth; + return colorBarWidth; } void JKQTPColorPaletteStyleAndToolsMixin::setColorBarOffset(int __value) { - this->colorBarOffset = __value; + colorBarOffset = __value; } int JKQTPColorPaletteStyleAndToolsMixin::getColorBarOffset() const { - return this->colorBarOffset; + return colorBarOffset; } void JKQTPColorPaletteStyleAndToolsMixin::setColorBarRelativeHeight(double __value) { - this->colorBarRelativeHeight = __value; + colorBarRelativeHeight = __value; } double JKQTPColorPaletteStyleAndToolsMixin::getColorBarRelativeHeight() const { - return this->colorBarRelativeHeight; + return colorBarRelativeHeight; } void JKQTPColorPaletteStyleAndToolsMixin::setImageMin(double __value) { - this->imageMin = __value; + imageMin = __value; } double JKQTPColorPaletteStyleAndToolsMixin::getImageMin() const { - return this->imageMin; + return imageMin; } void JKQTPColorPaletteStyleAndToolsMixin::setImageMax(double __value) { - this->imageMax = __value; + imageMax = __value; } double JKQTPColorPaletteStyleAndToolsMixin::getImageMax() const { - return this->imageMax; + return imageMax; } void JKQTPColorPaletteStyleAndToolsMixin::setAutoImageRange(bool __value) { - this->autoImageRange = __value; + autoImageRange = __value; } bool JKQTPColorPaletteStyleAndToolsMixin::getAutoImageRange() const { - return this->autoImageRange; + return autoImageRange; } void JKQTPColorPaletteStyleAndToolsMixin::setImageName(const QString &__value) { - this->imageName = __value; + imageName = __value; } QString JKQTPColorPaletteStyleAndToolsMixin::getImageName() const { - return this->imageName; + return imageName; } void JKQTPColorPaletteStyleAndToolsMixin::setImageNameFontName(const QString &__value) { - this->imageNameFontName = __value; + imageNameFontName = __value; } QString JKQTPColorPaletteStyleAndToolsMixin::getImageNameFontName() const { - return this->imageNameFontName; + return imageNameFontName; } void JKQTPColorPaletteStyleAndToolsMixin::setImageNameFontSize(double __value) { - this->imageNameFontSize = __value; + imageNameFontSize = __value; } double JKQTPColorPaletteStyleAndToolsMixin::getImageNameFontSize() const { - return this->imageNameFontSize; + return imageNameFontSize; } JKQTPVerticalIndependentAxis *JKQTPColorPaletteStyleAndToolsMixin::getColorBarRightAxis() { - return this->colorBarRightAxis; + return colorBarRightAxis; } JKQTPHorizontalIndependentAxis *JKQTPColorPaletteStyleAndToolsMixin::getColorBarTopAxis() { - return this->colorBarTopAxis; + return colorBarTopAxis; } const JKQTPVerticalIndependentAxis *JKQTPColorPaletteStyleAndToolsMixin::getColorBarRightAxis() const { - return this->colorBarRightAxis; + return colorBarRightAxis; } const JKQTPHorizontalIndependentAxis *JKQTPColorPaletteStyleAndToolsMixin::getColorBarTopAxis() const { - return this->colorBarTopAxis; + return colorBarTopAxis; } void JKQTPColorPaletteStyleAndToolsMixin::setColorBarTopVisible(bool __value) { - this->colorBarTopVisible = __value; + colorBarTopVisible = __value; } bool JKQTPColorPaletteStyleAndToolsMixin::getColorBarTopVisible() const { - return this->colorBarTopVisible; + return colorBarTopVisible; } void JKQTPColorPaletteStyleAndToolsMixin::setColorBarRightVisible(bool __value) { - this->colorBarRightVisible = __value; + colorBarRightVisible = __value; } bool JKQTPColorPaletteStyleAndToolsMixin::getColorBarRightVisible() const { - return this->colorBarRightVisible; + return colorBarRightVisible; } @@ -540,8 +540,11 @@ JKQTPColorPaletteWithModifierStyleAndToolsMixin::JKQTPColorPaletteWithModifierSt modifierColorBarTopAxis->setAxisLabel(""); modifierColorBarRightAxis=new JKQTPHorizontalIndependentAxis (0, 100, 0, 100, parent); modifierColorBarRightAxis->setAxisLabel(""); - this->colorBarModifiedWidth=80; + colorBarModifiedWidth=80; modifierMode=JKQTPMathImageModifierMode::ModifyNone; + modifierMin=0; + modifierMax=0; + autoModifierRange=true; } @@ -735,12 +738,12 @@ void JKQTPColorPaletteWithModifierStyleAndToolsMixin::cbSetParent(JKQTBasePlotte void JKQTPColorPaletteWithModifierStyleAndToolsMixin::setModifierMode(const JKQTPMathImageModifierMode &__value) { - this->modifierMode = __value; + modifierMode = __value; } JKQTPMathImageModifierMode JKQTPColorPaletteWithModifierStyleAndToolsMixin::getModifierMode() const { - return this->modifierMode; + return modifierMode; } @@ -752,59 +755,59 @@ void JKQTPColorPaletteWithModifierStyleAndToolsMixin::modifyImage(QImage &img, c void JKQTPColorPaletteWithModifierStyleAndToolsMixin::setColorBarModifiedWidth(double __value) { - this->colorBarModifiedWidth = __value; + colorBarModifiedWidth = __value; } double JKQTPColorPaletteWithModifierStyleAndToolsMixin::getColorBarModifiedWidth() const { - return this->colorBarModifiedWidth; + return colorBarModifiedWidth; } JKQTPVerticalIndependentAxis *JKQTPColorPaletteWithModifierStyleAndToolsMixin::getModifierColorBarTopAxis() { - return this->modifierColorBarTopAxis; + return modifierColorBarTopAxis; } JKQTPHorizontalIndependentAxis *JKQTPColorPaletteWithModifierStyleAndToolsMixin::getModifierColorBarRightAxis() { - return this->modifierColorBarRightAxis ; + return modifierColorBarRightAxis ; } const JKQTPVerticalIndependentAxis *JKQTPColorPaletteWithModifierStyleAndToolsMixin::getModifierColorBarTopAxis() const { - return this->modifierColorBarTopAxis; + return modifierColorBarTopAxis; } const JKQTPHorizontalIndependentAxis *JKQTPColorPaletteWithModifierStyleAndToolsMixin::getModifierColorBarRightAxis() const { - return this->modifierColorBarRightAxis ; + return modifierColorBarRightAxis ; } void JKQTPColorPaletteWithModifierStyleAndToolsMixin::setAutoModifierRange(bool __value) { - this->autoModifierRange = __value; + autoModifierRange = __value; } bool JKQTPColorPaletteWithModifierStyleAndToolsMixin::getAutoModifierRange() const { - return this->autoModifierRange; + return autoModifierRange; } void JKQTPColorPaletteWithModifierStyleAndToolsMixin::setModifierMin(double __value) { - this->modifierMin = __value; + modifierMin = __value; } double JKQTPColorPaletteWithModifierStyleAndToolsMixin::getModifierMin() const { - return this->modifierMin; + return modifierMin; } void JKQTPColorPaletteWithModifierStyleAndToolsMixin::setModifierMax(double __value) { - this->modifierMax = __value; + modifierMax = __value; } double JKQTPColorPaletteWithModifierStyleAndToolsMixin::getModifierMax() const { - return this->modifierMax; + return modifierMax; }