   Help! DAMAGE: after normal block (#171) =(
  I don't know what happened, but I'm getting this "DAMAGE: after normal block (#171)" error in my code now... and I don't know who to turn to =(What I'm trying to do is iterate through a large matrix one line at a time.  For every matrix cell in a line, I'll perform an operation on it and add that cell to a temporary storage array, then when I reach the end of the line, I'll print out that temporary array to a file.I then go on to the next line, and do the same thing, print it out to file... until I get to the end of the matrix.  I'll then have a near-copy of the initial matrix in a new file. Here's the specific code, now that you have an idea of what I'm doing...[source="cpp"]int smallX = 1;int largeX = 1000;int smallY = 1;int largeY = 1000;short * memblock = new short[blockSize];memset(memblock, 0, blockSize*2);ifstream inputFile;inputFile.open("foo.file", ios::in|ios::binary|ios::ate);ofstream finalFile;finalFile.open("bar.file", ios::out|ios::binary|ios::ate);for (int currentLine = 0; currentLine <= (largeY-smallY); currentLine++){for(int currentSample = 0; currentSample <= (largeX-smallX); currentSample++){AlterCell(FooFile, memblock, currentLine, currentSample);}finalFile.write((char *)memblock, blockSize*2);memset(memblock, 0, blockSize*2);}inputFile.close();finalFile.close();delete[] memblock;I've simplified the sourcecode to be easier to read, and I took out a lot of the stuff that matters for my program, but doesn't matter for the bug.The problem is that as soon as my program gets to the delete[] memblock;   it crashes and tosses up the error message I've indicated above.Hopefully there's enough information here that someone who has encountered this before can help... I'd very much appreciate it!   
  It means you have a buffer overrun. It looks like you don't allocate a large enough buffer.   ;  Hah! You're right.  I added 1 to blockSize (whose initialization I forgot to include in my code) and it runs fine now =PThanks =)   ;  That said,- 'short' isn't necessarily 2 bytes. You should at minimum be using 'sizeof(short)' (better yet, 'sizeof(*memblock)') rather than the constant 2.- If your buffer size is a compile-time constant, don't dynamically allocate.- Having an off-by-one buffer size is always suspicious. When dealing with chars, it suggests trying to read null-terminated strings into the buffer and forgetting about space for the null terminator; but you usually have better options anyway. With any other data type, it suggests something even weirder is happening...?- Don't use memset() in c++; use std::fill(). It will optimize down where possible, and call constructors where necessary. It also provides a nicer interface that shields you from having to worry about the size of the data type. - What does 'AlterCell' *do*? In particular, why should it care what the current line and sample number are, if it's just going to read data into a buffer?- You don't need to .close() file objects unless you will reuse them, or open another file object for the same file, in the same scope. The destructor of the file objects calls .close() implicitly at the end.- For extra documentation goodness, mark your constant int values as const. 'const int smallX = 1;', etc. It *may* help the compiler optimize, and while it's not likely to help, it's certain not to hurt. It also definitely will catch the error of trying to change the values somewhere else if you didn't mean to (e.g. writing ++smallX instead of smallX + 1, because you weren't thinking of the need to leave smallX alone and just use the modified value).   