From aeeaf4de3c5718e3ac094e046e8271b3beb56fb4 Mon Sep 17 00:00:00 2001 From: Ingo Date: Tue, 11 Mar 2014 11:49:06 +0100 Subject: [PATCH] Fixing some undefined behaviour, Issue 2277 --- rtengine/alignedbuffer.h | 2 +- rtengine/curves.cc | 14 +++++++------- rtengine/improcfun.cc | 20 ++++++++++---------- rtexif/pentaxattribs.cc | 5 ++++- rtexif/rtexif.cc | 4 +++- rtexif/sonyminoltaattribs.cc | 5 ++++- rtexif/stdattribs.cc | 4 +++- rtgui/adjuster.cc | 2 +- rtgui/batchtoolpanelcoord.cc | 2 +- rtgui/crophandler.cc | 2 +- rtgui/dirpyrdenoise.cc | 2 +- rtgui/editorpanel.cc | 17 ++++++++++++++--- rtgui/histogrampanel.cc | 2 +- rtgui/previewwindow.cc | 8 ++++---- 14 files changed, 55 insertions(+), 34 deletions(-) diff --git a/rtengine/alignedbuffer.h b/rtengine/alignedbuffer.h index 61fa08dff..ee3d4b586 100644 --- a/rtengine/alignedbuffer.h +++ b/rtengine/alignedbuffer.h @@ -125,7 +125,7 @@ public: MyMutex::MyLock lock(mtx); // Find available buffer - for (int i;iinUse) { buffers[i]->inUse=true; return buffers[i]; diff --git a/rtengine/curves.cc b/rtengine/curves.cc index 68dab3c7a..345237757 100644 --- a/rtengine/curves.cc +++ b/rtengine/curves.cc @@ -168,7 +168,7 @@ void CurveFactory::updatechroma ( if (outBeforeCCurveHistogramC /*&& histogramCropped*/) histNeededC = true; } - for (int i=0; i<=48000; i++) {//32768*1.414 + ... + for (int i=0; i<48000; i++) {//32768*1.414 + ... float val; if (histNeededC) { float hval = dCcurve[i]; @@ -266,7 +266,7 @@ void CurveFactory::curveLightBrightColor ( tcurve = NULL; } } - for (int i=0; i<=32768; i++) { + for (int i=0; i<32768; i++) { float val; if (histNeeded) { @@ -275,7 +275,7 @@ void CurveFactory::curveLightBrightColor ( outBeforeCCurveHistogram[hi] += histogram[i] ; } } - for (int i=0; i<=48000; i++) {//32768*1.414 + ... + for (int i=0; i<48000; i++) {//32768*1.414 + ... float val; if (histNeededC) { float hval = dCcurve[i]; @@ -336,7 +336,7 @@ void CurveFactory::curveBW ( } // create first curve if needed - for (int i=0; i<=32768; i++) { + for (int i=0; i<32768; i++) { float val; if (histNeeded) { @@ -373,7 +373,7 @@ void CurveFactory::curveCL ( bool & clcutili,const std::vector& clcurveP if (dCurve && !dCurve->isIdentity()) {needed = true;clcutili=true;} } - for (int i=0; i<=50000; i++) {//32768*1.414 + ... + for (int i=0; i<50000; i++) {//32768*1.414 + ... float val; if (histNeededCL) { float hval = dCcurve[i]; @@ -459,7 +459,7 @@ void CurveFactory::curveCL ( bool & clcutili,const std::vector& clcurveP if (dCurve && !dCurve->isIdentity()) {needed = true;ccutili=true;} } - for (int i=0; i<=48000; i++) {//32768*1.414 + ... + for (int i=0; i<48000; i++) {//32768*1.414 + ... float val; if (histNeededC) { float hval = dCcurve[i]; @@ -483,7 +483,7 @@ void CurveFactory::curveCL ( bool & clcutili,const std::vector& clcurveP if (dCurve && !dCurve->isIdentity()) {needed = true;cclutili=true;} } - for (int i=0; i<=48000; i++) {//32768*1.414 + ... + for (int i=0; i<48000; i++) {//32768*1.414 + ... float val; if (histNeededLC) { float hval = dCcurve[i]; diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index 0c2714249..99fa8d3d2 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -914,7 +914,7 @@ if(!params->edgePreservingDecompositionUI.enabled || !params->colorappearance.to if(ciedata) { //update histogram J if(pW!=1){//only with improccoordinator - for (int i=0; i<=32768; i++) {// + for (int i=0; i<32768; i++) {// if (jp) { float hval = dLcurve[i]; int hi = (int)(255.0*CLIPD(hval)); // @@ -923,7 +923,7 @@ if(!params->edgePreservingDecompositionUI.enabled || !params->colorappearance.to } } if(pW!=1){//only with improccoordinator - for (int i=0; i<=48000; i++) {// + for (int i=0; i<48000; i++) {// if (chropC) { float hvalc = dCcurve[i]; int hic = (int)(255.0*CLIPD(hvalc)); // @@ -1114,7 +1114,7 @@ if((params->colorappearance.tonecie || (params->colorappearance.tonecie && param if(ciedata) { //update histogram J and Q if(pW!=1){//only with improccoordinator - for (int i=0; i<=32768; i++) {// + for (int i=0; i<32768; i++) {// if (jp) { float hval = dLcurve[i]; int hi = (int)(255.0*CLIPD(hval)); // @@ -1124,7 +1124,7 @@ if((params->colorappearance.tonecie || (params->colorappearance.tonecie && param } //update color histogram M,s,C if(pW!=1){//only with improccoordinator - for (int i=0; i<=48000; i++) {// + for (int i=0; i<48000; i++) {// if (chropC) { float hvalc = dCcurve[i]; int hic = (int)(255.0*CLIPD(hvalc)); // @@ -1794,7 +1794,7 @@ if(!params->colorappearance.tonecie || !settings->autocielab){//normal if(ciedata) { //update histogram J if(pW!=1){//only with improccoordinator - for (int i=0; i<=32768; i++) {// + for (int i=0; i<32768; i++) {// if (jp) { float hval = dLcurve[i]; int hi = (int)(255.0f*CLIPD(hval)); // @@ -1803,7 +1803,7 @@ if(!params->colorappearance.tonecie || !settings->autocielab){//normal } } if(pW!=1){//only with improccoordinator - for (int i=0; i<=48000; i++) {// + for (int i=0; i<48000; i++) {// if (chropC) { float hvalc = dCcurve[i]; int hic = (int)(255.0f*CLIPD(hvalc)); // @@ -2005,7 +2005,7 @@ if((params->colorappearance.tonecie && (params->edgePreservingDecompositionUI.en if(ciedata) { //update histogram J and Q if(pW!=1){//only with improccoordinator - for (int i=0; i<=32768; i++) {// + for (int i=0; i<32768; i++) {// if (jp) { float hval = dLcurve[i]; int hi = (int)(255.0f*CLIPD(hval)); // @@ -2015,7 +2015,7 @@ if((params->colorappearance.tonecie && (params->edgePreservingDecompositionUI.en } //update color histogram M,s,C if(pW!=1){//only with improccoordinator - for (int i=0; i<=48000; i++) {// + for (int i=0; i<48000; i++) {// if (chropC) { float hvalc = dCcurve[i]; int hic = (int)(255.0f*CLIPD(hvalc)); // @@ -3492,7 +3492,7 @@ void ImProcFunctions::chromiLuminanceCurve (int pW, LabImage* lold, LabImage* ln } // end of parallelization //update histogram C with data chromaticity and not with CC curve if(pW!=1){//only with improccoordinator - for (int i=0; i<=48000; i++) {//32768*1.414 + ... + for (int i=0; i<48000; i++) {//32768*1.414 + ... if (chrop) { float hval = dCcurve[i]; int hi = (int)(255.0*CLIPD(hval)); // @@ -3501,7 +3501,7 @@ void ImProcFunctions::chromiLuminanceCurve (int pW, LabImage* lold, LabImage* ln } } //update histogram L with data luminance - for (int i=0; i<=65535; i++) { + for (int i=0; i<65535; i++) { if (chrop) { float hlval = dLcurve[i]; int hli = (int)(255.0*CLIPD(hlval)); diff --git a/rtexif/pentaxattribs.cc b/rtexif/pentaxattribs.cc index 991a4c6ef..810d2634f 100644 --- a/rtexif/pentaxattribs.cc +++ b/rtexif/pentaxattribs.cc @@ -888,7 +888,10 @@ class PALensTypeInterpreter : public IntLensInterpreter< int > { focalLength = flt->toDouble(); } } - return guess( lensID, focalLength, maxApertureAtFocal, liArray); + std::string retval = guess( lensID, focalLength, maxApertureAtFocal, liArray); + if(liArray) + delete [] liArray; + return retval; } }; PALensTypeInterpreter paLensTypeInterpreter; diff --git a/rtexif/rtexif.cc b/rtexif/rtexif.cc index 73aab5816..707e83d99 100644 --- a/rtexif/rtexif.cc +++ b/rtexif/rtexif.cc @@ -629,6 +629,7 @@ Tag::Tag (TagDirectory* p, FILE* f, int base) tag = get2 (f, order); type = (TagType)get2 (f, order); count = get4 (f, order); + if (!count) count = 1; makerNoteKind = NOMK; keep = false; @@ -867,8 +868,9 @@ Tag::Tag (TagDirectory* p, FILE* f, int base) } else { // read value - value = new unsigned char [valuesize]; + value = new unsigned char [valuesize+1]; fread (value, 1, valuesize, f); + value[valuesize] = '\0'; } // seek back to the saved position fseek (f, save, SEEK_SET); diff --git a/rtexif/sonyminoltaattribs.cc b/rtexif/sonyminoltaattribs.cc index 04ebb05cf..7c0059186 100644 --- a/rtexif/sonyminoltaattribs.cc +++ b/rtexif/sonyminoltaattribs.cc @@ -908,7 +908,10 @@ class SALensID2Interpreter : public IntLensInterpreter< int > { double *liArray = NULL; if (lensInfoTag) liArray = lensInfoTag->toDoubleArray(); - return guess( lensID, focalLength, maxApertureAtFocal, liArray); + std::string retval = guess( lensID, focalLength, maxApertureAtFocal, liArray); + if(liArray) + delete [] liArray; + return retval; } }; SALensID2Interpreter saLensID2Interpreter; diff --git a/rtexif/stdattribs.cc b/rtexif/stdattribs.cc index ab3a20b22..a66a64cd9 100644 --- a/rtexif/stdattribs.cc +++ b/rtexif/stdattribs.cc @@ -371,8 +371,10 @@ class UserCommentInterpreter : public Interpreter { UserCommentInterpreter () {} virtual std::string toString (Tag* t) { char *buffer = new char[t->getCount()]; - if (!strncmp((char*)t->getValue(), "ASCII\0\0\0",8)) + if (!strncmp((char*)t->getValue(), "ASCII\0\0\0",8)) { strncpy (buffer, (char*)t->getValue()+8, t->getCount()-8); + buffer[t->getCount()-8] = '\0'; + } else buffer[0]=0; std::string retVal(buffer); diff --git a/rtgui/adjuster.cc b/rtgui/adjuster.cc index 0b24ba645..6e90b5847 100644 --- a/rtgui/adjuster.cc +++ b/rtgui/adjuster.cc @@ -32,7 +32,7 @@ static double one2one(double val) { return val; } Adjuster::Adjuster (Glib::ustring vlabel, double vmin, double vmax, double vstep, double vdefault, Gtk::Image *imgIcon1, Gtk::Image *imgIcon2, double2double_fun slider2value_, double2double_fun value2slider_) { Gtk::HBox *hbox2=NULL; - + label = NULL; adjusterListener = NULL; afterReset = false; blocked = false; diff --git a/rtgui/batchtoolpanelcoord.cc b/rtgui/batchtoolpanelcoord.cc index e818da969..a99fa4bd5 100644 --- a/rtgui/batchtoolpanelcoord.cc +++ b/rtgui/batchtoolpanelcoord.cc @@ -25,7 +25,7 @@ using namespace rtengine::procparams; -BatchToolPanelCoordinator::BatchToolPanelCoordinator (FilePanel* parent) : ToolPanelCoordinator(), parent(parent) { +BatchToolPanelCoordinator::BatchToolPanelCoordinator (FilePanel* parent) : ToolPanelCoordinator(), parent(parent), somethingChanged(false) { blockedUpdate = false; // remove exif panel and iptc panel diff --git a/rtgui/crophandler.cc b/rtgui/crophandler.cc index 4efcaa466..7f6e0197a 100644 --- a/rtgui/crophandler.cc +++ b/rtgui/crophandler.cc @@ -28,7 +28,7 @@ using namespace rtengine; CropHandler::CropHandler () : zoom(10), cx(0), cy(0), cw(0), ch(0), cropX(0), cropY(0), cropW(0), cropH(0), enabled(false), - cropimg(NULL), cropimgtrue(NULL), ipc(NULL), crop(NULL), listener(NULL) { + cropimg(NULL), cropimgtrue(NULL), ipc(NULL), crop(NULL), listener(NULL), isLowUpdatePriority(false) { chi = new CropHandlerIdleHelper; chi->destroyed = false; diff --git a/rtgui/dirpyrdenoise.cc b/rtgui/dirpyrdenoise.cc index 851549dc8..6d53fbd51 100644 --- a/rtgui/dirpyrdenoise.cc +++ b/rtgui/dirpyrdenoise.cc @@ -23,7 +23,7 @@ using namespace rtengine; using namespace rtengine::procparams; -DirPyrDenoise::DirPyrDenoise () : Gtk::VBox(), FoldableToolPanel(this) { +DirPyrDenoise::DirPyrDenoise () : Gtk::VBox(), FoldableToolPanel(this), lastenhance(false) { set_border_width(4); diff --git a/rtgui/editorpanel.cc b/rtgui/editorpanel.cc index c02bc6edb..1a48eb0b4 100755 --- a/rtgui/editorpanel.cc +++ b/rtgui/editorpanel.cc @@ -32,7 +32,7 @@ using namespace rtengine::procparams; EditorPanel::EditorPanel (FilePanel* filePanel) - : beforePreviewHandler(NULL), beforeIarea(NULL), parent(NULL), ipc(NULL), beforeIpc(NULL), isProcessing(false), catalogPane(NULL) { + : beforePreviewHandler(NULL), beforeIarea(NULL), parent(NULL), ipc(NULL), beforeIpc(NULL), isProcessing(false), catalogPane(NULL), iHistoryShow(NULL), iHistoryHide(NULL), iBeforeLockON(NULL),iBeforeLockOFF(NULL), iRightPanel_1_Show(NULL), iRightPanel_1_Hide(NULL) { epih = new EditorPanelIdleHelper; epih->epanel = this; @@ -374,8 +374,19 @@ EditorPanel::~EditorPanel () { delete catalogPane; if (!iTopPanel_1_Show) delete iTopPanel_1_Show; - if (!iTopPanel_1_Hide) delete iTopPanel_1_Hide; - + if (!iTopPanel_1_Hide) delete iTopPanel_1_Hide; + if (iHistoryShow) + delete iHistoryShow; + if (iHistoryHide) + delete iHistoryHide; + if(iBeforeLockON) + delete iBeforeLockON; + if(iBeforeLockOFF) + delete iBeforeLockOFF; + if(iRightPanel_1_Show) + delete iRightPanel_1_Show; + if(iRightPanel_1_Hide) + delete iRightPanel_1_Hide; } void EditorPanel::leftPaneButtonReleased(GdkEventButton *event) { diff --git a/rtgui/histogrampanel.cc b/rtgui/histogrampanel.cc index 54e568328..f1cd465a8 100644 --- a/rtgui/histogrampanel.cc +++ b/rtgui/histogrampanel.cc @@ -547,7 +547,7 @@ void HistogramRGBArea::styleChanged (const Glib::RefPtr& style) { // // HistogramArea HistogramArea::HistogramArea (FullModeListener *fml) : //needChroma unactive by default - valid(false), fullMode(options.histogramFullMode), myFullModeListener(fml), oldwidth(-1), needLuma(true), needRed(true), needGreen(true), needBlue(true), rawMode(false), needChroma(false) { + valid(false), fullMode(options.histogramFullMode), myFullModeListener(fml), oldwidth(-1), oldheight(-1), needLuma(true), needRed(true), needGreen(true), needBlue(true), rawMode(false), needChroma(false) { lhist(256); rhist(256); diff --git a/rtgui/previewwindow.cc b/rtgui/previewwindow.cc index fafd6a563..ba4a5fe08 100644 --- a/rtgui/previewwindow.cc +++ b/rtgui/previewwindow.cc @@ -21,7 +21,7 @@ #include "imagearea.h" #include "cursormanager.h" -PreviewWindow::PreviewWindow () : previewHandler(NULL), mainCropWin(NULL), imageArea(NULL), isMoving(false) { +PreviewWindow::PreviewWindow () : previewHandler(NULL), mainCropWin(NULL), imageArea(NULL), isMoving(false), zoom(0.0) { rconn = signal_size_allocate().connect( sigc::mem_fun(*this, &PreviewWindow::on_resized) ); } @@ -36,7 +36,7 @@ void PreviewWindow::getObservedFrameArea (int& x, int& y, int& w, int& h) { if (mainCropWin) { int cropX, cropY, cropW, cropH; - mainCropWin->getCropRectangle (cropX, cropY, cropW, cropH); + mainCropWin->getCropRectangle (cropX, cropY, cropW, cropH); // translate it to screen coordinates x = imgX + cropX*zoom; y = imgY + cropY*zoom; @@ -100,12 +100,12 @@ bool PreviewWindow::on_expose_event (GdkEventExpose* event) { window->draw_drawable (get_style()->get_base_gc(Gtk::STATE_NORMAL), backBuffer, 0, 0, 0, 0, -1, -1); - if (mainCropWin) { + if (mainCropWin && zoom > 0.0) { Cairo::RefPtr cr = get_window()->create_cairo_context(); int x, y, w, h; getObservedFrameArea (x, y, w, h); cr->set_source_rgb (1.0, 1.0, 1.0); - cr->set_line_width (3); + cr->set_line_width (3); cr->rectangle (x-1.5, y-1.5, w+2, h+2); cr->stroke (); cr->set_source_rgb (1.0, 0.0, 0.0);