Re: Debugging corrupted memoy



Julien Lafaye <sensei+usenet@xxxxxxxxxxx> wrote:
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.

Sorry, typo in my snippet. One should read

obj_t *res = calloc((size_t)1, sizeof(obj_t));

Ok, that look more reasonable. What about other questions
like if you have included <stdlib.h> and how you did get
the value of 'res'? And what is obj_iterate() actually
doing (is it a function or a macro and why does its name
contain "iterate" when there's only one such structure)?
Finally, what is do_other_stuff() do or is it really
segfaulting already when called with 'res->fied' (what-
ever 'fied' is supposed to mean)?

If obj_iterate() is a function and the value of 'res' is
really changed after its call then I would speculate that
you're doing something nasty in obj_iterate() that some-
how writes over the place where 'res' is stored. And if
'obj_iterate' is a macro show us also what its doing.

Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.



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
    ... // res is 0xffffff.. ... You do not dereference the result of ... calloc() and assign it to an object, but assign it to a pointer to the ... pointer, when here it isn't. ...
    (comp.lang.c)
  • RE: Multiple sheet search
    ... personal workbook. ... Then select a cell or two and turn off macro recording. ... Dim ans As String, rng As Range ... Dim res As Long ...
    (microsoft.public.excel.programming)
  • Re: transforming code into typed code
    ...  And I decide (and specify) that lengths cannot ... function that would calculate lengths would be prefixed with an L! ... (let ((res (... ...
    (comp.lang.lisp)