Ignore:
Timestamp:
May 8, 2010, 12:47:57 PM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Children:
0341a9
Parents:
25e17e9
Message:

FIX: Memory corruption in particleInfo class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/molecule.cpp

    r25e17e9 r1de701  
    135135      if (pointer->type->Z != 1)
    136136        NoNonHydrogen++;
    137       if (pointer->Name == NULL) {
    138         Free(&pointer->Name);
    139         pointer->Name = Malloc<char>(6, "molecule::AddAtom: *pointer->Name");
    140         sprintf(pointer->Name, "%2s%02d", pointer->type->symbol, pointer->nr+1);
     137      if(pointer->getName() == "Unknown"){
     138        stringstream sstr;
     139        sstr << pointer->type->symbol << pointer->nr+1;
     140        pointer->setName(sstr.str());
    141141      }
    142142    }
     
    157157  if (pointer != NULL) {
    158158    atom *walker = pointer->clone();
    159     walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name");
    160     strcpy (walker->Name, pointer->Name);
     159    stringstream sstr;
     160    sstr << pointer->getName();
     161    walker->setName(sstr.str());
    161162    walker->nr = last_atom++;  // increase number within molecule
    162163    add(walker, end);
     
    252253  BondRescale = TopOrigin->type->HBondDistance[TopBond->BondDegree-1];
    253254  if (BondRescale == -1) {
    254     DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl);
     255    DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->getName() << "<->" << TopReplacement->getName() << ") of degree " << TopBond->BondDegree << "!" << endl);
    255256    return false;
    256257    BondRescale = bondlength;
     
    295296            SecondOtherAtom = (*Runner)->GetOtherAtom(TopOrigin);
    296297          } else {
    297             DoeLog(2) && (eLog()<< Verbose(2) << "Detected more than four bonds for atom " << TopOrigin->Name);
     298            DoeLog(2) && (eLog()<< Verbose(2) << "Detected more than four bonds for atom " << TopOrigin->getName());
    298299          }
    299300        }
     
    339340      bondangle = TopOrigin->type->HBondAngle[1];
    340341      if (bondangle == -1) {
    341         DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl);
     342        DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->getName() << "<->" << TopReplacement->getName() << ") of degree " << TopBond->BondDegree << "!" << endl);
    342343        return false;
    343344        bondangle = 0;
     
    616617    add(Binder, last);
    617618  } else {
    618     DoeLog(1) && (eLog()<< Verbose(1) << "Could not add bond between " << atom1->Name << " and " << atom2->Name << " as one or both are not present in the molecule." << endl);
     619    DoeLog(1) && (eLog()<< Verbose(1) << "Could not add bond between " << atom1->getName() << " and " << atom2->getName() << " as one or both are not present in the molecule." << endl);
    619620  }
    620621  return Binder;
     
    695696    AtomCount--;
    696697  } else
    697     DoeLog(1) && (eLog()<< Verbose(1) << "Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl);
     698    DoeLog(1) && (eLog()<< Verbose(1) << "Atom " << pointer->getName() << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl);
    698699  if (ElementsInMolecule[pointer->type->Z] == 0)  // was last atom of this element?
    699700    ElementCount--;
     
    713714    ElementsInMolecule[pointer->type->Z]--; // decrease number of atom of this element
    714715  else
    715     DoeLog(1) && (eLog()<< Verbose(1) << "Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl);
     716    DoeLog(1) && (eLog()<< Verbose(1) << "Atom " << pointer->getName() << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl);
    716717  if (ElementsInMolecule[pointer->type->Z] == 0)  // was last atom of this element?
    717718    ElementCount--;
     
    915916        if (Walker->type->Z != 1) // count non-hydrogen atoms whilst at it
    916917          NoNonHydrogen++;
    917         Free(&Walker->Name);
    918         Walker->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name");
    919         sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1);
    920         DoLog(3) && (Log() << Verbose(3) << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl);
     918        stringstream sstr;
     919        sstr << Walker->type->symbol << Walker->nr+1;
     920        Walker->setName(sstr.str());
     921        DoLog(3) && (Log() << Verbose(3) << "Naming atom nr. " << Walker->nr << " " << Walker->getName() << "." << endl);
    921922        i++;
    922923      }
Note: See TracChangeset for help on using the changeset viewer.