]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Coverity fix: substituted sscanf by a parser
authorshahoian <ruben.shahoyan@cern.ch>
Mon, 31 Mar 2014 09:54:54 +0000 (11:54 +0200)
committershahoian <ruben.shahoyan@cern.ch>
Mon, 31 Mar 2014 09:54:54 +0000 (11:54 +0200)
ITS/UPGRADE/AliITSUGeomTGeo.cxx
ITS/UPGRADE/AliITSUGeomTGeo.h

index 56809b7e2a8b24630fc6fc99c796afd1ada9089f..2fada33fe6098262b5a580d520c10d91281d7f54 100644 (file)
@@ -751,23 +751,28 @@ Int_t AliITSUGeomTGeo::ExtractNumberOfLayers()
     const char* name = nd->GetName();
     if (strstr(name,GetITSLayerPattern())) {
       numberOfLayers++;
-      if (sscanf(name, Form("%s%%2d",AliITSUGeomTGeo::GetITSLayerPattern()),&lrID)!=1)
+      if ( (lrID=ExtractVolumeCopy(name,AliITSUGeomTGeo::GetITSLayerPattern()))<0 ) {
        AliFatal(Form("Failed to extract layer ID from the %s",name));
+       exit(1);
+      }
       //
       fLr2Wrapper[lrID] = -1; // not wrapped
     }
     else if (strstr(name,GetITSWrapVolPattern())) { // this is a wrapper volume, may cointain layers
       int wrID = -1;
-      if (sscanf(name, Form("%s%%2d",AliITSUGeomTGeo::GetITSWrapVolPattern()),&wrID)!=1) 
+      if ( (wrID=ExtractVolumeCopy(name,AliITSUGeomTGeo::GetITSWrapVolPattern()))<0 ) {
        AliFatal(Form("Failed to extract wrapper ID from the %s",name));
+       exit(1);
+      }
       //
       TObjArray* nodesW = nd->GetNodes();
       int nNodesW = nodesW->GetEntriesFast();
       for (Int_t jw=0; jw<nNodesW; jw++) {
        TGeoNode* ndW = (TGeoNode*)nodesW->At(jw);
        if (strstr(ndW->GetName(),GetITSLayerPattern())) {
-         if (sscanf(ndW->GetName(), Form("%s%%2d",AliITSUGeomTGeo::GetITSLayerPattern()),&lrID)!=1) {
-           AliFatal(Form("Failed to extract layer ID from the %s",ndW->GetName()));
+         if ( (lrID=ExtractVolumeCopy(ndW->GetName(),AliITSUGeomTGeo::GetITSLayerPattern()))<0 ) {
+           AliFatal(Form("Failed to extract layer ID from the %s",name));
+           exit(1);
          }
          numberOfLayers++;
          fLr2Wrapper[lrID] = wrID;
@@ -1042,3 +1047,14 @@ void AliITSUGeomTGeo::CreateT2LMatrices()
   //
 }
 
+//______________________________________________________________________
+Int_t AliITSUGeomTGeo::ExtractVolumeCopy(const char* name, const char* prefix) const
+{
+  // extract Number following the prefix in the name string
+  TString nms = name;
+  if (!nms.BeginsWith(prefix)) return -1;
+  nms.Remove(0,strlen(prefix));
+  if (!isdigit(nms.Data()[0])) return -1;
+  return nms.Atoi();
+  //
+}
index 8083a4d94cc612315650ea990d4b892d69fbb31e..c5edc6842bcd882676aa28bb38fbb1528428225b 100644 (file)
@@ -177,6 +177,7 @@ class AliITSUGeomTGeo : public TObject {
   Int_t        ExtractNumberOfLayers();
   void         BuildITS(Bool_t loadSegm);
   //
+  Int_t        ExtractVolumeCopy(const char* name, const char* prefix) const;
  protected:
   //
   //