From 7f32010895bdb9ddcb7ed4b90147b724a2412d50 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Wed, 21 Nov 2018 16:21:05 +0100 Subject: [PATCH] Fix coverity issues --- rtexif/rtexif.cc | 64 +++++++++++++++++++++------------------- rtexif/rtexif.h | 12 ++++---- rtgui/mydiagonalcurve.cc | 8 ++--- rtgui/myflatcurve.cc | 8 ++--- 4 files changed, 47 insertions(+), 45 deletions(-) diff --git a/rtexif/rtexif.cc b/rtexif/rtexif.cc index 893d0fe22..f1c807126 100644 --- a/rtexif/rtexif.cc +++ b/rtexif/rtexif.cc @@ -720,7 +720,7 @@ int TagDirectory::write (int start, unsigned char* buffer) return maxPos; } -void TagDirectory::applyChange (std::string name, Glib::ustring value) +void TagDirectory::applyChange (const std::string &name, const Glib::ustring &value) { std::string::size_type dp = name.find_first_of ('.'); @@ -842,14 +842,15 @@ TagDirectoryTable::TagDirectoryTable (TagDirectory* p, FILE* f, int memsize, int : TagDirectory (p, ta, border), zeroOffset (offs), valuesSize (memsize), defaultType ( type ) { values = new unsigned char[valuesSize]; - fread (values, 1, valuesSize, f); + if (fread (values, 1, valuesSize, f) == static_cast(valuesSize)) { - // Security ; will avoid to read above the buffer limit if the RT's tagDirectoryTable is longer that what's in the file - int count = valuesSize / getTypeSize (type); + // Security ; will avoid to read above the buffer limit if the RT's tagDirectoryTable is longer that what's in the file + int count = valuesSize / getTypeSize (type); - for (const TagAttrib* tattr = ta; tattr->ignore != -1 && tattr->ID < count; ++tattr) { - Tag* newTag = new Tag (this, tattr, (values + zeroOffset + tattr->ID * getTypeSize (type)), tattr->type == AUTO ? type : tattr->type); - tags.push_back (newTag); // Here we can insert more tag in the same offset because of bitfield meaning + for (const TagAttrib* tattr = ta; tattr->ignore != -1 && tattr->ID < count; ++tattr) { + Tag* newTag = new Tag (this, tattr, (values + zeroOffset + tattr->ID * getTypeSize (type)), tattr->type == AUTO ? type : tattr->type); + tags.push_back (newTag); // Here we can insert more tag in the same offset because of bitfield meaning + } } } TagDirectory* TagDirectoryTable::clone (TagDirectory* parent) @@ -1215,32 +1216,33 @@ Tag::Tag (TagDirectory* p, FILE* f, int base) defsubdirs: // read value value = new unsigned char [valuesize]; - fread (value, 1, valuesize, f); - - // count the number of valid subdirs - int sdcount = count; - - if (sdcount > 0) { - if (parent->getAttribTable() == olympusAttribs) { - sdcount = 1; - } - - // allocate space - directory = new TagDirectory*[sdcount + 1]; - - // load directories - for (size_t j = 0, i = 0; j < count; j++, i++) { - int newpos = base + toInt (j * 4, LONG); - fseek (f, newpos, SEEK_SET); - directory[i] = new TagDirectory (parent, f, base, attrib->subdirAttribs, order); - } - - // set the terminating NULL - directory[sdcount] = nullptr; - } else { + if (fread (value, 1, valuesize, f) != static_cast(valuesize)) { type = INVALID; - } + } else { + // count the number of valid subdirs + int sdcount = count; + if (sdcount > 0) { + if (parent->getAttribTable() == olympusAttribs) { + sdcount = 1; + } + + // allocate space + directory = new TagDirectory*[sdcount + 1]; + + // load directories + for (size_t j = 0, i = 0; j < count; j++, i++) { + int newpos = base + toInt (j * 4, LONG); + fseek (f, newpos, SEEK_SET); + directory[i] = new TagDirectory (parent, f, base, attrib->subdirAttribs, order); + } + + // set the terminating NULL + directory[sdcount] = nullptr; + } else { + type = INVALID; + } + } // seek back to the saved position fseek (f, save, SEEK_SET); return; diff --git a/rtexif/rtexif.h b/rtexif/rtexif.h index 1beba92ec..d7004f388 100644 --- a/rtexif/rtexif.h +++ b/rtexif/rtexif.h @@ -155,11 +155,11 @@ public: virtual Tag* findTagUpward (const char* name) const; bool getXMPTagValue (const char* name, char* value) const; - void keepTag (int ID); - virtual void addTag (Tag* a); - virtual void addTagFront (Tag* a); - virtual void replaceTag (Tag* a); - inline Tag* getTagByIndex (int ix) + void keepTag (int ID); + void addTag (Tag* a); + void addTagFront (Tag* a); + void replaceTag (Tag* a); + inline Tag* getTagByIndex (int ix) { return tags[ix]; } @@ -171,7 +171,7 @@ public: virtual int calculateSize (); virtual int write (int start, unsigned char* buffer); virtual TagDirectory* clone (TagDirectory* parent); - virtual void applyChange (std::string field, Glib::ustring value); + void applyChange (const std::string &field, const Glib::ustring &value); virtual void printAll (unsigned int level = 0) const; // reentrant debug function, keep level=0 on first call ! virtual bool CPBDump (const Glib::ustring &commFName, const Glib::ustring &imageFName, const Glib::ustring &profileFName, const Glib::ustring &defaultPParams, diff --git a/rtgui/mydiagonalcurve.cc b/rtgui/mydiagonalcurve.cc index 0bc58f28e..5eacdcc46 100644 --- a/rtgui/mydiagonalcurve.cc +++ b/rtgui/mydiagonalcurve.cc @@ -545,7 +545,7 @@ bool MyDiagonalCurve::handleEvents (GdkEvent* event) double minDistanceY = double(MIN_DISTANCE) / double(graphH - 1); switch (event->type) { - case Gdk::BUTTON_PRESS: + case GDK_BUTTON_PRESS: snapToElmt = -100; if (curve.type != DCT_Parametric) { @@ -694,7 +694,7 @@ bool MyDiagonalCurve::handleEvents (GdkEvent* event) break; - case Gdk::BUTTON_RELEASE: + case GDK_BUTTON_RELEASE: snapToElmt = -100; if (curve.type != DCT_Parametric && edited_point == -1) { @@ -755,7 +755,7 @@ bool MyDiagonalCurve::handleEvents (GdkEvent* event) break; - case Gdk::LEAVE_NOTIFY: + case GDK_LEAVE_NOTIFY: // Pointer can LEAVE even when dragging the point, so we don't modify the cursor in this case // The cursor will have to LEAVE another time after the drag... @@ -772,7 +772,7 @@ bool MyDiagonalCurve::handleEvents (GdkEvent* event) retval = true; break; - case Gdk::MOTION_NOTIFY: + case GDK_MOTION_NOTIFY: snapToElmt = -100; if (curve.type == DCT_Linear || curve.type == DCT_Spline || curve.type == DCT_NURBS) { diff --git a/rtgui/myflatcurve.cc b/rtgui/myflatcurve.cc index 70fc0c7d7..9b64ee516 100644 --- a/rtgui/myflatcurve.cc +++ b/rtgui/myflatcurve.cc @@ -613,7 +613,7 @@ bool MyFlatCurve::handleEvents (GdkEvent* event) switch (event->type) { - case Gdk::BUTTON_PRESS: + case GDK_BUTTON_PRESS: if (edited_point == -1) { //curve.type!=FCT_Parametric) { if (event->button.button == 1) { buttonPressed = true; @@ -816,7 +816,7 @@ bool MyFlatCurve::handleEvents (GdkEvent* event) break; - case Gdk::BUTTON_RELEASE: + case GDK_BUTTON_RELEASE: if (edited_point == -1) { //curve.type!=FCT_Parametric) { if (buttonPressed && event->button.button == 1) { buttonPressed = false; @@ -908,7 +908,7 @@ bool MyFlatCurve::handleEvents (GdkEvent* event) break; - case Gdk::MOTION_NOTIFY: + case GDK_MOTION_NOTIFY: if (curve.type == FCT_Linear || curve.type == FCT_MinMaxCPoints) { int previous_lit_point = lit_point; @@ -1178,7 +1178,7 @@ bool MyFlatCurve::handleEvents (GdkEvent* event) retval = true; break; - case Gdk::LEAVE_NOTIFY: + case GDK_LEAVE_NOTIFY: // Pointer can LEAVE even when dragging the point, so we don't modify the cursor in this case // The cursor will have to LEAVE another time after the drag...