Add runtime bounds checks to bssl::Span.
Better safe than sorry. Change-Id: Ia99fa59ef1345835e01c330d99707bc8899a33a1 Reviewed-on: https://boringssl-review.googlesource.com/27484 Commit-Queue: Steven Valdez <svaldez@google.com> Reviewed-by: Steven Valdez <svaldez@google.com> CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
parent
9f0e7cb314
commit
68478b7e9b
@ -22,7 +22,6 @@
|
||||
extern "C++" {
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <type_traits>
|
||||
|
||||
@ -136,16 +135,25 @@ class Span : private internal::SpanBase<const T> {
|
||||
const T *cend() const { return end(); };
|
||||
|
||||
T &front() const {
|
||||
assert(size_ != 0);
|
||||
if (size_ == 0) {
|
||||
abort();
|
||||
}
|
||||
return data_[0];
|
||||
}
|
||||
T &back() const {
|
||||
assert(size_ != 0);
|
||||
if (size_ == 0) {
|
||||
abort();
|
||||
}
|
||||
return data_[size_ - 1];
|
||||
}
|
||||
|
||||
T &operator[](size_t i) const { return data_[i]; }
|
||||
T &at(size_t i) const { return data_[i]; }
|
||||
T &operator[](size_t i) const {
|
||||
if (i >= size_) {
|
||||
abort();
|
||||
}
|
||||
return data_[i];
|
||||
}
|
||||
T &at(size_t i) const { return (*this)[i]; }
|
||||
|
||||
Span subspan(size_t pos = 0, size_t len = npos) const {
|
||||
if (pos > size_) {
|
||||
|
Loading…
Reference in New Issue
Block a user