mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-19 11:28:11 +08:00
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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user