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

Make accessing single elements in empty parameter vectors return an empty optional #693

Merged
merged 3 commits into from
Nov 8, 2024

Conversation

tmadlener
Copy link
Collaborator

BEGINRELEASENOTES

  • Fix small issue in GenericParameters where trying to access a single element of a parameter that was stored as an empty vector resulted in a crash. Instead make this return an empty optional now.

ENDRELEASENOTES

@dirkzerwas this is the fix for the issue in our email discussion.

This seems to be the most reasonable thing to do. The other option would be to return an empty / default constructed value in this case. However, since we introduced the std::optional return type for avoiding exactly that (see #580), I don't think that makes a lot of sense and would make the API inconsistent again.

@tmadlener
Copy link
Collaborator Author

As discussed during the meeting on Nov 5, we will be using an empty optional (as is the current state of this PR at the moment).

@tmadlener tmadlener force-pushed the params-empty-vec-access branch from 40014d0 to 70f63ed Compare November 5, 2024 10:20
Otherwise we run into a read out of bounds in case the parameter is
stored, but with an empty vector value. E.g. from setting it with a
vector that comes from an external source which is empty.
@tmadlener tmadlener force-pushed the params-empty-vec-access branch from 70f63ed to 6c7c090 Compare November 8, 2024 12:18
@tmadlener tmadlener merged commit 706035f into AIDASoft:master Nov 8, 2024
18 checks passed
@tmadlener tmadlener deleted the params-empty-vec-access branch November 8, 2024 13:12
jmcarcell added a commit to jmcarcell/podio that referenced this pull request Nov 18, 2024
…mpty optional (AIDASoft#693)

* Add simple reproducer of previous issue as test

* Return an empty optional in case there are no values

Otherwise we run into a read out of bounds in case the parameter is
stored, but with an empty vector value. E.g. from setting it with a
vector that comes from an external source which is empty.

* Add test for python bindings
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

Successfully merging this pull request may close these issues.

1 participant