By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,804 Members | 1,634 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,804 IT Pros & Developers. It's quick & easy.

New debugging method(OT?)

P: n/a
Probably OT, but I did not get any suitable group to discuss this as
this post also has question regarding malloc.
For my current project I am inserting the following statements
randomly.
{
int x = 0;
if (x == 1)
exit(0);
}
I can exit by setting x to 1(Using Debugger) at anytime I want.I found
that if there is any mistake in the like dynamic array overflow, The
program will exit with SIGSEGV.If there is nothing wrong with code
until exiting, the program will exit normally.I know this does not work
always, but I am able to find certain mistakes.

Now, Have a look at the following piece of code.

{
int x = 0;
if (x == 1)/*I can exit when ever I want by setting x to 1 using
debugger*/
exit(0); /*Here the program is exiting normally*/
}
some_var = malloc(some size);
{
int x = 0;
if (x == 1)
exit(0);/*Here the program is exiting with SIGSEGV*/
}

When the exit statement is executed after malloc the program is exiting
with SIGSEGV, but if the exit statement is executed just before malloc,
it is exiting normally.Does this mean there is some problem with
malloc(I don't think so:))?Or what is causing this strange behavior?

I am using gcc on Linux for compilation.

Dec 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
va******@rediffmail.com wrote:

<snip>
When the exit statement is executed after malloc the program is exiting
with SIGSEGV, but if the exit statement is executed just before malloc,
it is exiting normally.Does this mean there is some problem with
malloc(I don't think so:))?Or what is causing this strange behavior?
You are almost certainly correct in thinking malloc is *not* the
problem. The problem is almost certainly that you have gone of the end
of a buffer (either end) and overwritten some data critical to the
correct operation of malloc, thus *you* are causing malloc to fail.
However, it could be something you have done 23487972354 lines earlier.

Of course, if you had checked the comp.lang.c FAQ you would have seen
lots of information on this.

http://www.eskimo.com/~scs/C-faq/q16.8.html
http://www.eskimo.com/~scs/C-faq/q7.19.html

Lots of other questions in the FAQ apply as well.
I am using gcc on Linux for compilation.


<OT>
Try using valgrind, but don't ask for help on it here since we only deal
with standard C not all the multifarious tools that are available.
</OT>
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Dec 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.