Don't compare iterators from potentially different containers

This patch addresses a static analysis issue reported by Cppcheck 2.9
where an assertion in the toml/region.hpp header would compare two
container's (that are known to be of type std::vector<char>) begin() and
end() iterators in order to verify that they are the same.  This
assertion either passes or invokes undefined behavior.  Which isn't
technically wrong because calling code must always ensure that
preconditions are met and assertions therefore pass anyway but it does
make the value that is added by having the assertion in the first place
marginal.  Fortunately, the assertion was easy to rewrite: Just compare
the container's address itself.  This is well-defined regardless of
whether the assertion will pass or fail.
This commit is contained in:
Moritz Klammler
2022-09-14 18:55:57 +02:00
parent 79c125b54f
commit 8bb2c63a01

View File

@@ -227,8 +227,7 @@ struct region final : public region_base
region& operator+=(const region& other)
{
// different regions cannot be concatenated
assert(this->begin() == other.begin() && this->end() == other.end() &&
this->last_ == other.first_);
assert(this->source_ == other.source_ && this->last_ == other.first_);
this->last_ = other.last_;
return *this;