Consider this snippet:
The program is quite happy to give me the benefit of the doubt in writing ints past the 200th place of the memory I allocated with malloc(). However, the realloc() causes this error:Code:int main() { int *pInt; int i; pInt = malloc(200 * sizeof(int)); for (i = 0; i < 300; i++) *(pInt + i) = 1; pInt = realloc (pInt, 400 * sizeof(int)); return 0; }
I know this is probably a dumb question, but what does realloc() care that I assigned to out of bounds memory in the for-loop? Why doesn't it just reallocate the block I originally asked for and have done with it?Heap block at 00301B40 modified at 00301E8C past requested size of 344