The Wayback Machine - https://web.archive.org/web/20220706210234/https://github.com/github/codeql/issues/9784
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ Call Target Predicates with Polymorphism #9784

Open
bdrodes opened this issue Jul 6, 2022 · 0 comments
Open

C++ Call Target Predicates with Polymorphism #9784

bdrodes opened this issue Jul 6, 2022 · 0 comments
Labels
question

Comments

@bdrodes
Copy link

@bdrodes bdrodes commented Jul 6, 2022

I'm experimenting with getting the target function for virtual function calls in C++. The documentation for FunctionCall suggests that getTarget() should return the 'most-specific function in the override tree', but I'm not sure if that is the behavior I'm observing.

In the example below, I have three calls, where I would expect the target for CALL1 to be a the ChildClass target, CALL2 the ParentClass target, and CALL3to be potentially from both ChildClass and ParentClass. In all cases, however, codeql reports the target as being the ParentClass function. Is that the expected result to getTarget() for FunctionCall, and is there a way to get my expected result with codeql?

#include <iostream>
#include <cstdlib>

using namespace std;

class ParentClass
{
	public:
		virtual char* test_func()
		{
			return "PARENT: test_func";
		}

};

class ChildClass: public ParentClass
{
	public:
		virtual char* test_func()
		{
			return "CHILD: test_func";
		}

};


int main(int argc, char** argv)
{

    ParentClass *c;
    if(argc > 1)
    {
        c = new ChildClass();
       // CALL1
        c->test_func();
    }
    else
    {
        c = new ParentClass();
        // CALL2
        c->test_func();
    }

    // CALL3
    c->test_func();
}
@bdrodes bdrodes added the question label Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question
Projects
None yet
Development

No branches or pull requests

1 participant