Another dynamic memory allocation bug.
- by m4design
I'm trying to allocate memory for a multidimensional array (8 rows, 3 columns).
Here's the code for the allocation (I'm sure the error is clear for you)
char **ptr = (char **) malloc( sizeof(char) * 8);
for (i = 0; i < 3; i++)
ptr[i] = (char *) malloc( sizeof(char) * 3);
The crash happens when I reference this:
ptr[3][0];
Unhandled exception at 0x0135144d in
xxxx.exe:
0xC0000005: Access violation writing
location 0xabababab.
Are there any recommended references/readings for this kind of subject?
Thanks.