Menu

var->valueType() nullptr when dereferenced

2020-11-19
2020-11-22
  • David Ledger

    David Ledger - 2020-11-19

    Gday,

    The following outlines some issues:

    The following results in a cppcheck crash. var->valueType() can be nullptr.

        out << " access=\""         << accessControlToString(var->mAccess) << '\"';
        out << " scope=\""          << var->scope() << '\"';
        out << " constness=\""      << var->valueType()->constness << '\"'; // THIS
        out << " isArgument=\""     << var->isArgument() << '\"';
        out << " isArray=\""        << var->isArray() << '\"';
    

    Also here:

        if (var->valueType()->type == ValueType::Type::CONTAINER) {
        } else if (var->type() && !var->type()->isEnumType()) { // Check if type is a struct or class.
            // Ensure that it is a large object.
            if (!var->type()->classScope)
                inconclusive = true;
            else if (estimateSize(var->type(), mSettings, symbolDatabase) <= 2 * mSettings->sizeof_pointer)
                continue;
        } else
            continue;
    

    The code that reproduces it is something like this, tough to reproduce outside of my project...

    struct Thing
    {
        struct B
        {
            const Command Code;
        };
        union
        {
            B         Bits;
            bytes<1u> Write;
        };
    
        PowerDown(decltype(Write) args) noexcept : Write{ args } {}
    };
    

    The variable args doesn't get a valueType.

     
  • Daniel Marjamäki

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.