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

Overridden methods populated with incompatible function pointer types. #3345

Open
robertwb opened this issue Feb 5, 2020 · 0 comments
Open

Overridden methods populated with incompatible function pointer types. #3345

robertwb opened this issue Feb 5, 2020 · 0 comments

Comments

@robertwb
Copy link
Contributor

@robertwb robertwb commented Feb 5, 2020

Given

cdef class Base(object):
    cdef int foo(self):
        ...

cdef class Sub(Base):
    cdef int foo(self):
        ...

we know that the self argument of Sub.foo is Sub. However, when inserting this in the vtable, we declare a C function of signature int(struct Sub*) rather than int(struct Base*) and simply cast it to the latter to put it in the base vtab. It is subsequently called via this base-class signature, which is technically undefined behavior. While this works fine in practice, it can trip up sanitizers such as ubsan (potentially masking further issues).

What we should do instead is declare the self argument to be the base type in the function declaration and then cast it to the correct type in the function body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.