Potential dangling reference on ActionParameterView example
Hello, In the example file (https://git.openlogisticsfoundation.org/silicon-economy/libraries/vda5050/libvda5050pp/-/blame/main/examples/src/detailed_action_handler_demo.cpp#L47) the construct of the ActionParamterView Class with a right-value if the action.actionParameters doesn't have any value. At that moment, the class might cause errors like segmentation faults.
So, I offer some suggestions for this part. Here is the current code:
vda5050pp::misc::ActionParameterView params(
action.actionParameters.value_or(std::vector<vda5050::ActionParameter>{}));
I would like to suggest a safer approach to ensure that ActionParameterView always refers to a valid object.
Suggestion #1 (following library style):
if (!action.actionParameters) {
action.actionParamaeters = std::vector<vda5050::ActionParameter>{}
}
vda5050pp::misc::ActionParameterView params(*action.actionParameters);
Suggestion #2 (personal preference):
if (!action.actionParameters.has_value()) {
action.actionParamaeters = std::vector<vda5050::ActionParameter>{}
}
vda5050pp::misc::ActionParameterView params(action.actionParameters.value());
Would you consider updating the example in this way?
Edited by Seungsoo Lee