Thread: Should this program generate core ?

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    1

    Should this program generate core ?

    I have question,

    should the below code dump core?

    Please debate if yes/no why ?

    Code:
    char a[6];  a[6]='\0';
    Last edited by pravlm; 10-01-2010 at 04:57 PM.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    It's definitely wrong, but whether it dumps core depends on many factors. In this case, you got unlucky and the bug didn't make itself known. Obviously, it's better if it dumps core because then you know you have a problem.

    A stack overflow usually causes a segfault through an indirect chain of events. The invalid memory access itself doesn't usually cause a fault. It's the corruption which happens to the stack which causes things to go haywire later. If the overflow destroys the base link pointer, then when the function returns, the calling function will have a messed up set of variables. If the overflow destroys the return address, the code will jump somewhere unpredictable and possibly crash. In other words, it will probably crash but not immediately on that line of code.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. im a noob at c++, do you think so?
    By belRasho in forum C++ Programming
    Replies: 6
    Last Post: 04-25-2010, 11:02 PM
  2. need help on C++ program
    By tezr87 in forum C++ Programming
    Replies: 1
    Last Post: 06-01-2006, 04:40 AM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM