QFT - the OP's examples are all about memory corruption, not memory leaks at all
That's not a memory leak. That's a buffer overrun. You can avoid it by not using magic numbers:rhuala, on 12 Feb 2013 - 18:49, said:
int i, a[10]; for(i=0;i<15;i++) a[i]=i;
const size_t ARRAY_LENGTH = 10; //or whatever int ary[ARRAY_LENGTH]; for(int i=0; i < ARRAY_LENGTH; ++i) { ary[i] = i; }
Another technique that you can use for arrays (but not arrays that have been cast/decayed into pointers) is:template <typename T, int N> uint ArraySize(T(&)[N]) { return N; } ... for(int i=0; i < ArraySize(ary); ++i) { ary[i] = i; }
okay my bad, I apologize... whatever it's called it leads to crashes or flaky behavior, I guess my technique sucks... although I never do allocate an array with a number, it's always a #define or const