Back to success stories

Sample of Defect

Project Name CID Checker Category Developer Description
CombLayer 1298974 DEADCODE Control flow issues Typical "easy to spot if you know there is a problem error". The code processes a physics modification option line given either from the command line or file. The format allows extra lines with multiple options -- unfortunately the later options are just ignored. This is very difficult to see in simulation output because the trailing lines are typically a list of cells to apply the physics option to. The simulation output will say stuff like: reading the correct physics, applying etc, because the first few options are correctly applied -- just not applied to all the cells it should have been. I really don't want to think about how much CPU time this might have wasted.....
File: /System/physics/PhysicsCards.cxx
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
    Clears the cell list from the hist tape file
   */
{
  histpCells.clear();
  return;
}

int 
PhysicsCards::processCard(const std::string& Line)
  /*!
    Attempt to process a card.
    If comment, store in 'Comments' and insert '0' into 'Cards'
    If card, insert "" into Comments and store in Cards.
    \param Line :: string to process
    \retval :: -ve on fail
    \retval 1 on successful addition of a card
    \retval 0 on null line/comment line
    \todo Trim leading space
  */
{
  ELog::RegMethod RegA("PhysicsCards","processCard");
  if(Line.empty())
    return 0;  
 << Assigning: "expCell" = "0".
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
  int expCell(0);
  std::string Comd=Line;
  StrFunc::stripComment(Comd);
  Comd=StrFunc::fullBlock(Comd);

  // Check the first 2 characters for comment
  if(Comd.size()<2 || (isspace(Comd[1]) &&
                       ( tolower(Comd[0])=='c' || Comd[0]=='!'))) 
    return 0;
  
  std::string::size_type pos=Comd.find("mode ");
  if (pos!=std::string::npos)
    {
      std::string item;
      Comd.erase(0,pos+5);
      while(StrFunc::section(Comd,item))
        mode.addElm(item);
      return 1;
    }
  pos=Comd.find("print ");
  if (pos!=std::string::npos)
    {
      printNum.clear();
      std::string Item=Comd.substr(pos+1);
      int pNum;
      while(StrFunc::section(Item,pNum))
        printNum.push_back(pNum);
    }

  
  pos=Comd.find("imp:");
  if (pos!=std::string::npos)
    {
      Comd.erase(0,pos+4);
      ImpCards.push_back(PhysImp("imp"));
      // Ugly hack to get all the a,b,c,d items 
      // since I can't think of the regular expression
      unsigned int index;
      for(index=0;index<Comd.length() && !isspace(Comd[index]);index++)
        if (Comd[index]!=',')
          ImpCards.back().addElm(std::string(1,Comd[index]));
      return 1;
    }

  pos=Comd.find("vol");
  if (pos!=std::string::npos)
    {
      Comd.erase(0,pos+3);
      Volume=PhysImp("vol");
      return 1;
    }

  pos=Comd.find("histp");
  if (pos!=std::string::npos)
    {
      histp=1;
      return 1;
    }

  // This is ignored since we have a prdmp card
  pos=Comd.find("prdmp");    
  if (pos!=std::string::npos)
    {
      return 1;
    }

  pos=Comd.find("nps");
  if (pos!=std::string::npos)
    {
      Comd.erase(0,pos+3);
      if (!StrFunc::convert(Comd,nps))
        nps=800000;
      return 1;
    }

  pos=Comd.find("dbcn");
  if (pos!=std::string::npos)
    {
      long int RS;
      size_t kType;
      double D;
      std::string keyName;
      Comd.erase(0,pos+4);
      if (StrFunc::convert(Comd,RS))
        dbCard->setComp("rndSeed",RS);
      else if (StrFunc::section(Comd,keyName) &&
               (kType=dbCard->keyType(keyName)) )
        {
          if (kType==1 && StrFunc::section(Comd,RS))
            dbCard->setComp(keyName,RS);
          else if (StrFunc::section(Comd,D))
            dbCard->setComp(keyName,RS);
          else
            ELog::EM<<"DBCN ["<<keyName<<"] error  == "
                    <<Comd<<ELog::endErr;
        }
      else
        {
          ELog::EM<<"DBCN [rnd] error  == "<<Comd<<ELog::endErr;
        }
      return 1;
    }

  pos=Comd.find("cut:");
  if (pos!=std::string::npos)
    {
      Comd.erase(0,pos+4);
      PhysCards.push_back(PhysCard("cut"));
      std::string Item;
      if (StrFunc::section(Comd,Item))
        {
          std::vector<std::string> part;
          boost::split(part,Item,boost::is_any_of(","));
          for(std::string& PStr : part)
            boost::trim(PStr,std::locale());
          // ensure no empty particles
          part.erase(
                     remove_if(part.begin(),part.end(),
                               std::bind<bool>(&std::string::empty,
                                               std::placeholders::_1)),
                     part.end());
          
          PhysCard& PC(PhysCards.back());
          for(const std::string& PStr : part)
            PC.addElm(PStr);
          // Strip and process numbers / j
          for(size_t i=0;i<5 && !Comd.empty();i++)
            {
              double d;
              if (StrFunc::section(Comd,d))
                PC.setValue(i,d);
              else if (StrFunc::section(Comd,Item))
                {
                  if (Item.size()==1 && tolower(Item[0]=='j'))
                    PC.setDef(i);
                }
            }
        }
      return 1;
    }
  // ext card
  pos=Comd.find("exp:");
  if (pos!=std::string::npos)
    {
      Comd.erase(0,pos+4);
      // Ugly hack to get all the a,b,c,d items 
      // since I can't think of the regular expression
      size_t index;
      for(index=0;index<Comd.length() && !isspace(Comd[index]);index++)
        if (Comd[index]!=',')
          ExtCard->addElm(std::string(1,Comd[index]));
      // NOW HAVE PROBLEM BECAUSE MULTI-LINE
      expCell=1;
      if (ExtCard->addUnitList(expCell,Comd))
        return 1;
      // drops through to further processing
 << Assigning: "expCell" = "0".
340
341
      expCell=0;
    }
 << The condition "expCell" cannot be true.
343
344
  if (expCell)
    {
 <<< CID 1298974: Control flow issues DEADCODE
 <<< Execution cannot reach this statement: "if (this->ExtCard->addUnitL...".
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
      if (ExtCard->addUnitList(expCell,Comd))
        return 1;
      expCell=0;
    }
        
  // Component:
  Basic.push_back(Line);
  return 1;
}

void
PhysicsCards::setEnergyCut(const double E) 
  /*!
    Sets the minimium energy cut
    \param E :: Energy [MeV]
  */
{
  ELog::RegMethod RegA("PhysicsCards","setEnergyCut");

  for(PhysCard& PC : PhysCards)
    PC.setEnergyCut(E);

  sdefCard.cutEnergy(E);
  return;
}

PhysImp&
Events:
assignment PhysicsCards.cxx:184
assignment PhysicsCards.cxx:340
const PhysicsCards.cxx:343
dead_error_condition PhysicsCards.cxx:343
dead_error_line PhysicsCards.cxx:345