Fix coverity issues

This commit is contained in:
heckflosse
2018-11-21 16:21:05 +01:00
parent b98f73e51b
commit 7f32010895
4 changed files with 47 additions and 45 deletions

View File

@@ -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<size_t>(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<size_t>(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;

View File

@@ -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,

View File

@@ -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) {

View File

@@ -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...