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