Fixed some coverity issues

This commit is contained in:
heckflosse 2017-06-12 17:54:34 +02:00
parent e8bbefef7a
commit 97e558a040
21 changed files with 97 additions and 96 deletions

View File

@ -102,6 +102,9 @@ int calcDistortion(unsigned char* img1, unsigned char* img2, int ncols, int nrow
if (n < 5) {
printf ("Not sufficient features.\n");
distortion = 0.0;
KLTFreeFeatureTable(ft);
KLTFreeFeatureList(fl);
KLTFreeTrackingContext(tc);
return -1;
}
@ -154,6 +157,9 @@ int calcDistortion(unsigned char* img1, unsigned char* img2, int ncols, int nrow
if (new_n < 5) {
printf ("Not sufficient features.\n");
distortion = 0.0;
KLTFreeFeatureTable(ft);
KLTFreeFeatureList(fl);
KLTFreeTrackingContext(tc);
return -1;
}
@ -252,17 +258,27 @@ int calcDistortion(unsigned char* img1, unsigned char* img2, int ncols, int nrow
if (total_delta / new_n > DELTA_2) {
printf ("Deviation is too big.\n");
distortion = 0.0;
KLTFreeFeatureTable(ft);
KLTFreeFeatureList(fl);
KLTFreeTrackingContext(tc);
return -2;
}
if (rxy < RXY_LIMIT) {
printf ("Not linear enough\n");
distortion = 0.0;
KLTFreeFeatureTable(ft);
KLTFreeFeatureList(fl);
KLTFreeTrackingContext(tc);
return -3;
}
printf ("distortion amount=%lf scale=%lf deviation=%lf, rxy=%lf\n", a, b, total_delta / n, rxy);
distortion = a;
KLTFreeFeatureTable(ft);
KLTFreeFeatureList(fl);
KLTFreeTrackingContext(tc);
return 1;
}

View File

@ -89,7 +89,7 @@ class ImProcFunctions
}
double rd, gd, bd;
double yr[4], yg[4], yb[4];
double yr[4] = {0.0}, yg[4] = {0.0}, yb[4] = {0.0};
for (int k = ys, kx = 0; k < ys + 4; k++, kx++) {
rd = gd = bd = 0.0;

View File

@ -172,7 +172,7 @@ void LCPPersModel::print() const
// if !vignette then geometric and CA
LCPMapper::LCPMapper(LCPProfile* pProf, float focalLength, float focalLength35mm, float focusDist, float aperture, bool vignette, bool useCADistP,
int fullWidth, int fullHeight, const CoarseTransformParams& coarse, int rawRotationDeg)
int fullWidth, int fullHeight, const CoarseTransformParams& coarse, int rawRotationDeg) :useCADist(false), swapXY(false), isFisheye(false), enableCA(false)
{
if (pProf == nullptr) {
return;
@ -388,6 +388,7 @@ LCPProfile::LCPProfile(const Glib::ustring &fname)
FILE *pFile = g_fopen(fname.c_str (), "rb");
if(pFile) {
bool done;
do {
@ -400,6 +401,7 @@ LCPProfile::LCPProfile(const Glib::ustring &fname)
} while (!done);
fclose(pFile);
}
XML_ParserFree(parser);
@ -736,7 +738,7 @@ void XMLCALL LCPProfile::XmlStartHandler(void *pLCPProfile, const char *el, cons
nameStart++;
}
strcpy(pProf->lastTag, nameStart);
strncpy(pProf->lastTag, nameStart, 255);
pProf->handle_text(attr[i+1]);
//XmlTextHandler(pLCPProfile, attr[i + 1], strlen(attr[i + 1]));

View File

@ -768,6 +768,8 @@ void WaveletParams::setDefaults()
for(int i = 0; i < 9; i ++) {
ch[i] = 0;
}
greenlow = greenmed = greenhigh = 0.0;
bluelow = bluemed = bluehigh = 0.0;
}
@ -832,6 +834,7 @@ void DirPyrDenoiseParams::setDefaults()
redchro = 0;
bluechro = 0;
gamma = 1.7;
perform = false;
}
void DirPyrDenoiseParams::getCurves(NoiseCurve &lCurve, NoiseCurve &cCurve) const

View File

@ -189,6 +189,7 @@ void rotate(unsigned char* img, int& w, int& h, int deg)
void hflip(unsigned char* img, int w, int h)
{
if(w > 0 && h > 0) {
unsigned char* flipped = new unsigned char[3 * w * h];
int ix = 0;
@ -201,10 +202,12 @@ void hflip(unsigned char* img, int w, int h)
memcpy(img, flipped, 3 * w * h);
delete[] flipped;
}
}
void vflip(unsigned char* img, int w, int h)
{
if(w > 0 && h > 0) {
unsigned char* flipped = new unsigned char[3 * w * h];
int ix = 0;
@ -217,6 +220,7 @@ void vflip(unsigned char* img, int w, int h)
memcpy(img, flipped, 3 * w * h);
delete[] flipped;
}
}
Glib::ustring getFileExtension(const Glib::ustring& filename)

View File

@ -780,6 +780,7 @@ Tag::Tag (TagDirectory* p, FILE* f, int base)
// (only a small part of it will actually be parsed though)
if ((int)type < 1 || (int)type > 14 || count > 10 * 1024 * 1024) {
type = INVALID;
valuesize = 0;
return;
}
@ -1346,7 +1347,9 @@ void Tag::fromString (const char* v, int size)
value = new unsigned char [valuesize];
}
if(value) {
memcpy ((char*)value, v, valuesize);
}
}
int Tag::toInt (int ofs, TagType astype)
@ -1450,7 +1453,6 @@ double Tag::toDouble (int ofs)
return 0.; // Quick fix for missing cases (INVALID, DOUBLE, OLYUNDEF, SUBDIR)
}
return 0.;
}
/**
@ -1655,17 +1657,15 @@ int Tag::calculateSize ()
if (j > 1) {
size += 4 * j;
}
if (makerNoteKind != NOMK) {
count = directory[0]->calculateSize () / getTypeSize (type);
}
} else if (valuesize > 4) {
size += valuesize + (valuesize % 2); // we align tags to even byte positions
}
if (makerNoteKind != NOMK) {
count = directory[0]->calculateSize () / getTypeSize (type);
}
if (makerNoteKind == NIKON3 || makerNoteKind == OLYMPUS2 || makerNoteKind == FUJI) {
size += valuesize;
} else if (makerNoteKind == HEADERIFD) {
if (makerNoteKind == NIKON3 || makerNoteKind == OLYMPUS2 || makerNoteKind == FUJI || makerNoteKind == HEADERIFD) {
size += valuesize;
}
@ -1913,6 +1913,7 @@ TagDirectory* ExifManager::parseCIFF (FILE* f, int base, int length)
Tag* ExifManager::saveCIFFMNTag (FILE* f, TagDirectory* root, int len, const char* name)
{
int s = ftell (f);
if(s >= 0) {
char* data = new char [len];
fread (data, len, 1, f);
TagDirectory* mn = root->getTag ("Exif")->getDirectory()->getTag ("MakerNote")->getDirectory();
@ -1920,7 +1921,11 @@ Tag* ExifManager::saveCIFFMNTag (FILE* f, TagDirectory* root, int len, const cha
cs->initUndefArray (data, len);
mn->addTag (cs);
fseek (f, s, SEEK_SET);
delete [] data;
return cs;
} else {
return nullptr;
}
}
void ExifManager::parseCIFF (FILE* f, int base, int length, TagDirectory* root)
@ -2500,6 +2505,8 @@ parse_leafdata (TagDirectory* root, ByteOrder order)
if (*p1 != '\0') {
t->initInt (atoi (p1), LONG);
exif->getDirectory()->addTagFront (t);
} else {
delete t;
}
} else if (strcmp (tag, "DateTimeOriginal") == 0 &&
sscanf (val, "%d-%d-%dT%d:%d:%dZ",

View File

@ -588,38 +588,23 @@ void Adjuster::editedToggled ()
eventPending = false;
}
double Adjuster::trimValue (double val)
void Adjuster::trimValue (double &val)
{
if (val > vMax) {
val = vMax; // shapeValue(vMax) ?
} else if (val < vMin) {
val = vMin; // shapeValue(vMin) ?
}
val = rtengine::LIM(val, vMin, vMax);
return val;
}
int Adjuster::trimValue (int val)
void Adjuster::trimValue (int &val)
{
if (val > (int)vMax) {
val = (int)vMax; // shapeValue(vMax) ?
} else if (val < (int)vMin) {
val = (int)vMin; // shapeValue(vMin) ?
}
val = rtengine::LIM(val, static_cast<int>(vMin), static_cast<int>(vMax));
return val;
}
float Adjuster::trimValue (float val)
void Adjuster::trimValue (float &val)
{
if (val > (float)vMax) {
val = (float)vMax; // shapeValue(vMax) ?
} else if (val < (float)vMin) {
val = (float)vMin; // shapeValue(vMin) ?
}
val = rtengine::LIM(val, static_cast<float>(vMin), static_cast<float>(vMax));
return val;
}

View File

@ -56,13 +56,11 @@ protected:
sigc::connection autoChange;
sigc::connection buttonReleaseSlider;
sigc::connection buttonReleaseSpin;
bool listenerReady;
double defaultVal; // current default value (it can change when switching from ADD or SET mode)
double ctorDefaultVal; // default value at construction time
EditedState editedState;
EditedState defEditedState;
EditedState autoState;
EditedState defAutoState;
int digits;
Gtk::CheckButton* editedCheckBox;
bool afterReset;
@ -172,9 +170,9 @@ public:
void resetValue (bool toInitial);
void resetPressed (GdkEventButton* event);
void editedToggled ();
double trimValue (double val);
float trimValue (float val);
int trimValue (int val);
void trimValue (double &val);
void trimValue (float &val);
void trimValue (int &val);
};
#endif

View File

@ -1219,10 +1219,6 @@ void Crop::cropResized (int &x, int &y, int& x2, int& y2)
W = maxw;
}
if (H > maxh) {
H = maxh;
}
if (fixr->get_active()) {
double r = getRatio ();

View File

@ -895,7 +895,7 @@ void CropWindow::pointerMoved (int bstate, int x, int y)
} else if (state == SDragPicker) {
Coord imgPos;
action_x = x - press_x;
action_x = y - press_y;
action_y = y - press_y;
screenCoordToImage (x, y, imgPos.x, imgPos.y);
if (imgPos.x < 0) {
imgPos.x = 0;

View File

@ -525,7 +525,8 @@ void DiagonalCurveEditorSubGroup::pipetteDrag(EditDataProvider *provider, int mo
case (DCT_Parametric):
if (editedAdjuster) {
int trimmedValue = editedAdjuster->trimValue(editedAdjusterValue - (provider->deltaScreen.y / 2));
int trimmedValue = editedAdjusterValue - (provider->deltaScreen.y / 2);
editedAdjuster->trimValue(trimmedValue);
if (trimmedValue != editedAdjuster->getIntValue()) {
editedAdjuster->setValue(trimmedValue);

View File

@ -22,7 +22,7 @@
#include "inspector.h"
#include "placesbrowser.h"
FilePanel::FilePanel () : parent(nullptr)
FilePanel::FilePanel () : parent(nullptr), error(0)
{
// Contains everything except for the batch Tool Panel and tabs (Fast Export, Inspect, etc)

View File

@ -191,7 +191,7 @@ void FilmSimulation::setAdjusterBehavior( bool strength )
void FilmSimulation::trimValues( rtengine::procparams::ProcParams* pp )
{
pp->filmSimulation.strength = m_strength->trimValue( pp->filmSimulation.strength );
m_strength->trimValue( pp->filmSimulation.strength );
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

View File

@ -1281,6 +1281,8 @@ MyImageMenuItem::MyImageMenuItem(Glib::ustring label, Glib::ustring imageFileNam
if (!imageFileName.empty()) {
image = Gtk::manage( new RTImage(imageFileName) );
box->attach_next_to(*image, Gtk::POS_LEFT, 1, 1);
} else {
image = nullptr;
}
box->attach_next_to(*this->label, Gtk::POS_RIGHT, 1, 1);

View File

@ -259,6 +259,7 @@ void Inspector::switchImage (const Glib::ustring &fullPath)
images.push_back(iBuffer);
currImage = images.at(images.size() - 1);
} else {
delete iBuffer;
currImage = nullptr;
}
}

View File

@ -168,11 +168,6 @@ PreviewLoader::PreviewLoader():
{
}
PreviewLoader::~PreviewLoader()
{
delete impl_;
}
PreviewLoader* PreviewLoader::getInstance()
{
static PreviewLoader instance_;

View File

@ -88,7 +88,6 @@ public:
private:
PreviewLoader();
~PreviewLoader();
class Impl;
Impl* impl_;

View File

@ -753,7 +753,6 @@ void ProfilePanel::initProfile (const Glib::ustring& profileFullPath, ProcParams
// adding the Last Saved combobox entry, if needed
if (lastsaved) {
defprofile = lastsaved;
lasSavedEntry = getLastSavedRow();
}

View File

@ -60,7 +60,6 @@ protected:
//sigc::connection spinChange;
sigc::connection selectorChange;
sigc::connection editedChange;
bool listenerReady;
double initialDefaultVal[4]; // default value at construction time
EditedState editedState;
EditedState defEditedState;

View File

@ -184,11 +184,6 @@ ThumbImageUpdater::ThumbImageUpdater():
{
}
ThumbImageUpdater::~ThumbImageUpdater()
{
delete impl_;
}
void
ThumbImageUpdater::add(ThumbBrowserEntryBase* tbe, bool* priority, bool upgrade, ThumbImageUpdateListener* l)
{

View File

@ -93,7 +93,6 @@ public:
private:
ThumbImageUpdater();
~ThumbImageUpdater();
class Impl;
Impl* impl_;