From 8bb2c63a0184496f0fa44d852396ef7dc954d4d9 Mon Sep 17 00:00:00 2001 From: Moritz Klammler Date: Wed, 14 Sep 2022 18:55:57 +0200 Subject: [PATCH] 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) 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. --- toml/region.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/toml/region.hpp b/toml/region.hpp index 2e01e51..8c4f2f1 100644 --- a/toml/region.hpp +++ b/toml/region.hpp @@ -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;