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