Detecting out-of-bounds in dynamic array?
-
How do I enable out-of-bounds memory checking for dynamically allocated memory (new/delete) in VC++ 2003? /RTC options enable stack-based checks, which I've got turned on, but that doesn't cover heap-based allocations.
-
How do I enable out-of-bounds memory checking for dynamically allocated memory (new/delete) in VC++ 2003? /RTC options enable stack-based checks, which I've got turned on, but that doesn't cover heap-based allocations.
-
Simply you cannot (AFAIK). :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
Well, I was hoping for a configurable option. Overloading operator new and delete is my backup plan, which will work because I only use new/delete.
-
Well, I was hoping for a configurable option. Overloading operator new and delete is my backup plan, which will work because I only use new/delete.
-
Can you do that?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
Of course. Overloading new/delete is part of the C++ Standard. Just tack on some extra bytes (on either side) during allocation and check those bytes before deleting the memory. If a match fails, then something overwrote the memory. Poor-man's solution is to use TRACE() at that point. A stack dump would be nicer. Even better would be the compiler offering the option at compile-time to do all of that without writing any code.
-
Of course. Overloading new/delete is part of the C++ Standard. Just tack on some extra bytes (on either side) during allocation and check those bytes before deleting the memory. If a match fails, then something overwrote the memory. Poor-man's solution is to use TRACE() at that point. A stack dump would be nicer. Even better would be the compiler offering the option at compile-time to do all of that without writing any code.
-
How do I enable out-of-bounds memory checking for dynamically allocated memory (new/delete) in VC++ 2003? /RTC options enable stack-based checks, which I've got turned on, but that doesn't cover heap-based allocations.
The debug CRT does it for you (using sentry bytes I believe). Try this in a debug build: BYTE *pBytes = new BYTE[10]; pBytes[10] = 255; delete[] pBytes;
"If you can dodge a wrench, you can dodge a ball."