I am using VS2017 and have the following lines of C code (sorry can't post all contents of function):
char *dptr; /* Global variables */
static u_int16_t vers;
...
static int32_t
read_row(database_t *dbase, table_t *table, int32_t col_flag, int32_t flag) {
row_t *rowptr;
char marker;
void *new_row;
table_t *t_new;
size_t row_length;
size_t row_ = 1;
marker = *dptr++;
if (vers < VERS && marker != ROW) {
return -1;
}
/* Create a new row */
t_new = table;
row_length = t_new->row_length;
new_row = calloc(row_, row_length);
rowptr = new_row;
if (rowptr == NULL)
return -1;
...
The last line is causing "Exception thrown at 0x00000000778745A0 (ntdll.dll) in ****.exe: 0xC0000005: Access violation reading location 0x00000000787745A0" error.
During debug, when I hover my pointer on calloc, I can see its value is "0x000000013f63dc94". But somehow, the exception is thrown and this value is never assigned to new_row (its value remains "0xcccccccccccccccc").
I have noticed that this exception is thrown when calloc has a value >"0x00000001********". It seems to work fine if 8 MSB of the address are 0. The definition of calloc() is from corecrt.malloc.h:
_Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size)
_ACRTIMP _CRT_JIT_INTRINSIC _CRTALLOCATOR _CRTRESTRICT
void* __cdecl calloc(
_In_ _CRT_GUARDOVERFLOW size_t _Count,
_In_ _CRT_GUARDOVERFLOW size_t _Size
);
Any ideas about what could be causing this exception and how to fix it would be appreciated. Btw, I am using Win 7 Pro with 8GB RAM.
User contributions licensed under CC BY-SA 3.0