Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Add undesired /dangerous type conversion queries #79

Open
itsacoderepo opened this issue May 5, 2021 · 1 comment
Open

Add undesired /dangerous type conversion queries #79

itsacoderepo opened this issue May 5, 2021 · 1 comment
Assignees

Comments

@itsacoderepo
Copy link
Contributor

Add a query undesired /dangerous type conversion

for example : "int" to "short"

int foo(int iPram)
{
    int iBig = 0;
    short sSmall = 0;

    iBig = iPram;
    sSmall = (short)iBig;
    return sSmall;
}
@jaiverma
Copy link

jaiverma commented May 6, 2021

Here are two queries that I use for similar patterns.

For finding mismatched casts, similar to the one in the example:

cpg.call.name("<operator>.cast").filter(
    call =>
        call.argument.order(1).code != call.argument.order(2).evalType).l

For finding mismatched assignments without a cast:

cpg.call.name("<operator>.assignment").filter(
    call => {
        def lhs = call.argument.order(1).isIdentifier
        def rhs = call.argument.order(2).isIdentifier

        if (lhs.size > 0 && rhs.size > 0) lhs.head.typeFullName != rhs.head.typeFullName
        else false
    }).l

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants