Re: Debugging corrupted memoy



Julien Lafaye wrote:
Hello,

i callocated a pointer to a user-defined struct. The value of the pointer is
something like 0x0000002aaaaa (can't remember actually, I don't have the
computer running the code with me). Then I perform some stuff on the
allocated structure which must be buggy since after its execution the value
of the pointer is something like 0xffffff2aaaaa, i.e. same lsb, different
msb. I don't know where to start to debug this. Obviously, when I run the
programm I get a SIGSEGV when deferencing the pointer and valgrind shows no
indication of invalid memory access. Do you have any clue on how to start
debugging this. Below is the template of my code.


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
}

Julien

PS: my architecture is X86_64, Linux, gcc-4; code is compiled without
optimization, debugging symbols activated

Julien...

Why the asterisk in front of calloc?

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto/
.



Relevant Pages

  • Re: An example of MACHO programming and why is wrong
    ... "space for an array of nmemb objects, ... then it should return a null pointer, ... of calloc(), not it's arguments (without implying that the parameters ... or not nmemb*size correctly calculates the amount of space required. ...
    (comp.lang.c)
  • Re: Trap representation
    ... I would say that it is possible for undefined behavior to occur. ... the calloc() itself would not cause undefined behavior. ... The calloc function returns either a null pointer or a pointer to ... representation and is read by an lvalue expression that does not have ...
    (comp.lang.c)
  • 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: Null terminated strings: bad or good?
    ... You name it by prefixing the name of the pointer with a *. ... That's not the name of the object, it's an lvalue expression that refers ... if it was in fact the entire object allocated by the call to calloc(). ... value 2, or equivalently sizeof **ptr. ...
    (comp.std.c)
  • Re: Null terminated strings: bad or good?
    ... You name it by prefixing the name of the pointer with a *. ... That's not the name of the object, it's an lvalue expression that refers to an object. ... if it was in fact the entire object allocated by the call to calloc(). ... value 2, or equivalently sizeof **ptr. ...
    (comp.std.c)