weird core dump

This is a discussion on weird core dump within the C++ Programming forums, part of the General Programming Boards category; I'm getting a core dump from the delete when using g++, but MS visual studio executes the code just fine. ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    42

    weird core dump

    I'm getting a core dump from the delete when using g++, but MS visual studio executes the code just fine. Any ideas on why this is happening with g++ or better yet how can I debug this. I use ddd/gdb but many of the variables are not being displayed during execution.

    Thanks for any help.

    Code:
    template <typename T, int NODE_SIZE>
    inline void unrolled_list<T,NODE_SIZE>::clear()
    {
        typename unrolled_list<T,NODE_SIZE>::node *n, *n_next;
        for (n = _head->next; n != NULL; n = n_next)
        {
            n_next = n->next;
            delete n; 
        }
        _head->count = 0;
        _head->next = NULL;
        _tail = _head;
    }

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    I see nothing wrong here (assuming you intend not to delete the _head itself). You may be corrupting the heap in some other part of your code.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    42
    Its strange that this only occurs on linux g++ but not Visual studio. Could this be using an unsupported feature.
    The full source for this is located at:

    Unrolled linked list (C Plus Plus) - LiteratePrograms

    Id be curious of the list_test program works ok for others...

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Quote Originally Posted by bean66 View Post
    Its strange that this only occurs on linux g++ but not Visual studio. Could this be using an unsupported feature.
    That's not strange at all, and is another piece of evidence in favor of the heap corruption theory
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    42
    brewbuck,

    I think i found the problem here:
    Code:
     struct node
        {
            static const int values_size_lb =
                (NODE_SIZE - 2*sizeof(node*) - sizeof(int))/sizeof(T);
            static const int values_size =
                values_size_lb == 0 ? 1 : values_size_lb;
    
    
            node()
              : next(NULL), prev(NULL), count(0)
            { cout << "Values Size: " << values_size << endl ;
              cout << "Values SizeLB: " << values_size_lb << endl ;
            }
    
            node* next;
            node* prev;
            int   count;
            T values[values_size];
        };
    
    main() {
          unrolled_list<int,20> lst;
    }

    When I ran this it generated a 1 for the values size and 0 for the values_size_lb.
    However on the VS platform the values size was 2 and values_size_lb was 2...

    After a bit of testing if the value_size was 1, the a core is generated during the free... I believe you are correct that some type of corruption is occurring. If the value_size is 2 then all is well. I'll check the rest of the code and see if there are assumptions about the number of values to be stored in the T values[values_size]; array.....

    Thanks for pointing me in the proper direction.

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    The size of integers and pointers can be different with different compilers. So, if you make the size parameter small enough you can end up with values_size_lb equaling 0 or less (which would be quite bad I guess).
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. having a core dump
    By justins in forum C Programming
    Replies: 6
    Last Post: 05-21-2008, 12:00 PM
  2. STL vector core dump
    By creativeinspira in forum C++ Programming
    Replies: 9
    Last Post: 07-22-2007, 04:49 PM
  3. Core Dump in While()
    By KrepNatas in forum C Programming
    Replies: 5
    Last Post: 05-17-2005, 11:15 AM
  4. core dump
    By kermit in forum Linux Programming
    Replies: 0
    Last Post: 08-03-2004, 06:25 PM
  5. core dump....
    By Shogun in forum C Programming
    Replies: 1
    Last Post: 06-03-2003, 08:41 AM

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