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

Dereference of an uninitialized boost::optional in rotors code #998

Open
joergbrech opened this issue Feb 29, 2024 · 0 comments
Open

Dereference of an uninitialized boost::optional in rotors code #998

joergbrech opened this issue Feb 29, 2024 · 0 comments

Comments

@joergbrech
Copy link
Contributor

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:

return *GetNominalRotationsPerMinute() / 30. * M_PI * GetRadius();

if (GetRotor().GetNominalRotationsPerMinute() < 0. ) {

return *GetRotor().GetNominalRotationsPerMinute() / 30. * M_PI * GetRadius();

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.

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

No branches or pull requests

1 participant