Could this be a stack or Heap corruption?

 

Thankies ^^

-San Saeteurn

________________________________

San Saeteurn

Software Engineer, Switching and Routing Solutions Engineering

Grass Valley, Inc.

Tel: (1) 530 478 3571

Fax: (1) 530 478 4020

Cell: (1) 530 370 7294

E-mail: san.saeteurn@grassvalley.com

Mail:

Grass Valley

400 Providence Mine Road

Nevada City, CA, 95959

USA

 

 

From: Saeteurn San [mailto:San.Saeteurn@grassvalley.com]
Sent: Thursday, September 16, 2010 9:13 AM
To: mingw-users@lists.sourceforge.net
Subject: [Mingw-users] Crash in GDB but not in standalone

 

Howdy,

 

When I run my program under GDB, it consistently crashes with a Segmentation fault somewhere during execution of new.

However, if I run this program independently, not under GDB, it runs just fine…  Further, if I set a breakpoint at the point where it crashes, and step, it doesn’t crash!!

 

The line where it crashes is as follow:

      tmpCell = new CKfCell<short>[2];

 

I am creating a dynamic array of a template class.  The class definition is as follows:

template<typename T>

class CKfCell

{

public:

      //##ModelId=396AAD2B01B7

      CKfCell()

      {

      }

 

      //Conversion operator from raw data to this data type.

      //##ModelId=396AAD2B01B8

      CKfCell(const T & value)

      : mValue(value)

      {

      }

 

      //Copy constructor.

      //##ModelId=396AAD2B01BA

      CKfCell(const CKfCell & rhs)

      : mValue(rhs.value)

      {

      }

 

      //Destructor.

      //##ModelId=396AAD2B01B6

      ~CKfCell()

      {

      }

 

      //Assignment operator using same data type.

      //##ModelId=396AAD2B01A8

      CKfCell & operator=(const CKfCell & rhs)

      {

            if (&rhs != this)

                  mValue = rhs.mValue;

 

            return (*this);

      }

 

      //Assignment operator for raw data type.

      //##ModelId=396AAD2B01AA

      CKfCell & operator=(const T & value)

      {

            mValue = value;

 

            return (*this);

      }

 

#if 0

      operator T()

      {

            return (mValue);

      }

#endif

 

      //Conversion operator to raw data type.

      operator T&()

      {

            return (mValue);

      }

 

      //Conversion operator to raw data type.

      operator T const &() const

      {

            return (mValue);

      }

 

private:

      //Data item.

      //##ModelId=396AAD2B01A7

      T mValue;

};

 

If I put this code and class definition into a small program, then it doesn’t crash at all.

If I modify the code to do a malloc instead, it still crashes.  If I use a type that is NOT “short” it doesn’t crash!

This code is ran in a constructor.  It is the only code in the body of this constructor, though there is a lot of pre-construction going on constructing the same class with different template types used.

 

Anyone have any idea what might be going on?  Seems like a bug in MinGW GDB…

 

Thankies ^^

-San Saeteurn

________________________________

San Saeteurn

Software Engineer, Switching and Routing Solutions Engineering

Grass Valley, Inc.

Tel: (1) 530 478 3571

Fax: (1) 530 478 4020

Cell: (1) 530 370 7294

E-mail: san.saeteurn@grassvalley.com

Mail:

Grass Valley

400 Providence Mine Road

Nevada City, CA, 95959

USA