[Dcmlib] gdcm and NDEBUG

Tim Day timday at bottlenose.demon.co.uk
Wed Sep 10 00:51:41 CEST 2008


I'm on an up-to-date Debian Lenny system with g++ (Debian 4.3.1-9) 4.3.1
I installed gdcm from the 2.0.8 sources as per the INSTALL.txt, and
basically it all works very nicely, apart from one issue which is
illustrated by the following:

The code 
-----

#include <iostream>
#include <gdcm-2.0/gdcmReader.h>

void foo()
{
  std::cerr << "About to create " << sizeof(gdcm::Reader) 
    << " byte reader...\n";
  gdcm::Reader reader;
  std::cerr << "...created reader\n";
  std::cerr << "About to destroy reader...\n";
}

int main(int argc,char** argv)
{ 
  foo();
  return 0;
}
-----
in file dcm.cpp, say, works fine when compiled so:

g++ dcm.cpp -o dcm -lgdcmDSED -lgdcmMSFF -lgdcmCommon -lgdcmzlib
./gdcm
About to create 40 byte reader...
...created reader
About to destroy reader...

but if you add a -DNDEBUG, it crashes:

g++ -DNDEBUG dcm.cpp -o dcm \
  -lgdcmDSED -lgdcmMSFF -lgdcmCommon -lgdcmzlib
./dcm
About to create  32 byte reader...
...created reader
About to destroy reader...
Segmentation fault

On inspecting the DataStructureAndEncodingDefinition/gdcmReader.h header
it's clear this is due to the final member being wrapped with a
  #ifndef NDEBUG
    std::string DebugFileName;
  #endif
so any code compiled with -DNDEBUG has a different idea from the
libraries about how big a gdcmReader is and... *BOOM*.
A quick peruse of
  grep -A 2 NDEBUG `find . -name '*.h'`
shows gdcmWriter is similarly affected, but everything else should be
fine.

I'd urge you to fix this (probably by just always allocating the
std::string DebugFileName even if it's unused).  I don't want to be
recompiling and reinstalling GDCM every time I switch on and off asserts
in my own code, or keeping 2 GDCM builds around and somehow making sure
I link with the right one depending on a preprocessor macro.
I see the issue still exists in the svn head.

Thanks for taking the time to read all this.
Tim

PS I'm only on the regular dcmlib list, not the sourceforge developers
one.





More information about the Dcmlib mailing list