Re: Debugging corrupted memoy



Julien wrote:
) 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
) }

Others have pointed out the problems with calloc().
Here's another two questions:
Is the prototype for obj_iterate in scope (and has it been compiled
for 64-bit pointer architecture) ?
What does obj_iterate return as value and type ?


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
.



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: linked list (c programming)
    ... int i = 0; ... you've just invoked Undefined Behavior, ... I would have thought that the cast to a pointer would transform 0 to ... You all think I'm paranoid, ...
    (comp.programming)
  • Re: Sorting
    ... )> pointer to get to the Data, ... int cmpdouble(const void *vleft, const void *vright) ... You all think I'm paranoid, ...
    (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)