From 97face1527989f59479ab61d47bb13765257bf8a Mon Sep 17 00:00:00 2001 From: Alex Ames Date: Fri, 20 Oct 2017 16:49:15 -0700 Subject: [PATCH] Changed how vector_data works. (#4467) In some debug environments using vector[i] does bounds checking even though the standard specifies that it should not. Using *(vector.begin()) sidesteps this though, giving the same result without the bounds checking. --- include/flatbuffers/stl_emulation.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/flatbuffers/stl_emulation.h b/include/flatbuffers/stl_emulation.h index 16d35f2e9..2a6fbb76b 100644 --- a/include/flatbuffers/stl_emulation.h +++ b/include/flatbuffers/stl_emulation.h @@ -41,12 +41,14 @@ inline char string_back(const std::string &value) { // Helper method that retrieves ::data() from a vector in a way that is // compatible with pre C++11 STLs (e.g stlport). template inline T *vector_data(std::vector &vector) { - return &(vector[0]); + // In some debug environments, operator[] does bounds checking, so &vector[0] + // can't be used. + return &(*vector.begin()); } template inline const T *vector_data( const std::vector &vector) { - return &(vector[0]); + return &(*vector.begin()); } template