From 9202f0cf09b80e356a6b468e280b2fb0f10d2871 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 27 Nov 2015 20:05:48 +0000 Subject: [PATCH 1/2] Return the full string when requested from a flatbuffers::String, even if it contains a NULL byte. --- include/flatbuffers/flatbuffers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index a728a79cf..c2b938d36 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -379,7 +379,7 @@ template static inline size_t VectorLength(const Vector *v) { struct String : public Vector { const char *c_str() const { return reinterpret_cast(Data()); } - std::string str() const { return c_str(); } + std::string str() const { return std::string(c_str(), Length()); } bool operator <(const String &o) const { return strcmp(c_str(), o.c_str()) < 0; From 345e8ca804265640f12e4edd93fb9d752aed9cf8 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 27 Nov 2015 20:06:41 +0000 Subject: [PATCH 2/2] Fix use of std::max when Windows.h is imported. --- include/flatbuffers/flatbuffers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index c2b938d36..2af4486c7 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -445,7 +445,7 @@ class vector_downward { if (len > static_cast(cur_ - buf_)) { auto old_size = size(); auto largest_align = AlignOf(); - reserved_ += std::max(len, growth_policy(reserved_)); + reserved_ += (std::max)(len, growth_policy(reserved_)); // Round up to avoid undefined behavior from unaligned loads and stores. reserved_ = (reserved_ + (largest_align - 1)) & ~(largest_align - 1); auto new_buf = allocator_.allocate(reserved_);