Operating System - HP-UX
1834158 Members
2406 Online
110064 Solutions
New Discussion

Core dump casting NULL to virtual base class

 
SOLVED
Go to solution
David W Lauderback
New Member

Core dump casting NULL to virtual base class

Bug(?) with "aCC: HP ANSI C++ B3910B A.03.30"

Casting a null pointer to a virtual base class
appears to try to reference its virtual (function)
table and crash. This works on older versions of
the compiler and on other compilers (Sun's and MSVC).

Casting of NULL pointers as a special case is
described in "The C++ Programming Language" by
Bjarne Stroustrup Section 15.4.1 (dynamic_cast).

The following code compiles but (incorrectly)
core dumps. Is there a patch for this? I could
not find one.

Dave Lauderback
davel@silvaco.com

======= Dummy example code ==================

class Item
{
public:
Item(){}
virtual ~Item();
};

Item::~Item()
{
}

class List : virtual public Item
{
public:
List(){}
virtual ~List(){}
};


int main(int argc , char* argv[])
{
List* context = 0;
Item* death = context;
return 0;
}

======= end example ==========================
2 REPLIES 2
Steven Gillard_2
Honored Contributor
Solution

Re: Core dump casting NULL to virtual base class

Try patch PHSS_25170, which has the following defect fix:

JAGad58885: Signal 11, derived to virtual base
conversion not checked for NULL.

Regards,
Steve
David W Lauderback
New Member

Re: Core dump casting NULL to virtual base class

Thanks, PHSS_25170 did solve
my problem. Due to priority
changes, I did not get a chance to
test it until now.

Thanks again.
Dave L.