|
|
ade8bb |
From c6755a399e8a31cbee5129dde5124f9c54a47ab6 Mon Sep 17 00:00:00 2001
|
|
|
ade8bb |
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
|
|
|
ade8bb |
Date: Wed, 4 Apr 2018 14:58:03 +0200
|
|
|
ade8bb |
Subject: [PATCH] Do not call back() on an empty vector
|
|
|
ade8bb |
MIME-Version: 1.0
|
|
|
ade8bb |
Content-Type: text/plain; charset=UTF-8
|
|
|
ade8bb |
Content-Transfer-Encoding: 8bit
|
|
|
ade8bb |
|
|
|
ade8bb |
Calling std::vector::back() on an empty container is undefined.
|
|
|
ade8bb |
Avoid doing that, simply return pointer to the beginning in case
|
|
|
ade8bb |
the vector is empty.
|
|
|
ade8bb |
|
|
|
ade8bb |
Signed-off-by: Nikola Forró <nforro@redhat.com>
|
|
|
ade8bb |
---
|
|
|
ade8bb |
common/vector.hpp | 6 +++---
|
|
|
ade8bb |
1 file changed, 3 insertions(+), 3 deletions(-)
|
|
|
ade8bb |
|
|
|
ade8bb |
diff --git a/common/vector.hpp b/common/vector.hpp
|
|
|
ade8bb |
index 782e4b0..cb344bd 100644
|
|
|
ade8bb |
--- a/common/vector.hpp
|
|
|
ade8bb |
+++ b/common/vector.hpp
|
|
|
ade8bb |
@@ -36,13 +36,13 @@ namespace acommon
|
|
|
ade8bb |
}
|
|
|
ade8bb |
T * data() {return &*this->begin();}
|
|
|
ade8bb |
T * data(int pos) {return &*this->begin() + pos;}
|
|
|
ade8bb |
- T * data_end() {return &this->back()+1;}
|
|
|
ade8bb |
+ T * data_end() {return this->empty() ? &*this->begin() : &this->back()+1;}
|
|
|
ade8bb |
|
|
|
ade8bb |
T * pbegin() {return &*this->begin();}
|
|
|
ade8bb |
- T * pend() {return &this->back()+1;}
|
|
|
ade8bb |
+ T * pend() {return this->empty() ? &*this->begin() : &this->back()+1;}
|
|
|
ade8bb |
|
|
|
ade8bb |
const T * pbegin() const {return &*this->begin();}
|
|
|
ade8bb |
- const T * pend() const {return &this->back()+1;}
|
|
|
ade8bb |
+ const T * pend() const {return this->empty() ? &*this->begin() : &this->back()+1;}
|
|
|
ade8bb |
|
|
|
ade8bb |
template <typename U>
|
|
|
ade8bb |
U * datap() {
|