Should this program generate core ?

This is a discussion on Should this program generate core ? within the C Programming forums, part of the General Programming Boards category; I have question, should the below code dump core? Please debate if yes/no why ? Code: char a[6]; a[6]='

  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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21