Why am I getting warning C28182 when using boost polymorphic_cast?

I am getting this error ( C12182 ) while compiling Release | x86 of my code when used boost::polymorphic_cast

to ensure that the pointer is not null.

Warning 2   warning C28182: Dereferencing NULL pointer. 'tv' contains the same NULL value as '(dva::TimedValue *)=(tv)' did. : Lines: 808, 810, 812, 813, 808, 810, 812 c:\path\to\my\code\timedvalue.cpp   812 1   mylibrary

      

My question is, why do I need this warning? What should I do? polymorphic_cast

will issue if the pointer is null. As far as I understand, this code is correct. What am I missing?

Here is my code. apr_time_t

is a 64-bit int, and m_cobjs is a vector of pointers to the class from which it is derived TimedValue

. Commented out ASSERT_PTR

throws an exception if the pointer is null and resolves the warning if I don't comment it out.

void TimedValueTable::RemovePointsBefore(apr_time_t time)
{
    for (size_t i = 0; i < m_cobjs.size(); )
    {
        TimedValue *tv = boost::polymorphic_cast<TimedValue *>(m_cobjs[i]);
        // ASSERT_PTR(tv);
        if (tv->get_Time() < time)
            delete tv;
        else
            ++i;
    }
}

      

+3


source to share





All Articles