-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
avoid undefined behaviour from downcasting ptr implentation #5
Conversation
avoid runtime errors of wrong downcasts by adding a underlaying ptr data getter and only cast the data, downcasting the implentation type isnt inherited from eachother, while the intention was do upcast/downcast a derived class to a base class. found with UBSAN "runtime error: downcast of address which does not point to an object of type "CSharedPointer_::impl<IKeyboard>" note: object is of type "Hyprutils::Memory::CSharedPointer_::impl<CKeyboard>" also make dataNonNull check against != nullptr.
make it more type safe, C style casts tries every single one until one works, or not. compilers also produces better warnings/errors when using c++ casts in favour of C style ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
or does it break the ABI? I think it does. edit: yeah newer will expect a vtable entry for get |
Yeah , Adding a virtual function breaks ABI because it changes the layout (and possibly the order) of entries in the vtable |
I don't think it changes the order, arent vtable indices just ordered the way they are in the src? |
havent digged that deep into vtables but googling it a bit the order is a bit up to the compiler but mostly should stay the same when it comes to adding new virtual functions at the end of the class, But we still have the derived impl class, so i suspect the addition of the function could change the order depending on how the vtable is layed out there? i mean
thats fine, order sticks. but what about the derived?
derived::bar() and derived::bar2() is now moved down a step. and isnt the size of the vtable now also potentially increased breaking ABI further? |
ABI is broken and thats what really matters (I'll have to bump sover at release) the rest was me just being curious |
Yeah you made me curious aswell 😄 |
errors can be seen with UBSAN in hyprland like
and the reason is because CKeyboard is a derived class from the base IKeyboard so the underlaying ptr can be casted but the implentation stored in the ptrs is not related. so add a getter and only cast the underlaying ptr.
also change C style casts in favour of reinterpret_cast.