coverity reports 15781 15550 15089 13953 13952 13951 13950 11215 10013 10012 10011
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 2 Feb 2011 14:56:53 +0000 (14:56 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 2 Feb 2011 14:56:53 +0000 (14:56 +0000)
cleanup of dynamic arrays in error branches and a few minor changes

HLT/TPCLib/comp/AliHLTTPCCompModelAnalysis.cxx
HLT/TPCLib/comp/AliHLTTPCCompModelAnalysis.h
HLT/TPCLib/comp/AliHLTTPCCompModelConverter.cxx
HLT/TPCLib/comp/AliHLTTPCCompModelDeflater.cxx

index f1b88e8..d04d847 100644 (file)
@@ -70,9 +70,10 @@ AliHLTTPCCompModelAnalysis::~AliHLTTPCCompModelAnalysis()
     for ( UInt_t slice=0; slice<36; slice++ )
        for ( UInt_t patch=0; patch<6; patch++ )
            {
-           if ( fDiscardedClusters[slice][patch]->fSpacePoints )
+           if ( fDiscardedClusters[slice][patch]!=NULL )
                {
                delete [] fDiscardedClusters[slice][patch];
+               fDiscardedClusters[slice][patch]=NULL;
                }
            }
     }
@@ -229,21 +230,23 @@ Int_t AliHLTTPCCompModelAnalysis::CompareTracks()
   if(firsttracks == 0)
     {
       HLTError("No tracks in first track array!");
-      return EINVAL;
+      return -EINVAL;
     };
  
 
   if(secondtracks == 0)
     {
       HLTError("No tracks in second track array!");
-      return EINVAL;
+      return -EINVAL;
     };
 
   // take track from first tracking,
   for(Int_t ii=0; ii < firsttracks; ii++)
     {
       // build track list for all tracks in first array
+      // FIXME: I can't find the cleanup of the linked list fFirstTrackList
       AliHLTTPCTrackList* currenttrackentry = new AliHLTTPCTrackList;
+      if (!currenttrackentry) return -ENOMEM;
       currenttrackentry->fTrack = *(fFirstTrackArray.GetCheckedTrack(ii));
 
       // get its pythia information, 
@@ -267,7 +270,9 @@ Int_t AliHLTTPCCompModelAnalysis::CompareTracks()
   for(Int_t ii=0; ii < secondtracks; ii++)
     {
       // build track list for all tracks in second array
+      // FIXME: I can't find the cleanup of the linked list fSecondTrackArray
       AliHLTTPCTrackList* currenttrackentry = new AliHLTTPCTrackList;
+      if (!currenttrackentry) return -ENOMEM;
       currenttrackentry->fTrack = *(fSecondTrackArray.GetCheckedTrack(ii));
 
       // get its pythia information, 
@@ -632,7 +637,7 @@ Int_t AliHLTTPCCompModelAnalysis::CompareClusters(Bool_t relativedifferences)
   return 0;
 }
 
-AliHLTTPCTrack AliHLTTPCCompModelAnalysis::GetComparableTrackPythiaInfo(AliHLTTPCTrack comparabletrack) const
+AliHLTTPCTrack AliHLTTPCCompModelAnalysis::GetComparableTrackPythiaInfo(const AliHLTTPCTrack& comparabletrack) const
 {
   // see headerfile for class documentation
 
@@ -680,7 +685,7 @@ Int_t AliHLTTPCCompModelAnalysis::MarkTrashCluster(AliHLTTPCClusterData *discard
   return 0;
 }
 
-Bool_t AliHLTTPCCompModelAnalysis::GetTrashTrackPythiaInfo(AliHLTTPCTrack* /*discardedtrack*/ ) const
+Bool_t AliHLTTPCCompModelAnalysis::GetTrashTrackPythiaInfo(const AliHLTTPCTrack* /*discardedtrack*/ ) const
 {
   // see header file for class documentation
   // store information from pythia in current track list entry
@@ -689,7 +694,7 @@ Bool_t AliHLTTPCCompModelAnalysis::GetTrashTrackPythiaInfo(AliHLTTPCTrack* /*dis
   return 0;
 }
 
-Bool_t AliHLTTPCCompModelAnalysis::GetClusterPythiaInfo(AliHLTTPCClusterData* /*discardedcluster*/) const
+Bool_t AliHLTTPCCompModelAnalysis::GetClusterPythiaInfo(const AliHLTTPCClusterData* /*discardedcluster*/) const
 {
   // see header file for class documentation
   // Pythia information can be
@@ -1263,8 +1268,6 @@ Int_t AliHLTTPCCompModelAnalysis::DisplayTrackResults()
       return EINVAL;
     }
 
-  return 0; // exit after cluster analysis has been done
   // start with comparison
   if(CompareTracks() != 0)
     {
index e894ec7..3fe4b77 100644 (file)
@@ -148,21 +148,21 @@ private:
    * @param comparabletrack track to look for pythia information
    * @return pythiatrack    track information from pythia lookup
    */
-  AliHLTTPCTrack GetComparableTrackPythiaInfo(AliHLTTPCTrack comparabletrack) const;
+  AliHLTTPCTrack GetComparableTrackPythiaInfo(const AliHLTTPCTrack& comparabletrack) const;
 
   /** compare discarded track parameters with parameters from Pythia event
    * @param discardedtrack  pointer to a discarded track (usually with low pt)
    * @return 0 upon correct decision (track with low pt accoridng to Pythia, i.e. track = delta-electron or similar noise)
    * @return 1 upon wrong decision (track wrongly discarded, should by taken into account according to Pythia information)
    */
-  Bool_t GetTrashTrackPythiaInfo(AliHLTTPCTrack* discardedtrack) const;
+  Bool_t GetTrashTrackPythiaInfo(const AliHLTTPCTrack* discardedtrack) const;
 
   /** compare information of a cluster not assigned to any track with its Pythia information
    * @param discardedcluster  pointer to discarded cluster
    * @return 0 upon correct decision (cluster not assigned to any track is true in Pythia, i.e. cluster = noise cluster)
    * @return 1 upon wrong decision (cluster wrongly discarded, i.e. it belongs to a valuable track according to Pythia)
    */
-  Bool_t GetClusterPythiaInfo(AliHLTTPCClusterData* discardedcluster) const;
+  Bool_t GetClusterPythiaInfo(const AliHLTTPCClusterData* discardedcluster) const;
 
   /** compare two tracks in order to find if the match
    * @param firsttracklistelement   track from orignal tracking, stored in AliHLTTPCTrackList
index 14c6f25..38cfe7a 100644 (file)
@@ -563,6 +563,7 @@ void AliHLTTPCCompModelConverter::SelectRemainingClusters()
 unsigned long AliHLTTPCCompModelConverter::GetRemainingClustersOutputDataSize()
     {
       // see header file for class documentation
+      int iResult=0;
 #if 0
     for ( UInt_t slice=0; slice<36; slice++ )
        for ( UInt_t patch=0; patch<6; patch++ )
@@ -584,9 +585,10 @@ unsigned long AliHLTTPCCompModelConverter::GetRemainingClustersOutputDataSize()
 
     dataWritten += sizeof(AliHLTUInt32_t);
 
-    for(Int_t slice=0; slice<35; slice++)
+    // FIXME: get rid of hardcoded numbers
+    for(Int_t slice=0; slice<35 && iResult>=0; slice++)
        {
-       for(Int_t patch=0; patch < 6; patch++)
+       for(Int_t patch=0; patch < 6 && iResult>=0; patch++)
            {
            if ( !fClusters[slice][patch] )
                {
@@ -631,13 +633,15 @@ unsigned long AliHLTTPCCompModelConverter::GetRemainingClustersOutputDataSize()
                        if(!tempPt)
                            {
                            HLTError( "Zero row pointer " );
-                           return EINVAL;
+                           iResult=-EINVAL;
+                           break;
                            }
                        if(localcounter != tempPt->fNClusters)
                            {
                            HLTError( "Mismatching clustercounter %lu - %d ", 
                                      (unsigned long)localcounter, (Int_t)tempPt->fNClusters );
-                           return EINVAL;
+                           iResult=EINVAL;
+                           break;
                            }
                        dataWritten += size;
                        }
@@ -645,7 +649,7 @@ unsigned long AliHLTTPCCompModelConverter::GetRemainingClustersOutputDataSize()
                        delete [] data;
                    size = sizeof(AliHLTTPCRemainingRow) + npoints[padrow]*sizeof(AliHLTTPCRemainingCluster);
                    data = new Byte_t[size];
-                   tempPt = (AliHLTTPCRemainingRow*)data;
+                   tempPt = reinterpret_cast<AliHLTTPCRemainingRow*>(data);
                    
                    localcounter=0;
                    tempPt->fPadRow = padrow;
@@ -656,7 +660,8 @@ unsigned long AliHLTTPCCompModelConverter::GetRemainingClustersOutputDataSize()
                    {
                    HLTError( "Cluster counter out of range: %lu - %lu",
                              (unsigned long)localcounter, (unsigned long)npoints[padrow] );
-                   return EINVAL;
+                   iResult=-EINVAL;
+                   break;
                    }
              
                localcounter++;
@@ -666,12 +671,14 @@ unsigned long AliHLTTPCCompModelConverter::GetRemainingClustersOutputDataSize()
            if ( tempPt )
                {
                dataWritten += size;
-               if(data)
-                   delete [] data;
                }
+           if(data)
+             delete [] data;
            }
        }
     delete [] npoints;
+    // FIXME check the caller and propagate an error condition
+    if (iResult<0) return 0;
     return dataWritten;
 #endif
     }
@@ -679,7 +686,10 @@ unsigned long AliHLTTPCCompModelConverter::GetRemainingClustersOutputDataSize()
 int AliHLTTPCCompModelConverter::GetRemainingClusters( AliHLTUInt8_t* const pTgt, unsigned long& dataSize )
     { 
       // see header file for class documentation
-      
+      int iResult=0;
+
+      // FIXME: almost identical code to  GetRemainingClustersOutputDataSize
+      // try to combine
       const Int_t nrows = AliHLTTPCTransform::GetNRows();
       Int_t * npoints = new Int_t[nrows];
       unsigned long dataWritten = 0;
@@ -689,9 +699,9 @@ int AliHLTTPCCompModelConverter::GetRemainingClusters( AliHLTUInt8_t* const pTgt
       dataWritten += sizeof(AliHLTUInt32_t);
       writePtr += sizeof(AliHLTUInt32_t);
 
-      for(Int_t slice=0; slice<=35; slice++)
+      for(Int_t slice=0; slice<=35 && iResult>=0; slice++)
        {
-         for(Int_t patch=0; patch < 6; patch++)
+         for(Int_t patch=0; patch < 6 && iResult>=0; patch++)
            {
              if ( !fClusters[slice][patch] )
                {
@@ -740,20 +750,23 @@ int AliHLTTPCCompModelConverter::GetRemainingClusters( AliHLTUInt8_t* const pTgt
                          if(!tempPt)
                            {
                              HLTError( "Zero row pointer " );
-                             return EINVAL;
+                             iResult=-EINVAL;
+                             break;
                            }
                          if(localcounter != tempPt->fNClusters)
                            {
                              HLTError( "Mismatching clustercounter %lu - %d ", 
                                        (unsigned long)localcounter, (Int_t)tempPt->fNClusters );
-                             return EINVAL;
+                             iResult=-EINVAL;
+                             break;
                            }
                          //cout<<"Writing row "<<(int)tempPt->fPadRow<<" with "<<(int)tempPt->fNClusters<<" clusters"<<endl;
                          //fwrite(tempPt,size,1,outfile);
                          if ( dataWritten+size > dataSize )
                            {
                              HLTWarning( "Cannot write remaining clusters to output. Data size too large (exceeding %lu bytes)", (unsigned long)dataSize );
-                             return ENOBUFS;
+                             iResult=-ENOBUFS;
+                             break;
                            }
                          memcpy( writePtr, tempPt, size );
                          dataWritten += size;
@@ -774,7 +787,8 @@ int AliHLTTPCCompModelConverter::GetRemainingClusters( AliHLTUInt8_t* const pTgt
                    {
                      HLTError( "Cluster counter out of range: %lu - %lu",
                                (unsigned long)localcounter, (unsigned long)npoints[padrow] );
-                     return EINVAL;
+                     iResult=EINVAL;
+                     break;
                    }
                  
                  Float_t xyz[3] = {points[j].fX,points[j].fY,points[j].fZ};
@@ -811,20 +825,21 @@ int AliHLTTPCCompModelConverter::GetRemainingClusters( AliHLTUInt8_t* const pTgt
              if ( dataWritten+size > dataSize )
                {
                HLTWarning( "Cannot write remaining clusters to output. Data size too large (exceeding %lu bytes)", (unsigned long)dataSize );
-               return ENOBUFS;
+               iResult=-ENOBUFS;
+               break;
                }
              if ( tempPt )
                {
                  memcpy( writePtr, tempPt, size );
                  dataWritten += size;
                  writePtr += size;
-                 if(data)
-                   delete [] data;
                }
+             if(data)
+               delete [] data;
            }
        }
       dataSize = dataWritten;
 
       delete [] npoints;
-      return 0;
+      return iResult;
     }
index d9d00d3..46e6252 100644 (file)
@@ -203,6 +203,7 @@ int AliHLTTPCCompModelDeflater::CompressTracks( AliHLTUInt8_t* inData, UInt_t co
       
       printf( "outuptSize: %lu\n", (unsigned long)outputSize );
       
+      // FIXME: check return value of OutputBit(s) to make code more robust
       InitBitDataOutput( output, outputSize );
       HLTDebug( "Output: Position: %lu / %u (0x%02X)", GetCurrentByteOutputPosition(), GetCurrentBitOutputPosition(), (unsigned)GetCurrentOutputByte() );
       OutputBits( 0, 4 ); // Version information
@@ -537,6 +538,7 @@ int AliHLTTPCCompModelDeflater::CompressRemainingClusters( AliHLTUInt8_t* inData
        }
       
       InitBitDataOutput( output, outputSize );
+      // FIXME: check return value of OutputBits to make code more robust
       OutputBits( 0, 4 ); // Version information
       //OutputBit( fWriteShape ); // Data format flag
       Pad8Bits();