weggli-rs / weggli

weggli is a fast and robust semantic search tool for C and C++ codebases. It is designed to help security researchers identify interesting functionality in large codebases.
Apache License 2.0
2.34k stars 130 forks source link

Is it possible to only report when the last else {} contains a single statement only (either throw or return) ? #40

Open 0x8000-0000 opened 2 years ago

0x8000-0000 commented 2 years ago

Is it possible to only report when the last else {} contains a single statement only (either throw or return) ?

So, I want to find these:

if (condition)
{
    /* do */
    /* many */
    /* things */
}
else
{
    throw PreconditionNotSatisified{};   // or return -ERROR
}

but not these:

if (condition)
{
    /* do */
    /* many */
    /* things */
}
else
{
    if (someOtherCondition)
    {
        // try something else
    }
    else
    {
         throw PreconditionNotSatisified{};   // or return -ERROR
    }
}

Originally posted by @0x8000-0000 in https://github.com/googleprojectzero/weggli/issues/17#issuecomment-951189507