MSVC++ 2005 Image::read() string problem

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Bob-O-Rama
Posts: 31
Joined: 2007-11-23T15:34:51-07:00

MSVC++ 2005 Image::read() string problem

Post by Bob-O-Rama »

Hi,

I have an issue where the VC++ 2005 ( or with SP1 ) Release build throws a null pointer exception in memcpy() right after calling Image::read(), apparently while initializing the file name.

On tracing this down, it appears there is some calling issue between the VC++ code and the Magick++ libraries, but only for the Release build. The code is as follows:

Code: Select all

CString theFile;
:
theFile = "C:\\JPG\\TEST.JPG";
:
Image my_image; // create an *empty* image using the default Image constructor
my_image.read( (LPCSTR) theFile ); // read a GIF image file from disk
Under the Debug build all is well and you can trace the pointer to "C:\\JPG\\TEST.JPG" as its passed and converted and eventually passed into read() and it all works. However for the release version, this falls apart in such a way that read is passed a NULL, which works its way down a bit and results in a memcpy error. The disassembly of the call, despite having the necessary debug related checking, looks pretty similar. Here is the working, debug, version:

Code: Select all

		Image my_image; // create an *empty* image using the default Image constructor
0041BB30  mov         esi,esp 
0041BB32  lea         ecx,[my_image] 
0041BB38  call        dword ptr [__imp_Magick::Image::Image (445C28h)] 
0041BB3E  cmp         esi,esp 
0041BB40  call        @ILT+3440(__RTC_CheckEsp) (412D75h) 
0041BB45  mov         byte ptr [ebp-4],0Dh 
		my_image.read( (LPCSTR) theFile ); // read a GIF image file from disk;
0041BB49  mov         esi,esp 
0041BB4B  lea         ecx,[ebp-80h] 
0041BB4E  call        dword ptr [__imp_ATL::CSimpleStringT<char,1>::operator char const * (445F88h)] 
0041BB54  cmp         esi,esp 
0041BB56  call        @ILT+3440(__RTC_CheckEsp) (412D75h) 
0041BB5B  mov         esi,esp 
0041BB5D  push        eax  
0041BB5E  lea         ecx,[ebp-1B0h] 
0041BB64  call        dword ptr [__imp_std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> > (446304h)] 
0041BB6A  cmp         esi,esp 
0041BB6C  call        @ILT+3440(__RTC_CheckEsp) (412D75h) 
0041BB71  mov         byte ptr [ebp-4],0Eh 
0041BB75  mov         esi,esp 
0041BB77  lea         eax,[ebp-1B0h] 
0041BB7D  push        eax  
0041BB7E  lea         ecx,[my_image] 
0041BB84  call        dword ptr [__imp_Magick::Image::read (445C2Ch)] 
0041BB8A  cmp         esi,esp 
0041BB8C  call        @ILT+3440(__RTC_CheckEsp) (412D75h) 
0041BB91  mov         byte ptr [ebp-4],0Dh 
0041BB95  mov         esi,esp 
0041BB97  lea         ecx,[ebp-1B0h] 
0041BB9D  call        dword ptr [__imp_std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> > (446308h)] 
0041BBA3  cmp         esi,esp 
0041BBA5  call        @ILT+3440(__RTC_CheckEsp) (412D75h) 


And here is the broken release version code:

Code: Select all

 		Image my_image; // create an *empty* image using the default Image constructor
00403514  lea         ecx,[my_image] 
00403517  call        dword ptr [__imp_Magick::Image::Image (40E010h)] 
0040351D  mov         byte ptr [ebp-4],0Dh 



		my_image.read( (LPCSTR) theFile ); // read a GIF image file from disk;

00403521  lea         ecx,[ebp-48h] 
00403524  call        dword ptr [__imp_ATL::CSimpleStringT<char,1>::operator char const * (40E274h)] 



0040352A  push        eax  
0040352B  lea         ecx,[ebp-88h] 
00403531  call        dword ptr [__imp_std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> > (40E468h)] 


00403537  mov         byte ptr [ebp-4],0Eh 

0040353B  lea         ecx,[ebp-88h] 
00403541  push        ecx  
00403542  lea         ecx,[my_image] 
00403545  call        dword ptr [__imp_Magick::Image::read (40E00Ch)] 


0040354B  mov         byte ptr [ebp-4],0Dh 
0040354F  lea         ecx,[ebp-88h] 

00403555  call        dword ptr [__imp_std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> > (40E46Ch)] 
Perhaps I've been looking at this too long, but I just cannot resolve this. I've disable optimization, and ensured that every setting between the two builds not directly relating to debug, are the same. This is the same story with the 6.3.6-10 binary distribution, and freshly built from source 6.3.7-9 libraries. Has anyone else seen this?

Many thanks in advance!

-- Bob
Bob-O-Rama
Posts: 31
Joined: 2007-11-23T15:34:51-07:00

Re: MSVC++ 2005 Image::read() string problem

Post by Bob-O-Rama »

OK, so reducing it to its simplest, in VC2005 I am unable to get:

Image myImage;
myImage.read( "C:\\SOME.JPG" );
myImage.read( _T("C:\\SOME.JPG") );
// etc... or any other way to construct strings

to work from a Release build. From a Debug build it works fine. If I create a str::simple_string and pass that in, I sill gat the same error. The proper data is being passed into read(), but it blows up trying to copy the string to its internal variables.

-- Bob
Post Reply