X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=src%2FgdcmDocument.cxx;h=821b7027da0546aae3dbf59c3cd3228320ed2b99;hb=a0091d68a2eaa1a0c128f962030bb6c45cc0c366;hp=e406a1c480f5076ed2274d0f3e868cd3a455e89c;hpb=eae9a01c2edd9f615a78dc64a8e7731d09e815a1;p=gdcm.git diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index e406a1c4..821b7027 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2004/11/12 21:33:46 $ - Version: $Revision: 1.122 $ + Date: $Date: 2004/11/16 02:54:35 $ + Version: $Revision: 1.124 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -1044,13 +1044,13 @@ void* Document::GetEntryBinAreaByNumber(uint16_t group, uint16_t elem) * @param group group number of the Entry * @param elem element number of the Entry */ -void* Document::LoadEntryBinArea(uint16_t group, uint16_t elem) +void Document::LoadEntryBinArea(uint16_t group, uint16_t elem) { + // Search the corresponding DocEntry DocEntry *docElement = GetDocEntryByNumber(group, elem); if ( !docElement ) - { - return NULL; - } + return; + size_t o =(size_t)docElement->GetOffset(); Fp->seekg( o, std::ios_base::beg); size_t l = docElement->GetLength(); @@ -1058,27 +1058,30 @@ void* Document::LoadEntryBinArea(uint16_t group, uint16_t elem) if(!a) { dbg.Verbose(0, "Document::LoadEntryBinArea cannot allocate a"); - return NULL; + return; } + + // Read the value Fp->read((char*)a, l); if( Fp->fail() || Fp->eof() )//Fp->gcount() == 1 { delete[] a; - return NULL; + return; } - /// \todo Drop any already existing void area! JPR + + // Set the value to the DocEntry if( !SetEntryBinAreaByNumber( a, group, elem ) ) { + delete[] a; dbg.Verbose(0, "Document::LoadEntryBinArea setting failed."); } - return a; } /** * \brief Loads (from disk) the element content * when a string is not suitable * @param element Entry whose binArea is going to be loaded */ -void* Document::LoadEntryBinArea(BinEntry* element) +void Document::LoadEntryBinArea(BinEntry* element) { size_t o =(size_t)element->GetOffset(); Fp->seekg(o, std::ios_base::beg); @@ -1087,18 +1090,18 @@ void* Document::LoadEntryBinArea(BinEntry* element) if( !a ) { dbg.Verbose(0, "Document::LoadEntryBinArea cannot allocate a"); - return NULL; + return; } - element->SetBinArea((uint8_t*)a); + /// \todo check the result Fp->read((char*)a, l); if( Fp->fail() || Fp->eof()) //Fp->gcount() == 1 { delete[] a; - return NULL; + return; } - return a; + element->SetBinArea((uint8_t*)a); } /** @@ -1116,12 +1119,14 @@ bool Document::SetEntryBinAreaByNumber(uint8_t* area, { return false; } + if ( BinEntry* binEntry = dynamic_cast(currentEntry) ) { binEntry->SetBinArea( area ); return true; } - return true; + + return false; } /** @@ -1341,7 +1346,7 @@ void Document::ParseDES(DocEntrySet *set, long offset, { /////////////////////// ValEntry ValEntry* newValEntry = - new ValEntry( newDocEntry->GetDictEntry() ); + new ValEntry( newDocEntry->GetDictEntry() ); //LEAK newValEntry->Copy( newDocEntry ); // When "set" is a Document, then we are at the top of the @@ -1360,7 +1365,11 @@ void Document::ParseDES(DocEntrySet *set, long offset, + newValEntry->GetKey() ); } - set->AddEntry( newValEntry ); + if( !set->AddEntry( newValEntry ) ) + { + // If here expect big troubles + delete newValEntry; //otherwise mem leak + } LoadDocEntry( newValEntry ); if (newValEntry->IsItemDelimitor()) { @@ -1401,7 +1410,11 @@ void Document::ParseDES(DocEntrySet *set, long offset, + newBinEntry->GetKey() ); } - set->AddEntry( newBinEntry ); + if( !set->AddEntry( newBinEntry ) ) + { + //Expect big troubles if here + delete newBinEntry; + } LoadDocEntry( newBinEntry ); } @@ -1591,7 +1604,7 @@ void Document::LoadDocEntry(DocEntry* entry) s << " x(" << std::hex << entry->GetLength() << ")"; binEntryPtr->SetValue(s.str()); } - // Be carefull : a BinEntry IS_A ValEntry ... + // Be carefull : a BinEntry IS_A ValEntry ... else if (ValEntry* valEntryPtr = dynamic_cast< ValEntry* >(entry) ) { // s << "gdcm::NotLoaded. (ValEntry)";