「view this page in B3 βῆτα server」

Revisions №60368

branch: master 「№60368」
Commited by: Vikram K. Mulligan
GitHub commit link: 「64d61ab7a9e5521d」 「№3428」
Difference from previous tested commit:  code diff
Commit date: 2018-08-27 11:53:48

Merge pull request #3428 from RosettaCommons/vmullig/fix_parametric_ubsan_issue Trying to fix an ubsan issue that I introduced when refactoring the parametric code I had a base class with a method in it that could be used to determine the derived class, and a switch statement of the following pattern: ```c++ // Using static_cast instead of dynamic_cast to avoid the overhead of a dynamic_cast, since I // don't need dynamic_cast to tell me the derived class type because I have the class function // instead: DerivedClass1OP class1pointer( static_pointer_cast< DerivedClass1 >( baseclass_pointer ); DerivedClass2OP class2pointer( static_pointer_cast< DerivedClass2 >( baseclass_pointer ); switch( baseclass->tell_me_derived_class() ) { case class1: // Do stuff with the class1pointer break; case class2: // Do stuff with the class2pointer break; } ``` This meant that I was guaranteed to be setting up at least one pointer that had been invalidly static-casted to the wrong type, but I was never using it, so it didn't matter. The code was working as written, but was probably a bit fragile and non-ideal, and was tripping up the Ubsan tests. (If ever someone modified it and _did_ try to do something with the wrong pointer, it would cause nasty things to happen.) I've refactored it to follow this safer pattern instead: ```c++ switch( baseclass->tell_me_derived_class() ) { case class1: { //Scope for declaration DerivedClass1OP class1pointer( static_pointer_cast< DerivedClass1 >( baseclass_pointer ); // Do stuff with the class1pointer break; } case class2: { //Scope for declaration DerivedClass2OP class2pointer( static_pointer_cast< DerivedClass2 >( baseclass_pointer ); // Do stuff with the class2pointer break; } } ```

...