Skip to content

[ModuleManager] Added dynamic cast instead of static_cast

Matteo Pignataro requested to merge module-manager-fix into main

Corrected static_cast to a more secure dynamic_cast, that allows for proper downcasting. For reference: https://en.cppreference.com/w/cpp/language/dynamic_cast.

static_cast performs an unsafe bitwise pointer cast, this assumes that the Boardcore::Module pointer and the class pointer coincide. This is not always the case, for example if our module class inherits from multiple different classes, the various base classes will be at different addresses, so performing a static_cast from Boardcore::Module to our class could lead to a pointer in the middle of the class.

The reason this hasn't been an issue yet is that for some reason with our compiler Boardcore::Module always coincide with the class, this is probably due to the virtual constructor, but this is completely arbitrary and we cannot rely on it.

Edited by Davide Mor

Merge request reports

Loading