Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tlug: gcc misplacing pointers?



>>>>> "Scott" == Scott Stone <sstone@example.com> writes:

    Scott> char *s0;

    Scott> s0=(char *)malloc(80);

    Scott> (and then proceeded to do operations on s0).

My first guess would be what the "operations on s0" are trampling over
the bits of memory that malloc/free use to keep track of chunks of
memory. 

As a second guess, the function is writing past the end of the 80 byte
and killing something else.

    Scott> Anyway, it would segfault upon leaving the function in
    Scott> '_libc_free()', according to gdb.  What was weird, though
    Scott> is that if I set the breakpoint one line past the malloc
    Scott> statement, and said 'print s0', it would say, 'no symbol s0
    Scott> in current context'.

I seen the behavior as well. Not sure of the cause. 

    Scott> Changing s0 to be 'char s0[200]' and removing the malloc
    Scott> line fixed the problem.

If it did not work the char s0[80], then the function is most likely
writing past the end of the s0 and clobbering the stack. After thats
done, anything can happen :)

    Scott> Any idea why gcc would 'lose' the pointer to s0 like that?

Try 'info locals' in gdb. It will tell what it thinks your local
variables are.

One last possibility is that something before your function clobbered
memory, making for some very strange behavior. On Solaris I use
"purify" to catch such nasty things, but I don't know if there is a
public domain equivalent. It checks all memory accesses to make sure
nothing funny is going on. If there public domain tool that does the
same, I love to find out about it.

Andy
---------------------------------------------------------------
Next TLUG Nomikai: 11 March Wed 1998 Tengu TokyoEkiMae 19:30
Chuo-ku, Kyobashi 1-1-6, EchiZenYa Bld. B1/B2 03-3275-3691
Next TLUG Meeting: 11 April 1998 Saturday, Tokyo Station
Featuring Tague Griffith of Netscape i18n talking on source code
---------------------------------------------------------------
a word from the sponsor:
TWICS - Japan's First Public-Access Internet System
www.twics.com  info@example.com  Tel:03-3351-5977  Fax:03-3353-6096



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links