Now blogging at diego's weblog. See you over there!

purify rocks


A short detour from my usual Java-oriented commentary...

As I'm finishing the implementation of my thesis work, I've been testing the system a bit more. It's written in C++/Win32 and runs both in Windows and PocketPC. Yesterday, a horrific bug appeared as I was stress-testing some new functionality. The program was crashing with a mysterious message that said that I was trying to "relocate" KERNEL32.DLL. WTF? I thought. I dug in. Hours of debugging and I was getting nowhere. I knew that somewhere there was a memory overflow, but couldn't figure out where. I'd been working on it for 10 hours straight. It was 4 am. Being tired was certainly a factor. Then I remembered Purify.

I had used Purify at my last job when checking for leaks on an ActiveX IE Control. Back then, it had been a huge timesaver. So I downloaded the evaluation version (2 hours through my puny modem connection) and went to sleep.

I woke up about 5 hours later, feeling like crap but slightly refreshed. I installed purify. After some minimal fiddling with VS.NET's settings, I recompiled and Purify immediately flagged the problem. Bingo!

The problem was an assignment overflow on a statically allocated array, when copying character data with strcpy. Now, my question is, why is it so hard for VC++ to add a check that you are not writing beyond the allocated size, at least in debugging mode? I'm not talking about anything sophisticated here. strcpy, since it's copying strings, knows perfectly well the length of data to be copied. Why not add a check? I can't find any practical reason for not doing it.

In any case, the bug was fixed, the code now works, Purify once again to the rescue. If it didn't cost a fortune I would buy it to run it permanently on my C++ code.

Categories: technology
Posted by diego on February 22 2003 at 4:02 PM

Copyright © Diego Doval 2002-2011.
Powered by
Movable Type 4.37