Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

WideFormat problem


#1

I’ updated SmartInspect and i found some problem with widestrings. Is seems a problem with %p (for pointer) specifier that is not handled well from the WideFormat Routine.

TSession.SiLogDebug (and i think all other) does non work properly with format containing ‘%p’

I suggest you to investigate in all case WideFormat is involved.

Regards
Ing Giuseppe Monteleone


#2

Hello Giuseppe,

Thanks for reporting the problem. This is indeed a problem with the WideFormat function of the Delphi VCL. I’m not sure why this happens, but I will report the problem to Borland/CodeGear if it’s not already known. We will try to add a workaround for this in our SiFormat wrapper function for WideFormat in a future version.

In the meantime, you have basically two options to workaround this. You could replace the “%p” with the similar expression “%.8x”. But this also requires casting the pointer argument to an Integer or Cardinal variable. The other option would be to format the string yourself with the traditional Format function and then use the normal LogDebug method instead of the overloaded variant with the format string.

The options would thus look like:

Original: SiMain.LogDebug('%p', [SomePointer]); Option 1: SiMain.LogDebug('%.8x', [Cardinal(SomePointer)]); Option 2: SiMain.LogDebug(Format('%p', [SomePointer]));

We try to get this fixed. Sorry for the inconveniences.


#3

Hello again,

I’ve just looked at the source code of the WideFormat function and found the root of the problem. I will submit my bug fix to Borland/CodeGear and will try to get it integrated into the upcoming Delphi 2007 release.