Question

I am working with a legacy code ported from Visual C++ 6.0 to VC++ 9.0 (2008). I disabled the secure CRT warnings using _CRT_SECURE_NO_WARNINGS pre-processor definition. But that has lead to crashes in the std::vector destructor.

Any issues in using _CRT_SECURE_NO_WARNINGS?

Was it helpful?

Solution

How is it crashing? This sounds more like you've got memory in one location overwriting memory in your vector, then freeing it before your vector is freed. I'd look to any place with pointers. Since you're now on a standards compliant compiler replace them with boost shared pointers or boost arrays. Anything to remove the need for pointer arithmetic where an iterator would be safer to use.

OTHER TIPS

Those are unrelated problems. _CRT_SECURE_NO_WARNINGS only suppresses deprecation warnings, it doesn't change program behavior. You have to debug the actual problem.

You are definitely one of them who need quick and dirty solution just to "make it work" any how. Bad approach. Don't define the directive to hide the warnings, instead enable ALL warnings (level 4 - /W4) in your code and diligently remove all of them. Make your code more robust by removing all possible warnings and side effects caused by them.

There is a vast difference between VC6 and latest VC compilers - what has worked flawlessly in VC6 may not work now, and it is not latest compiler's fault but your code's fault. The compiler/debugger is helping to find the flaw early (at development/debugging stage).

I would also suggest you to run some static analysis (like Code Analysis in higher version of Visual Studio using /analyze switch, if you have). You should also run dynamic code analysis on your code to find any more issues.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top