473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

New debugging method(OT?)

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
1 1084
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: demo | last post by:
using visual studio 6 with service pack 0 and 5, why does the distructor of a class contained inside a namespace isn't called and instead it's called when: - iostream.h is included instead of...
7
by: Advocated | last post by:
Hi there, just wondering if anyone uses visual studio 6? Im having real problems, just with debugging, i could either do with a really good tutorial, if anyone knows of one, but the main thing...
7
by: e | last post by:
I've been having an extremely difficult time finding an answer to this in IE / js groups, so I thought I'd try here. I've got an aspx page that delivers loads of report data into custom-named...
1
by: si_owen | last post by:
Hi folks, I started a project, web app, last week in visual studio 2005, and restored my computer on the weekend. I have re-installed visual studio and have set up IIS again to create my root...
40
by: ramu | last post by:
Hi, what happens when i run the below code? main() { int *p; while(1) p= (int *)malloc(1000); } Do i get segmentation fault?
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
51
by: Zach | last post by:
What are the best websites (or HTML or PDF free books available for download and if so where) for learning C? Is this a good site: http://www.space.unibe.ch/comp_doc/c_manual/C/cref.html Zach
13
by: Hussein B | last post by:
Hi, I'm familiar with static method concept, but what is the class method? how it does differ from static method? when to use it? -- class M: def method(cls, x): pass method =...
33
by: fmassei | last post by:
Hello! I made a short piece of code that I find very useful for debugging, and I wanted to ask you if it is correct, somehow acceptable or if I simply reinvented the wheel. To deal with some bad...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.