Problem 142 - G4ReactionDynamics:GenerateXandPt unprotected vs. vecLen==0
Summary: G4ReactionDynamics:GenerateXandPt unprotected vs. vecLen==0
Status: CLOSED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: processes/hadronic (show other problems)
Version: 2.0
Hardware: All All
: P2 critical
Assignee: Hans-Peter.Wellisch
URL:
Depends on:
Blocks:
 
Reported: 2000-07-29 21:41 CEST by dcasper
Modified: 2012-02-15 05:10 CET (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description dcasper 2000-07-29 21:41:11 CEST
The program crashes when G4ReactionDynamics::GenerateXandPt() is called with
vecLen == 0.  I don't understand the code well enough to know if vecLen=0 is an
invalid input, but most of the routine is protected against it.  However the
block:

      // DEBUGGING --> DumpFrames::DumpFrame(vec, vecLen);
      if( backwardParticlesLeft == 0)
      {
        backwardEnergy += targetParticle.GetMass()/GeV;
        targetParticle = *vec[0];
        --backwardCount;
        for( G4int j=0; j<(vecLen-1); ++j )*vec[j] = *vec[j+1];
        //G4ReactionProduct *temp = vec[vecLen];
        //delete temp;
        if( --vecLen == 0 )return false;  // all the secondaries have been
eliminated
        break;
      }

is not protected against vecLen == 0.  It crashes on the assignment of *vec[0]
to targetParticle.  If it did not crash here, it would get in more trouble when
it executed the --vecLen instruction and vecLen became negative, I think.

From a fairly naive analysis of the code, it looks to me like the routine
should return if vecLen==0 before the statement:

    while( forwardEnergy <= 0.0 )  // must eliminate a particle from the
forward side

Above this instruction there appear to be possibilities for vecLen to increase;
below it, particles can only be removed, and whenever --vecLen yields 0 after
this point the routine does in fact return.
Comment 1 Hans-Peter.Wellisch 2000-07-30 06:51:59 CEST
I'll have to leafe through it in more detail, but it seems to be indeed a
protection missing for the case where GenerateXandPt is called, while no
particle was created.

Thank you for spotting this one.
Comment 2 Hans-Peter.Wellisch 2000-11-26 05:17:59 CET
Fixed. To be released in the next reference tag.