Repository navigation
Harden stl_emulation span assignment, make_span deduction, and bounds safety - #9349
Open
anagnorisis2peripeteia wants to merge 1 commit into
Conversation
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.
Description
This change hardens the STL emulation utility header (
include/flatbuffers/stl_emulation.h):flatbuffers::span,data_was declaredpointer const data_, making copy assignment ill-formed when instantiated. Furthermore,operator=was missing a return statement (return *this;). Fixeddata_to be non-const so the span view is rebindable (matching C++20std::span) and addedreturn *this;.Extenttemplate parameter from the pointer overloads ofmake_span(first, count), allowing caller template argument deduction without requiring manual instantiation of<ElementType, Extent>.FLATBUFFERS_ASSERT(idx < size())inspan::operator[]to catch out-of-bounds accesses.FLATBUFFERS_ASSERT(has_value())inOptional::operator*()to guard against dereferencing an empty optional.Testing
StlEmulationSafetyTestintests/test.cppverifying span copy-assignment rebinding,make_spantemplate deduction on mutable and const pointers, and optional value access.flattestspass.