addressing coverity warnings: now checking return value of fscanf
authordsilverm <dsilverm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 12 Nov 2011 11:42:08 +0000 (11:42 +0000)
committerdsilverm <dsilverm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 12 Nov 2011 11:42:08 +0000 (11:42 +0000)
EMCAL/AliCaloRawAnalyzerPeakFinder.cxx

index 8d62701..24f7df1 100644 (file)
@@ -287,6 +287,9 @@ AliCaloRawAnalyzerPeakFinder::LoadVectorsASCII()
       
       FILE *fp  =  fopen(filename, "r");
       FILE *fpc =  fopen(filenameCoarse, "r");
+
+      int status = 0;
+      int statusc = 0;
       
       if( fp == 0 )
            {
@@ -299,17 +302,23 @@ AliCaloRawAnalyzerPeakFinder::LoadVectorsASCII()
       else
            {
              for(int m = 0; m < n ; m++ )
-        {
-          fscanf(fp,  "%lf\t", &fPFAmpVectors[i][j][m] );
-          fscanf(fpc, "%lf\t", &fPFAmpVectorsCoarse[i][j][m] );
-        }
-             fscanf(fp,   "\n" );
-             fscanf(fpc,  "\n" );
+               {
+                 status = fscanf(fp,  "%lf\t", &fPFAmpVectors[i][j][m] );
+                 statusc = fscanf(fpc, "%lf\t", &fPFAmpVectorsCoarse[i][j][m] );
+                 if (!status) { AliFatal( Form( "could not read file: %s", filename ) ); }
+                 if (!statusc) { AliFatal( Form( "could not read file: %s", filenameCoarse ) ); }
+               }
+             status = fscanf(fp,   "\n" );
+             statusc = fscanf(fpc,  "\n" );
+             if (status < 0) { AliFatal( Form( "could not read file: %s", filename ) ); }
+             if (statusc < 0) { AliFatal( Form( "could not read file: %s", filenameCoarse ) ); }
              for(int m = 0; m < n ; m++ )
-        {
-          fscanf(fp, "%lf\t",   &fPFTofVectors[i][j][m]  );
-          fscanf(fpc, "%lf\t",  &fPFTofVectorsCoarse[i][j][m]  );  
-        }
+               {
+                 status = fscanf(fp, "%lf\t",   &fPFTofVectors[i][j][m]  );
+                 statusc = fscanf(fpc, "%lf\t",  &fPFTofVectorsCoarse[i][j][m]  );  
+                 if (!status) { AliFatal( Form( "could not read file: %s", filename ) ); }
+                 if (!statusc) { AliFatal( Form( "could not read file: %s", filenameCoarse ) ); }
+               }
              
              fPeakFinderVectors->SetVector( i, j, fPFAmpVectors[i][j], fPFTofVectors[i][j],    
                                       fPFAmpVectorsCoarse[i][j], fPFTofVectorsCoarse[i][j] );