Warning when compiling with VS 2012 x64 when using SetValues function for...
Cross-platform DICOM implementation
Brought to you by:
malat
When attempting to use the following code to set the imageType tag, Visual Studio throws a compiler warning that the use of std::copy is potentially unsafe due to standard arrays being passed to std::copy instead of iterators.
gdcm::Attribute<0x0008, 0x0008> ImageType; static const gdcm::CSComp imageTypeValues[] = { "ORIGINAL", "PRIMARY", "AXIAL" }; ImageType.SetValues(imageTypeValues, 3, true);
The warning thrown is as follows:
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xutility(2132): error C2220: warning treated as error - no 'object' file generated 1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xutility(2132): warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' 1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xutility(2113) : see declaration of 'std::_Copy_impl' 1> D:\.......\Include\gdcm\gdcmAttribute.h(638) : see reference to function template instantiation '_OutIt std::copy<const double*,double*>(_InIt,_InIt,_OutIt)' being compiled 1> with 1> [ 1> _OutIt=double * 1> , _InIt=const double * 1> ] 1> D:\.....\Include\gdcm\gdcmAttribute.h(622) : while compiling class template member function 'void gdcm::Attribute<40,4176,32,218367>::SetValues(const double *,unsigned int,bool)' 1> XXXXX.cpp(194) : see reference to function template instantiation 'void gdcm::Attribute<40,4176,32,218367>::SetValues(const double *,unsigned int,bool)' being compiled 1> XXXXX.cpp(192) : see reference to class template instantiation 'gdcm::Attribute<40,4176,32,218367>' being compiled 1> XXXXX.cpp(96) : see reference to function template instantiation 'bool XXXXX::XXXXX<float>(XXXXX *,std::string,T *,unsigned int,unsigned int,unsigned int,unsigned long &,bool,bool)' being compiled 1> with 1> [ 1> T=float 1> ] 1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xutility(2113) : see declaration of 'std::_Copy_impl' 1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xutility(2113) : see declaration of 'std::_Copy_impl'
The solution, as far as my testing has been able to determine, is to wrap the Internal pointer in a stdext::checked_array_iterator. This is in gdcmAttribute.h on line 637 of 2.4.3
std::copy(array, array+numel, Internal);
Becomes
std::copy(array, array+numel, stdext::checked_array_iterator<ArrayType *>(Internal, numel));
stdext is a microsoft extension AFAIK (definitely not portable C++98).
The bug is definitely on the app side and not on the lib side, simply follow the recommendations and use: -D_SCL_SECURE_NO_WARNINGS