This is from gdb:
22 database->size = size;
(gdb) n
23 return database;
(gdb) p size
$6 = 1401
(gdb) p database->size
$7 = 3086862424
(gdb) p &size
$8 = (unsigned int *) 0xbffff050
(gdb) p &database->size
$9 = (unsigned int *) 0xb7fc6ff8
This is from the code:
typedef struct _DATABASE {
RESULT* res;
unsigned int size;
} DATABASE;
....
....
DATABASE* alloc_database(unsigned int size, DATABASE* database)
{
database = (DATABASE*) malloc (sizeof(DATABASE));
if (!database) return NULL;
database->res = (RESULT*) malloc (sizeof(RESULT) * size);
if (!database->res) {
free_database(database);
return NULL;
}
memset(database->res, 0, sizeof(RESULT) * size);
database->size = size;
return database;
}
You can see that both database->size and size are from the (unsigned int) type, in both code and gdb, but for some reason, after the assignment the values are different.
Does anyone knows the what is the reason of that?