Repository navigation
Fix container type and empty-vector defects in the composite quadratures #105
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,16 +49,13 @@ struct quadrature_traits< | |
| inline static std::tuple<point_container,weight_container> | ||
| generate( range_idx_type idx_range, const Quadrature<DerivedQuad>& quad ) { | ||
| const auto [begin_idx, end_idx] = idx_range; | ||
| assert( begin_idx >= 0 ); | ||
| assert( begin_idx <= quad.npts() ); | ||
| assert( end_idx >= 0 ); | ||
| assert( end_idx <= quad.npts() ); | ||
| assert( begin_idx < end_idx ); | ||
|
|
||
| point_container points( quad.points().begin() + begin_idx, | ||
| quad.points().begin() + end_idx ); | ||
| point_container weights( quad.weights().begin() + begin_idx, | ||
| quad.weights().begin() + end_idx ); | ||
| assert( begin_idx < end_idx ); | ||
| assert( end_idx <= quad.npts() ); | ||
|
|
||
| point_container points ( quad.points().begin() + begin_idx, | ||
| quad.points().begin() + end_idx ); | ||
| weight_container weights( quad.weights().begin() + begin_idx, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing in the suite instantiates
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added as a "Sub Quadratures" case over One correction to the premise, in the good direction: it would not have regressed silently. With master's |
||
| quad.weights().begin() + end_idx ); | ||
|
|
||
| return std::make_tuple( points, weights ); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same default-constructed partition still hits UB through the iterators:
end(),cend()andend() const(lines 141/148/155) computepartition_idx_.end()-1, which on an empty vector steps beforebegin(). With-D_GLIBCXX_DEBUGon this head,RadialGridPartition<LebedevLaikov<double>>{}.end()aborts with "attempt to retreat a past-the-end iterator". Since this PR is about the empty-vector cases, could those be made safe here too? AREQUIRE_THROWSnext to the default-constructedrgpintest/composite_quadratures.cxx:202would also pin the newfinalize()behaviour.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, and the iterators were the live path. Fixed in 7ab221b:
end(),cend()andend() constpresent an empty range whenpartition_idx_is empty instead of computingend()-1. I reproduced your abort first —-D_GLIBCXX_DEBUGon master gives "attempt to retreat a past-the-end iterator" fromRadialGridPartition<LebedevLaikov<double>>{}.end(), and the patched version reports an empty range.The new "Unfinalized Partition" section pins
REQUIRE_THROWS( rgp.finalize(r) )together withbegin() == end()for all three overloads.