Repository navigation
Conversation
Containers accept fewer indices than dimensions (the missing leading ones are 0) or more (the extra leading ones are ignored). concatenate_access computed the offset into the index range as distance(first, last) - dimension() in size_t. With fewer indices this wrapped around, so concatenate and hstack read before the start of the index array: c(1) returned garbage for a 2-D concatenation and hstack crashed. stack_access ignored the index count entirely, so stack and 1-D vstack returned wrong values with both fewer and more indices. Both access methods now go through detail::trailing_index, which aligns the indices on the last dimensions like containers do. It also converts the index values explicitly: flat_expression_adaptor passes the signed indices returned by unravel_index, which are never negative. This removes the -Wsign-conversion warnings in xbuilder.hpp. The new test fails on master and passes with ASan and UBSan.
4 tasks done
Contributor
Merging this PR will not alter performance1 warning
Comparing |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
Description
Like containers, builder expressions should accept fewer indices than dimensions (missing leading indices are 0) or more (extra leading ones are ignored). They did not:
concatenate_accesscomputeddistance(first, last) - dimension()instd::size_t, which wraps around when there are fewer indices than dimensions:concatenatereturned garbage andhstackcrashed with a segmentation fault.stack_accessignored the number of indices, sostackand 1-Dvstackreturned wrong values in both directions.Both now go through a
detail::trailing_indexhelper that aligns the indices on the last dimensions, as containers do. This also removes the-Wsign-conversionwarnings inxbuilder.hpp.xbuilder.concatenate_stack_index_countchecksconcatenate,hstack,stackandvstackwith fewer and more indices against the evaluated result. It fails on master and passes with the fix, also under AddressSanitizer and UBSan.