From 9163073ca120478733602d42e344f14c241ad2d1 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Thu, 28 Feb 2008 21:11:39 +0000 Subject: [PATCH] Fix for JSON Protocol string-reading methods. Clear return-by-reference strings before appending to them in the JSON Protocol reading methods. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665533 13f79535-47bb-0310-9956-ffa450edef68 --- lib/cpp/src/protocol/TJSONProtocol.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/cpp/src/protocol/TJSONProtocol.cpp b/lib/cpp/src/protocol/TJSONProtocol.cpp index 0f3b102d..39eb1290 100644 --- a/lib/cpp/src/protocol/TJSONProtocol.cpp +++ b/lib/cpp/src/protocol/TJSONProtocol.cpp @@ -669,6 +669,7 @@ uint32_t TJSONProtocol::readJSONString(std::string &str, bool skipContext) { uint32_t result = (skipContext ? 0 : context_->read(reader_)); result += readJSONSyntaxChar(kJSONStringDelimiter); uint8_t ch; + str.clear(); while (true) { ch = reader_.read(); ++result; @@ -702,6 +703,7 @@ uint32_t TJSONProtocol::readJSONBase64(std::string &str) { uint32_t result = readJSONString(tmp); uint8_t *b = (uint8_t *)tmp.c_str(); uint32_t len = tmp.length(); + str.clear(); while (len >= 4) { base64_decode(b, 4); str.append((const char *)b, 3); @@ -721,6 +723,7 @@ uint32_t TJSONProtocol::readJSONBase64(std::string &str) { // a valid JSON numeric character. uint32_t TJSONProtocol::readJSONNumericChars(std::string &str) { uint32_t result = 0; + str.clear(); while (true) { uint8_t ch = reader_.peek(); if (!isJSONNumeric(ch)) { -- 2.17.1