Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > C++ application which crashes in dynamic_cast

Reply
Thread Tools

C++ application which crashes in dynamic_cast

 
 
yinglcs@gmail.com
Guest
Posts: n/a
 
      01-17-2007
Hi,

I have a c++ application which crashes in this line (from the debugger,
I have a segmentation fault here):
void *object = dynamic_cast<void>(aObject);


I have stepped thru the code in debugger and the 'aObject' pointer is
Not null. So can you please tell me, what else can go wrong so that my
program crashes in this line?

Thank you. for any help.



Code:

NS_IMETHODIMP
nsTraceRefcntImpl::LogAddCOMPtr(void* aCOMPtr,
nsISupports* aObject)
{
#if defined(NS_BUILD_REFCNT_LOGGING) &&
defined(HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR)
// Get the most-derived object.
void *object = dynamic_cast<void>(aObject); // crashes in this
line????
//......

}

 
Reply With Quote
 
 
 
 
Andre Kostur
Guest
Posts: n/a
 
      01-17-2007
"(E-Mail Removed)" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) oups.com:

> Hi,
>
> I have a c++ application which crashes in this line (from the debugger,
> I have a segmentation fault here):
> void *object = dynamic_cast<void>(aObject);
>
>
> I have stepped thru the code in debugger and the 'aObject' pointer is
> Not null. So can you please tell me, what else can go wrong so that my
> program crashes in this line?
>
> Thank you. for any help.
>
>
>
> Code:
>
> NS_IMETHODIMP
> nsTraceRefcntImpl::LogAddCOMPtr(void* aCOMPtr,
> nsISupports* aObject)
> {
> #if defined(NS_BUILD_REFCNT_LOGGING) &&
> defined(HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR)
> // Get the most-derived object.
> void *object = dynamic_cast<void>(aObject); // crashes in this
> line????
> //......
>
> }



dynamic_cast to a void? I thought you had to either dynamic_cast to either
a pointer (and check the return value for NULL) or a reference (and be
prepared for a bad_cast exception).
 
Reply With Quote
 
 
 
 
yinglcs@gmail.com
Guest
Posts: n/a
 
      01-17-2007

That is code from others. But i would like to investigate when the
program crashes at that line.

Thank you.

Andre Kostur wrote:
> "(E-Mail Removed)" <(E-Mail Removed)> wrote in
> news:(E-Mail Removed) oups.com:
>
> > Hi,
> >
> > I have a c++ application which crashes in this line (from the debugger,
> > I have a segmentation fault here):
> > void *object = dynamic_cast<void>(aObject);
> >
> >
> > I have stepped thru the code in debugger and the 'aObject' pointer is
> > Not null. So can you please tell me, what else can go wrong so that my
> > program crashes in this line?
> >
> > Thank you. for any help.
> >
> >
> >
> > Code:
> >
> > NS_IMETHODIMP
> > nsTraceRefcntImpl::LogAddCOMPtr(void* aCOMPtr,
> > nsISupports* aObject)
> > {
> > #if defined(NS_BUILD_REFCNT_LOGGING) &&
> > defined(HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR)
> > // Get the most-derived object.
> > void *object = dynamic_cast<void>(aObject); // crashes in this
> > line????
> > //......
> >
> > }

>
>
> dynamic_cast to a void? I thought you had to either dynamic_cast to either
> a pointer (and check the return value for NULL) or a reference (and be
> prepared for a bad_cast exception).


 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      01-17-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> I have a c++ application which crashes in this line (from the debugger,
> I have a segmentation fault here):
> void *object = dynamic_cast<void>(aObject);
>
>
> I have stepped thru the code in debugger and the 'aObject' pointer is
> Not null. So can you please tell me, what else can go wrong so that my
> program crashes in this line?
>
> Thank you. for any help.
>
>
>
> Code:
>
> NS_IMETHODIMP
> nsTraceRefcntImpl::LogAddCOMPtr(void* aCOMPtr,
> nsISupports* aObject)
> {
> #if defined(NS_BUILD_REFCNT_LOGGING) &&
> defined(HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR)
> // Get the most-derived object.
> void *object = dynamic_cast<void>(aObject); // crashes in this
> line????
> //......
>
> }
>


The cast should be to void*, not to void.

Per 5.2.7, it is legal to dynamic cast to void* (specifically 5.2.7/1
and 5.7.7/7).

To be honest, I'm surprised your fragment compiled if it really is
<void> and not <void*>.



 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      01-17-2007
(E-Mail Removed) wrote:

>
> That is code from others. But i would like to investigate when the
> program crashes at that line.


Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
James Gosling the Creator of EMACS and JAVA - leaves ORACLE - Butthen reports started coming in of odd failures. Systems would crashstrangely. We'd get crashes in applications. All applications. Crashes in thekernel. small Pox C Programming 2 07-22-2010 10:07 PM
typeid and dynamic_cast, gcc 3.3 Andreas Sch. C++ 18 01-29-2004 10:24 PM
how static_cast and dynamic_cast implemented? Yuming Ma C++ 1 12-17-2003 12:58 AM
dynamic_cast and references Dan Noland C++ 0 07-29-2003 09:43 PM
dynamic_cast<> alg C++ 3 07-14-2003 09:08 AM



Advertisments