diff --git a/apps/haartraining/cvboost.cpp b/apps/haartraining/cvboost.cpp index c32a313101..2ee363790e 100644 --- a/apps/haartraining/cvboost.cpp +++ b/apps/haartraining/cvboost.cpp @@ -3390,6 +3390,7 @@ CvClassifier* cvCreateBtClassifierFromFile( const char* filename ) int num_features; int num_classes; int type; + int values_read = -1; CV_ASSERT( filename != NULL ); @@ -3400,7 +3401,8 @@ CvClassifier* cvCreateBtClassifierFromFile( const char* filename ) CV_ERROR( CV_StsError, "Unable to open file" ); } - fscanf( file, "%d %d %d %d", &type, &num_classes, &num_features, &num_classifiers ); + values_read = fscanf( file, "%d %d %d %d", &type, &num_classes, &num_features, &num_classifiers ); + CV_Assert(values_read == 4); CV_ASSERT( type >= (int) CV_DABCLASS && type <= (int) CV_MREG ); CV_ASSERT( num_features > 0 ); @@ -3418,7 +3420,8 @@ CvClassifier* cvCreateBtClassifierFromFile( const char* filename ) int count; CvCARTClassifier* tree; - fscanf( file, "%d", &count ); + values_read = fscanf( file, "%d", &count ); + CV_Assert(values_read == 1); data_size = sizeof( *tree ) + count * ( sizeof( *(tree->compidx) ) + sizeof( *(tree->threshold) ) + @@ -3439,14 +3442,16 @@ CvClassifier* cvCreateBtClassifierFromFile( const char* filename ) tree->count = count; for( j = 0; j < tree->count; j++ ) { - fscanf( file, "%d %g %d %d", &(tree->compidx[j]), + values_read = fscanf( file, "%d %g %d %d", &(tree->compidx[j]), &(tree->threshold[j]), &(tree->left[j]), &(tree->right[j]) ); + CV_Assert(values_read == 4); } for( j = 0; j <= tree->count; j++ ) { - fscanf( file, "%g", &(tree->val[j]) ); + values_read = fscanf( file, "%g", &(tree->val[j]) ); + CV_Assert(values_read == 1); } ptr->trees[i] = tree; } @@ -3553,6 +3558,7 @@ void cvReadTrainData( const char* filename, int flags, int m, n; int i, j; float val; + int values_read = -1; if( filename == NULL ) { @@ -3575,7 +3581,8 @@ void cvReadTrainData( const char* filename, int flags, CV_ERROR( CV_StsError, "Unable to open file" ); } - fscanf( file, "%d %d", &m, &n ); + values_read = fscanf( file, "%d %d", &m, &n ); + CV_Assert(values_read == 2); if( CV_IS_ROW_SAMPLE( flags ) ) { @@ -3592,7 +3599,8 @@ void cvReadTrainData( const char* filename, int flags, { for( j = 0; j < n; j++ ) { - fscanf( file, "%f", &val ); + values_read = fscanf( file, "%f", &val ); + CV_Assert(values_read == 1); if( CV_IS_ROW_SAMPLE( flags ) ) { CV_MAT_ELEM( **trainData, float, i, j ) = val; @@ -3602,7 +3610,8 @@ void cvReadTrainData( const char* filename, int flags, CV_MAT_ELEM( **trainData, float, j, i ) = val; } } - fscanf( file, "%f", &val ); + values_read = fscanf( file, "%f", &val ); + CV_Assert(values_read == 2); CV_MAT_ELEM( **trainClasses, float, 0, i ) = val; } diff --git a/apps/haartraining/cvhaarclassifier.cpp b/apps/haartraining/cvhaarclassifier.cpp index 004508b43a..458712b3b3 100644 --- a/apps/haartraining/cvhaarclassifier.cpp +++ b/apps/haartraining/cvhaarclassifier.cpp @@ -285,18 +285,20 @@ void icvLoadHaarFeature( CvTHaarFeature* feature, FILE* file ) int weight; nrect = 0; - fscanf( file, "%d", &nrect ); + int values_read = fscanf( file, "%d", &nrect ); + CV_Assert(values_read == 1); assert( nrect <= CV_HAAR_FEATURE_MAX ); for( j = 0; j < nrect; j++ ) { - fscanf( file, "%d %d %d %d %d %d", + values_read = fscanf( file, "%d %d %d %d %d %d", &(feature->rect[j].r.x), &(feature->rect[j].r.y), &(feature->rect[j].r.width), &(feature->rect[j].r.height), &tmp, &weight ); + CV_Assert(values_read == 6); feature->rect[j].weight = (float) weight; } for( j = nrect; j < CV_HAAR_FEATURE_MAX; j++ ) @@ -307,7 +309,8 @@ void icvLoadHaarFeature( CvTHaarFeature* feature, FILE* file ) feature->rect[j].r.height = 0; feature->rect[j].weight = 0.0f; } - fscanf( file, "%s", &(feature->desc[0]) ); + values_read = fscanf( file, "%s", &(feature->desc[0]) ); + CV_Assert(values_read == 1); feature->tilted = ( feature->desc[0] == 't' ); } @@ -342,19 +345,23 @@ CvIntHaarClassifier* icvLoadCARTHaarClassifier( FILE* file, int step ) int count; ptr = NULL; - fscanf( file, "%d", &count ); + int values_read = fscanf( file, "%d", &count ); + CV_Assert(values_read == 1); + if( count > 0 ) { ptr = (CvCARTHaarClassifier*) icvCreateCARTHaarClassifier( count ); for( i = 0; i < count; i++ ) { icvLoadHaarFeature( &(ptr->feature[i]), file ); - fscanf( file, "%f %d %d", &(ptr->threshold[i]), &(ptr->left[i]), + values_read = fscanf( file, "%f %d %d", &(ptr->threshold[i]), &(ptr->left[i]), &(ptr->right[i]) ); + CV_Assert(values_read == 3); } for( i = 0; i <= count; i++ ) { - fscanf( file, "%f", &(ptr->val[i]) ); + values_read = fscanf( file, "%f", &(ptr->val[i]) ); + CV_Assert(values_read == 1); } icvConvertToFastHaarFeature( ptr->feature, ptr->fastfeature, ptr->count, step ); } @@ -402,7 +409,8 @@ CvIntHaarClassifier* icvLoadCARTStageHaarClassifierF( FILE* file, int step ) float threshold; count = 0; - fscanf( file, "%d", &count ); + int values_read = fscanf( file, "%d", &count ); + CV_Assert(values_read == 1); if( count > 0 ) { ptr = (CvStageHaarClassifier*) icvCreateStageHaarClassifier( count, 0.0F ); @@ -411,7 +419,8 @@ CvIntHaarClassifier* icvLoadCARTStageHaarClassifierF( FILE* file, int step ) ptr->classifier[i] = icvLoadCARTHaarClassifier( file, step ); } - fscanf( file, "%f", &threshold ); + values_read = fscanf( file, "%f", &threshold ); + CV_Assert(values_read == 1); ptr->threshold = threshold; /* to be compatible with the previous implementation */ diff --git a/modules/calib3d/test/test_cameracalibration.cpp b/modules/calib3d/test/test_cameracalibration.cpp index abb9fa7ded..23bf5f0961 100644 --- a/modules/calib3d/test/test_cameracalibration.cpp +++ b/modules/calib3d/test/test_cameracalibration.cpp @@ -333,6 +333,7 @@ void CV_CameraCalibrationTest::run( int start_from ) goodTransVects = 0; goodRotMatrs = 0; int progress = 0; + int values_read = -1; sprintf( filepath, "%scameracalibration/", ts->get_data_path().c_str() ); sprintf( filename, "%sdatafiles.txt", filepath ); @@ -344,11 +345,13 @@ void CV_CameraCalibrationTest::run( int start_from ) goto _exit_; } - fscanf(datafile,"%d",&numTests); + values_read = fscanf(datafile,"%d",&numTests); + CV_Assert(values_read == 1); for( currTest = start_from; currTest < numTests; currTest++ ) { - fscanf(datafile,"%s",i_dat_file); + values_read = fscanf(datafile,"%s",i_dat_file); + CV_Assert(values_read == 1); sprintf(filename, "%s%s", filepath, i_dat_file); file = fopen(filename,"r"); @@ -366,7 +369,8 @@ void CV_CameraCalibrationTest::run( int start_from ) continue; // if there is more than one test, just skip the test } - fscanf(file,"%d %d\n",&(imageSize.width),&(imageSize.height)); + values_read = fscanf(file,"%d %d\n",&(imageSize.width),&(imageSize.height)); + CV_Assert(values_read == 2); if( imageSize.width <= 0 || imageSize.height <= 0 ) { ts->printf( cvtest::TS::LOG, "Image size in test file is incorrect\n" ); @@ -375,7 +379,8 @@ void CV_CameraCalibrationTest::run( int start_from ) } /* Read etalon size */ - fscanf(file,"%d %d\n",&(etalonSize.width),&(etalonSize.height)); + values_read = fscanf(file,"%d %d\n",&(etalonSize.width),&(etalonSize.height)); + CV_Assert(values_read == 2); if( etalonSize.width <= 0 || etalonSize.height <= 0 ) { ts->printf( cvtest::TS::LOG, "Pattern size in test file is incorrect\n" ); @@ -386,7 +391,8 @@ void CV_CameraCalibrationTest::run( int start_from ) numPoints = etalonSize.width * etalonSize.height; /* Read number of images */ - fscanf(file,"%d\n",&numImages); + values_read = fscanf(file,"%d\n",&numImages); + CV_Assert(values_read == 1); if( numImages <=0 ) { ts->printf( cvtest::TS::LOG, "Number of images in test file is incorrect\n"); @@ -427,7 +433,8 @@ void CV_CameraCalibrationTest::run( int start_from ) for( currPoint = 0; currPoint < numPoints; currPoint++ ) { double x,y,z; - fscanf(file,"%lf %lf %lf\n",&x,&y,&z); + values_read = fscanf(file,"%lf %lf %lf\n",&x,&y,&z); + CV_Assert(values_read == 3); (objectPoints+i)->x = x; (objectPoints+i)->y = y; @@ -443,7 +450,8 @@ void CV_CameraCalibrationTest::run( int start_from ) for( currPoint = 0; currPoint < numPoints; currPoint++ ) { double x,y; - fscanf(file,"%lf %lf\n",&x,&y); + values_read = fscanf(file,"%lf %lf\n",&x,&y); + CV_Assert(values_read == 2); (imagePoints+i)->x = x; (imagePoints+i)->y = y; @@ -455,32 +463,40 @@ void CV_CameraCalibrationTest::run( int start_from ) /* Focal lengths */ double goodFcx,goodFcy; - fscanf(file,"%lf %lf",&goodFcx,&goodFcy); + values_read = fscanf(file,"%lf %lf",&goodFcx,&goodFcy); + CV_Assert(values_read == 2); /* Principal points */ double goodCx,goodCy; - fscanf(file,"%lf %lf",&goodCx,&goodCy); + values_read = fscanf(file,"%lf %lf",&goodCx,&goodCy); + CV_Assert(values_read == 2); /* Read distortion */ - fscanf(file,"%lf",goodDistortion+0); - fscanf(file,"%lf",goodDistortion+1); - fscanf(file,"%lf",goodDistortion+2); - fscanf(file,"%lf",goodDistortion+3); + values_read = fscanf(file,"%lf",goodDistortion+0); CV_Assert(values_read == 1); + values_read = fscanf(file,"%lf",goodDistortion+1); CV_Assert(values_read == 1); + values_read = fscanf(file,"%lf",goodDistortion+2); CV_Assert(values_read == 1); + values_read = fscanf(file,"%lf",goodDistortion+3); CV_Assert(values_read == 1); /* Read good Rot matrixes */ for( currImage = 0; currImage < numImages; currImage++ ) { for( i = 0; i < 3; i++ ) for( j = 0; j < 3; j++ ) - fscanf(file, "%lf", goodRotMatrs + currImage * 9 + j * 3 + i); + { + values_read = fscanf(file, "%lf", goodRotMatrs + currImage * 9 + j * 3 + i); + CV_Assert(values_read == 1); + } } /* Read good Trans vectors */ for( currImage = 0; currImage < numImages; currImage++ ) { for( i = 0; i < 3; i++ ) - fscanf(file, "%lf", goodTransVects + currImage * 3 + i); + { + values_read = fscanf(file, "%lf", goodTransVects + currImage * 3 + i); + CV_Assert(values_read == 1); + } } calibFlags = 0 diff --git a/modules/features2d/test/test_mser.cpp b/modules/features2d/test/test_mser.cpp index 32a4be976e..89e51c1f59 100644 --- a/modules/features2d/test/test_mser.cpp +++ b/modules/features2d/test/test_mser.cpp @@ -75,7 +75,8 @@ int CV_MserTest::LoadBoxes(const char* path, vector& boxes) while (!feof(f)) { CvBox2D box; - fscanf(f,"%f,%f,%f,%f,%f\n",&box.angle,&box.center.x,&box.center.y,&box.size.width,&box.size.height); + int values_read = fscanf(f,"%f,%f,%f,%f,%f\n",&box.angle,&box.center.x,&box.center.y,&box.size.width,&box.size.height); + CV_Assert(values_read == 5); boxes.push_back(box); } fclose(f); diff --git a/modules/legacy/src/calibfilter.cpp b/modules/legacy/src/calibfilter.cpp index 78d29f0990..4d608bb358 100644 --- a/modules/legacy/src/calibfilter.cpp +++ b/modules/legacy/src/calibfilter.cpp @@ -734,7 +734,8 @@ bool CvCalibFilter::LoadCameraParams( const char* filename ) { for( j = 0; j < (int)(sizeof(cameraParams[i])/sizeof(float)); j++ ) { - fscanf( f, "%f", &((float*)(cameraParams + i))[j] ); + int values_read = fscanf( f, "%f", &((float*)(cameraParams + i))[j] ); + CV_Assert(values_read == 1); } } @@ -746,8 +747,10 @@ bool CvCalibFilter::LoadCameraParams( const char* filename ) { for( j = 0; j < 4; j++ ) { - fscanf(f, "%f ", &(stereo.quad[i][j].x) ); - fscanf(f, "%f ", &(stereo.quad[i][j].y) ); + int values_read = fscanf(f, "%f ", &(stereo.quad[i][j].x) ); + CV_Assert(values_read == 1); + values_read = fscanf(f, "%f ", &(stereo.quad[i][j].y) ); + CV_Assert(values_read == 1); } } @@ -756,7 +759,8 @@ bool CvCalibFilter::LoadCameraParams( const char* filename ) { for( j = 0; j < 9; j++ ) { - fscanf(f, "%lf ", &(stereo.coeffs[i][j/3][j%3]) ); + int values_read = fscanf(f, "%lf ", &(stereo.coeffs[i][j/3][j%3]) ); + CV_Assert(values_read == 1); } } diff --git a/samples/c/mushroom.cpp b/samples/c/mushroom.cpp index 223091291d..4211bcfea2 100644 --- a/samples/c/mushroom.cpp +++ b/samples/c/mushroom.cpp @@ -192,7 +192,9 @@ void print_variable_importance( CvDTree* dtree, const char** var_desc ) } printf( "Print variable importance information? (y/n) " ); - scanf( "%1s", input ); + int values_read = scanf( "%1s", input ); + CV_Assert(values_read == 1); + if( input[0] != 'y' && input[0] != 'Y' ) return; @@ -230,7 +232,9 @@ void interactive_classification( CvDTree* dtree, const char** var_desc ) const CvDTreeNode* node; printf( "Start/Proceed with interactive mushroom classification (y/n): " ); - scanf( "%1s", input ); + int values_read = scanf( "%1s", input ); + CV_Assert(values_read == 1); + if( input[0] != 'y' && input[0] != 'Y' ) break; printf( "Enter 1-letter answers, '?' for missing/unknown value...\n" ); @@ -252,7 +256,8 @@ void interactive_classification( CvDTree* dtree, const char** var_desc ) const int* map = data->cat_map->data.i + data->cat_ofs->data.i[vi]; printf( "%s: ", var_desc[vi] ); - scanf( "%1s", input ); + values_read = scanf( "%1s", input ); + CV_Assert(values_read == 1); if( input[0] == '?' ) { diff --git a/samples/cpp/detector_descriptor_matcher_evaluation.cpp b/samples/cpp/detector_descriptor_matcher_evaluation.cpp index e7e9de943d..6652cab9e7 100644 --- a/samples/cpp/detector_descriptor_matcher_evaluation.cpp +++ b/samples/cpp/detector_descriptor_matcher_evaluation.cpp @@ -273,7 +273,8 @@ int main(int argc, char** argv) if( dir[dir.size()-1] != '\\' && dir[dir.size()-1] != '/' ) dir += "/"; - system(("mkdir " + dir).c_str()); + int result = system(("mkdir " + dir).c_str()); + CV_Assert(result == 0); for( int i = 0; ddms[i*4] != 0; i++ ) { diff --git a/samples/cpp/hybridtrackingsample.cpp b/samples/cpp/hybridtrackingsample.cpp index 3096dc0fc5..72776101aa 100644 --- a/samples/cpp/hybridtrackingsample.cpp +++ b/samples/cpp/hybridtrackingsample.cpp @@ -82,7 +82,8 @@ int main(int argc, char** argv) sprintf(test_file, "%s", argv[1]); f = fopen(test_file, "r"); char vid[20]; - fscanf(f, "%s\n", vid); + int values_read = fscanf(f, "%s\n", vid); + CV_Assert(values_read == 1); cout << "Benchmarking against " << vid << endl; live = 0; } @@ -133,7 +134,8 @@ int main(int argc, char** argv) } else { - fscanf(f, "%d %f %f %f %f\n", &i, &w[0], &w[1], &w[2], &w[3]); + int values_read = fscanf(f, "%d %f %f %f %f\n", &i, &w[0], &w[1], &w[2], &w[3]); + CV_Assert(values_read == 5); sprintf(img_file, "seqG/%04d.png", i); image = imread(img_file, CV_LOAD_IMAGE_COLOR); if (image.empty()) diff --git a/samples/cpp/select3dobj.cpp b/samples/cpp/select3dobj.cpp index 94ade9b85a..987290d8c2 100644 --- a/samples/cpp/select3dobj.cpp +++ b/samples/cpp/select3dobj.cpp @@ -491,7 +491,8 @@ int main(int argc, char** argv) if( outbarename ) { cmd[6 + outbarename - outprefix] = '\0'; - system(cmd); + int result = system(cmd); + CV_Assert(result == 0); outbarename++; } else