From c074f47f4e25f15c42b3a96f93cde1e3dbcfb0d2 Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Mon, 14 Mar 2016 12:12:54 +0100 Subject: [PATCH] Port a velocypack fix. --- 3rdParty/velocypack/src/Builder.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/3rdParty/velocypack/src/Builder.cpp b/3rdParty/velocypack/src/Builder.cpp index 707aed2a60..77e2636fed 100644 --- a/3rdParty/velocypack/src/Builder.cpp +++ b/3rdParty/velocypack/src/Builder.cpp @@ -423,7 +423,7 @@ Slice Builder::getKey(std::string const& key) const { } uint8_t* Builder::set(Value const& item) { - auto const oldPos = _start + _pos; + auto const oldPos = _pos; auto ctype = item.cType(); checkKeyIsString(item.valueType() == ValueType::String); @@ -668,7 +668,7 @@ uint8_t* Builder::set(Value const& item) { "Cannot set a ValueType::Custom with this method"); } } - return oldPos; + return _start + oldPos; } uint8_t* Builder::set(Slice const& item) { @@ -687,6 +687,8 @@ uint8_t* Builder::set(ValuePair const& pair) { // ValueType::Binary, or ValueType::Custom, which can be built // with two pieces of information + auto const oldPos = _pos; + checkKeyIsString(pair.valueType() == ValueType::String); if (pair.valueType() == ValueType::Binary) { @@ -694,7 +696,7 @@ uint8_t* Builder::set(ValuePair const& pair) { appendUInt(v, 0xbf); memcpy(_start + _pos, pair.getStart(), checkOverflow(v)); _pos += v; - return nullptr; // unused here + return _start + oldPos; } else if (pair.valueType() == ValueType::String) { uint64_t size = pair.getSize(); if (size > 126) { @@ -802,12 +804,13 @@ uint8_t* Builder::add(ObjectIterator&& sub) { if (_keyWritten) { throw Exception(Exception::BuilderKeyAlreadyWritten); } - auto const oldPos = _start + _pos; + auto const oldPos = _pos; while (sub.valid()) { - add(sub.key().copyString(), sub.value()); + add(sub.key()); + add(sub.value()); sub.next(); } - return oldPos; + return _start + oldPos; } uint8_t* Builder::add(Value const& sub) { return addInternal(sub); } @@ -832,12 +835,12 @@ uint8_t* Builder::add(ArrayIterator&& sub) { if (_start[tos] != 0x06 && _start[tos] != 0x13) { throw Exception(Exception::BuilderNeedOpenArray); } - auto const oldPos = _start + _pos; + auto const oldPos = _pos; while (sub.valid()) { add(sub.value()); sub.next(); } - return oldPos; + return _start + oldPos; } static_assert(sizeof(double) == 8, "double is not 8 bytes");