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

Crash when incorrectly calling member function #15

Closed
Flamefire opened this issue Mar 18, 2016 · 1 comment · Fixed by #16
Closed

Crash when incorrectly calling member function #15

Flamefire opened this issue Mar 18, 2016 · 1 comment · Fixed by #16
Labels

Comments

@Flamefire
Copy link
Contributor

I found a crash that can easily occur by a typo in the lua code:

std::map<unsigned, unsigned> myMap;

class FooClass{
public:
    void mapCallback(const std::map<unsigned, unsigned>& map)
    {
        myMap = map;
    }
};

void testMap(kaguya::State& state)
{
    state["testMap"].setClass(kaguya::ClassMetatable<FooClass>().addMemberFunction("testMap", &FooClass::mapCallback));
    state["foo"] = FooClass();
    // Wrong -> Crash
    state("myMap = {[1]=2, [3]=4, [5]=6}\n foo.testMap(myMap)");
    //Correct
    state("myMap = {[1]=2, [3]=4, [5]=6}\n foo:testMap(myMap)");
    TEST_EQUAL(myMap[1], 2);
    TEST_EQUAL(myMap[3], 4);
    TEST_EQUAL(myMap[5], 6);
}

The reason is that the . instead of : skips the this pointer and kaguya does not detect the invalid argument count and happily tries to get a map from index 2 at the stack which is not there. Such errors should be detected

satoren added a commit that referenced this issue Mar 18, 2016
@satoren
Copy link
Owner

satoren commented Mar 18, 2016

thanks for report and PR.
It fixed code did not use, but merged test code.

@satoren satoren added the bug label Mar 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants