From: jpr Date: Wed, 15 Oct 2003 15:01:15 +0000 (+0000) Subject: gdcmHeader::gdcmHeader(const char *InFilename, bool exception_on_error) X-Git-Tag: Version0.3.1~101 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=35d42d4166f9dae6312ec59765e08b48f9ef946f;p=gdcm.git gdcmHeader::gdcmHeader(const char *InFilename, bool exception_on_error) no longer seg faults when file is not found --- diff --git a/DEVELOPPER b/DEVELOPPER index 3465ece9..dfcfe033 100644 --- a/DEVELOPPER +++ b/DEVELOPPER @@ -30,7 +30,7 @@ The following comments are intended for core gdcm developpers. the final user by gdcmPython/__init__.py. - the second python wrappers uses the vtk (http://public.kitware.com/VTK/) native wrappers i.e. the binary vtkWrapPython. But it should be noticed - that the purpous is here a bit different than the one of the Swig + that the purpose is here a bit different than the one of the Swig generated Python wrappers. When using vtkWrapPython the goal is to wrap a single vtk class namely vtkGdcmReader as defined in files vtk/vtkGdcmReader.h and vtk/vtkGdcmReader.cxx (and of course those diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 6689c01f..7274df46 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -25,13 +25,15 @@ gdcmFile::gdcmFile(std::string & filename) :gdcmHeader(filename.c_str()) { - SetPixelDataSizeFromHeader(); + if (IsReadable()) + SetPixelDataSizeFromHeader(); } gdcmFile::gdcmFile(const char * filename) :gdcmHeader(filename) { - SetPixelDataSizeFromHeader(); + if (IsReadable()) + SetPixelDataSizeFromHeader(); } /** diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 43f6f549..13da756d 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -1,4 +1,4 @@ -// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.100 2003/10/14 11:53:16 jpr Exp $ +// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.101 2003/10/15 15:01:16 jpr Exp $ #include "gdcmHeader.h" @@ -44,7 +44,6 @@ gdcmHeader::gdcmHeader(const char *InFilename, bool exception_on_error) { Initialise(); if ( !OpenFile(exception_on_error)) return; - ParseHeader(); LoadElements(); CloseFile(); @@ -73,10 +72,11 @@ gdcmHeader::gdcmHeader(bool exception_on_error) { if(!fp) throw gdcmFileError("gdcmHeader::gdcmHeader(const char *, bool)"); } -// char *testEntete = new char[204]; - guint16 zero; - fread(&zero, (size_t)2, (size_t)1, fp); + if ( fp ) { + guint16 zero; + fread(&zero, (size_t)2, (size_t)1, fp); + //ACR -- or DICOM with no Preamble if( zero == 0x0008 || zero == 0x0800 || zero == 0x0002 || zero == 0x0200) return true; @@ -84,7 +84,7 @@ gdcmHeader::gdcmHeader(bool exception_on_error) { fseek(fp, 126L, SEEK_CUR); char dicm[4]; fread(dicm, (size_t)4, (size_t)1, fp); - if( strncmp(dicm, "DICM", 4) == 0 ) + if( memcmp(dicm, "DICM", 4) == 0 ) return true; fclose(fp); dbg.Verbose(0, "gdcmHeader::gdcmHeader not DICOM/ACR", filename.c_str());