motioncells: protect against not found id

If searchIdx() doesn't find the id it returns -1, which breaks
motioncelssvector.at (idx). Check for it and return if not found.

Changing a few other lines for style consistency.
This commit is contained in:
Luis de Bethencourt 2015-03-05 15:54:55 +00:00
parent 632854eba3
commit 290508932e

View file

@ -89,12 +89,15 @@ perform_detection_motion_cells (IplImage * p_image, double p_sensitivity,
{ {
int idx = 0; int idx = 0;
idx = searchIdx (p_id); idx = searchIdx (p_id);
return motioncellsvector.at (idx).mc->performDetectionMotionCells (p_image, if (idx > -1)
p_sensitivity, p_framerate, p_gridx, p_gridy, p_timestamp_millisec, return motioncellsvector.at (idx).mc->performDetectionMotionCells (p_image,
p_isVisible, p_useAlpha, motionmaskcoord_count, motionmaskcoords, p_sensitivity, p_framerate, p_gridx, p_gridy, p_timestamp_millisec,
motionmaskcells_count, motionmaskcellsidx, motioncellscolor, p_isVisible, p_useAlpha, motionmaskcoord_count, motionmaskcoords,
motioncells_count, motioncellsidx, starttime, p_datafile, motionmaskcells_count, motionmaskcellsidx, motioncellscolor,
p_changed_datafile, p_thickness); motioncells_count, motioncellsidx, starttime, p_datafile,
p_changed_datafile, p_thickness);
else
return -1;
} }
@ -103,7 +106,8 @@ setPrevFrame (IplImage * p_prevFrame, int p_id)
{ {
int idx = 0; int idx = 0;
idx = searchIdx (p_id); idx = searchIdx (p_id);
motioncellsvector.at (idx).mc->setPrevFrame (p_prevFrame); if (idx > -1)
motioncellsvector.at (idx).mc->setPrevFrame (p_prevFrame);
} }
char * char *
@ -113,10 +117,8 @@ getMotionCellsIdx (int p_id)
idx = searchIdx (p_id); idx = searchIdx (p_id);
if (idx > -1) if (idx > -1)
return motioncellsvector.at (idx).mc->getMotionCellsIdx (); return motioncellsvector.at (idx).mc->getMotionCellsIdx ();
else { else
return p_str; return p_str;
}
} }
int int
@ -161,9 +163,8 @@ getInitDataFileFailed (int p_id)
idx = searchIdx (p_id); idx = searchIdx (p_id);
if (idx > -1) if (idx > -1)
return motioncellsvector.at (idx).mc->getDatafileInitFailed (); return motioncellsvector.at (idx).mc->getDatafileInitFailed ();
else { else
return p_str; return p_str;
}
} }
char * char *
@ -173,9 +174,8 @@ getSaveDataFileFailed (int p_id)
idx = searchIdx (p_id); idx = searchIdx (p_id);
if (idx > -1) if (idx > -1)
return motioncellsvector.at (idx).mc->getDatafileSaveFailed (); return motioncellsvector.at (idx).mc->getDatafileSaveFailed ();
else { else
return p_str; return p_str;
}
} }
int int