Re: Debugging corrupted memoy



static int do_stuff()
{
obj_t res = *calloc((size_t)1, sizeof(obj_t));
// res is 0x000000..
obj_iterate(res);
// res is 0xffffff..
do_other_stuff(res->fied); <-- SIGSEGV
}
The code is fundamentally wrong. You do not dereference the result of
calloc() and assign it to an object, but assign it to a pointer to the
object.

obj_iterate() probably and do_other_stuff() definitely expect "res" to be a
pointer, when here it isn't.

.



Relevant Pages

  • Re: Debugging corrupted memoy
    ... i callocated a pointer to a user-defined struct. ... But your code below cannot be doing that, because you are _not_ using calloc to store a value in a pointer. ... res is not a pointer to obj_t but an obj_t. ... Unneeded casts are often incorrect casts, and the occurance of casts, while sometimes appropriate, are more often signs of poor design or inadequate understanding. ...
    (comp.lang.c)
  • Re: Debugging corrupted memoy
    ... i callocated a pointer to a user-defined struct. ... // res is 0xffffff.. ... Why the asterisk in front of calloc? ...
    (comp.lang.c)
  • Re: Debugging corrupted memoy
    ... calloc() and assign it to an object, but assign it to a pointer to the ... If obj_iterateis a function and the value of 'res' is ... 'obj_iterate' is a macro show us also what its doing. ...
    (comp.lang.c)
  • Re: mysql problem
    ... > Thus, res becomes null. ... mysql_store_resultalso returns a null pointer if reading of the ... An empty result set is returned if there are no rows returned. ...
    (comp.lang.c)
  • FindResource() / LoadResource() return an invalid pointer
    ... char *GetRes ... HRSRC hResource; ... if(!(hResource = FindResource(gInstance, res, RT_RCDATA))) ... The pointer returned by FindResourceand/or LoadResourceseems to be ...
    (microsoft.public.pocketpc.developer)