I have some code for outputting a buffer as a HEX dump like this:
000000: 00000000 00000000 00000000 00000000 ................
000010: 00000000 00000000 00000000 00000000 ................
000020: 00000000 00000000 00000000 00000000 ................
I have used this code for years on AIX, HP-UX, IBM i (OS/400), Linux, Solaris, Windows and z/OS without issue. I have compiled it for both 32-bit and 64-bit on various platforms without issue.
I recently purchased a new PC and last week I install Microsoft’s Visual C# and Visual C++ 2010 Express followed by Microsoft’s Windows SDK for Windows 7 and .NET Framework 4.
Today, I wanted to do some Windows 64-bit testing, so I rebuild the application using VS C++ 2010 and started testing. Everything was running along fine then I decided to turn on logging in a MQ exit and bam, I get the following error:
I scratched my head and thought, I do not have any source code called ‘isctype.c’ and the code is not using a C function called ‘ isctype’. So, I did the same test with the 32-bit version of the program it was fine. After swearing for a while, I started adding debug statements through the code and finally narrow it down to the following:
for (i=0; i < lenSrc; i++) pTgt[j+i] = isprint(pSrc[i]) ? pSrc[i] : '.';[/sourcecode] After some more debugging, I noticed that it crashed when the high-order bit was set. i.e. pSrc[i] is 'AA'. The VS C++ runtime was treating pSrc[i] as a signed integer. pSrc is typed as 'char *', so technically is it a signed char but who in the world deals with signed chararcters. So, after some searching on the internet, I found many other people with similar issue. The simplest solution is to cast pSrc[i] to unsigned char. [sourcecode language="c"]for (i=0; i < lenSrc; i++) pTgt[j+i] = isprint((unsigned char)pSrc[i]) ? pSrc[i] : '.';[/sourcecode] I don't know what's up with Microsoft's runtime for VS C++ 2010 but I wasted 3 hours of my life that I will never get back. Regards, Roger Lacroix Capitalware Inc.