Commit f9d9fccd authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

make sure stringbuf::pubseekpos(0) is performed before checking in_avail()


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1405 e5f2f494-b856-4b98-b285-d166d9295462
parent 461d4abe
...@@ -18,9 +18,10 @@ ...@@ -18,9 +18,10 @@
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
#include <string>
#include <sstream> #include <sstream>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp> // for iequals
using namespace std; using namespace std;
using namespace isc::data; using namespace isc::data;
...@@ -841,6 +842,7 @@ ListElement::toWire(std::stringstream& ss, int omit_length) ...@@ -841,6 +842,7 @@ ListElement::toWire(std::stringstream& ss, int omit_length)
if (omit_length) { if (omit_length) {
stringbuf *ss2_buf = ss2.rdbuf(); stringbuf *ss2_buf = ss2.rdbuf();
ss2_buf->pubseekpos(0);
if (ss2_buf->in_avail() > 0) { if (ss2_buf->in_avail() > 0) {
ss << ss2_buf; ss << ss2_buf;
} }
...@@ -867,7 +869,6 @@ void ...@@ -867,7 +869,6 @@ void
MapElement::toWire(std::stringstream& ss, int omit_length) MapElement::toWire(std::stringstream& ss, int omit_length)
{ {
std::stringstream ss2; std::stringstream ss2;
std::map<std::string, ElementPtr> m;
// //
// If we don't want the length, we will want the protocol header // If we don't want the length, we will want the protocol header
...@@ -877,8 +878,8 @@ MapElement::toWire(std::stringstream& ss, int omit_length) ...@@ -877,8 +878,8 @@ MapElement::toWire(std::stringstream& ss, int omit_length)
ss2 << PROTOCOL_VERSION[2] << PROTOCOL_VERSION[3]; ss2 << PROTOCOL_VERSION[2] << PROTOCOL_VERSION[3];
} }
m = mapValue(); const std::map<std::string, ElementPtr>& m = mapValue();
for (std::map<std::string, ElementPtr>::iterator it = m.begin() ; for (std::map<std::string, ElementPtr>::const_iterator it = m.begin() ;
it != m.end() ; ++it) { it != m.end() ; ++it) {
encode_tag(ss2, (*it).first); encode_tag(ss2, (*it).first);
(*it).second->toWire(ss2, 0); (*it).second->toWire(ss2, 0);
...@@ -889,14 +890,15 @@ MapElement::toWire(std::stringstream& ss, int omit_length) ...@@ -889,14 +890,15 @@ MapElement::toWire(std::stringstream& ss, int omit_length)
// //
if (omit_length) { if (omit_length) {
stringbuf *ss2_buf = ss2.rdbuf(); stringbuf *ss2_buf = ss2.rdbuf();
if (ss2_buf->in_avail() > 0) { ss2_buf->pubseekpos(0);
if (ss2_buf->in_avail()) {
ss << ss2_buf; ss << ss2_buf;
} }
} else { } else {
stringbuf *ss2_buf = ss2.rdbuf(); stringbuf *ss2_buf = ss2.rdbuf();
ss2_buf->pubseekpos(0); ss2_buf->pubseekpos(0);
ss << encode_length(ss2_buf->in_avail(), ITEM_HASH); ss << encode_length(ss2_buf->in_avail(), ITEM_HASH);
if (ss2_buf->in_avail() > 0) { if (ss2_buf->in_avail()) {
ss << ss2_buf; ss << ss2_buf;
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment