Skip to content

Commit bacc210

Browse files
devnexenDavid Carlier
authored andcommitted
fixing segfaults occuring when launching those unit tests
1 parent 0d10eb5 commit bacc210

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

modules/calib3d/test/test_cameracalibration.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,8 @@ void CV_StereoCalibrationTest::run( int )
15701570
{
15711571
ts->printf( cvtest::TS::LOG, "The file %s can not be opened or has invalid content\n", filepath.c_str() );
15721572
ts->set_failed_test_info( f ? cvtest::TS::FAIL_INVALID_TEST_DATA : cvtest::TS::FAIL_MISSING_TEST_DATA );
1573-
fclose(f);
1573+
if (f)
1574+
fclose(f);
15741575
return;
15751576
}
15761577

modules/ml/src/lr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ bool LogisticRegressionImpl::train(const Ptr<TrainData>& trainData, int)
138138
// return value
139139
bool ok = false;
140140

141+
if (trainData.empty()) {
142+
return false;
143+
}
141144
clear();
142145
Mat _data_i = trainData->getSamples();
143146
Mat _labels_i = trainData->getResponses();

modules/ml/test/test_emknearestkmeans.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ class CV_EMTest_Classification : public cvtest::BaseTest
618618
{
619619
ts->printf(cvtest::TS::LOG, "File with spambase dataset cann't be read.\n");
620620
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
621+
return;
621622
}
622623

623624
Mat samples = data->getSamples();

modules/ml/test/test_lr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ void CV_LRTest::run( int /*start_from*/ )
9595
string dataFileName = ts->get_data_path() + "iris.data";
9696
Ptr<TrainData> tdata = TrainData::loadFromCSV(dataFileName, 0);
9797

98+
if (tdata.empty()) {
99+
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
100+
return;
101+
}
102+
98103
// run LR classifier train classifier
99104
Ptr<LogisticRegression> p = LogisticRegression::create();
100105
p->setLearningRate(1.0);

modules/shape/test/test_shape.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class ShapeBaseTest : public cvtest::BaseTest
8383

8484
vector<PointType> convertContourType(const Mat& currentQuery) const
8585
{
86+
if (currentQuery.empty()) {
87+
return vector<PointType>();
88+
}
8689
vector<vector<Point> > _contoursQuery;
8790
findContours(currentQuery, _contoursQuery, RETR_LIST, CHAIN_APPROX_NONE);
8891

0 commit comments

Comments
 (0)