tigl icon indicating copy to clipboard operation
tigl copied to clipboard

Dereference of an uninitialized boost::optional in rotors code

Open joergbrech opened this issue 4 months ago • 0 comments

CPACSRotor::GetNominalRotationsPerMinute() returns a boost::optional<double>&. The return value is dereferenced in several places without first checking if the boost::optional holds a value:

https://github.com/DLR-SC/tigl/blob/ede4575ff42c8f7359e940fa2b92c2e48050862e/src/rotor/CCPACSRotor.cpp#L220

https://github.com/DLR-SC/tigl/blob/ede4575ff42c8f7359e940fa2b92c2e48050862e/src/rotor/CCPACSRotorBladeAttachment.cpp#L84

https://github.com/DLR-SC/tigl/blob/ede4575ff42c8f7359e940fa2b92c2e48050862e/src/rotor/CTiglAttachedRotorBlade.cpp#L216

Suggestion:

I suggest shadowing GetNominalRotationsPerMinute in CCPACSRotor with a wrapper function that returns a double by calling generated::CPACSRotor::GetNominalRotationsPerMinute().get_value_or(0.); This makes sure that the default value for this optional is defined only in one place in the code.

joergbrech avatar Feb 29 '24 12:02 joergbrech