[svn] commit: r1405 - /trunk/src/lib/cc/data.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Mar 15 04:52:16 UTC 2010


Author: jinmei
Date: Mon Mar 15 04:52:16 2010
New Revision: 1405

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

Modified:
    trunk/src/lib/cc/data.cc

Modified: trunk/src/lib/cc/data.cc
==============================================================================
--- trunk/src/lib/cc/data.cc (original)
+++ trunk/src/lib/cc/data.cc Mon Mar 15 04:52:16 2010
@@ -18,9 +18,10 @@
 
 #include <cstdio>
 #include <iostream>
+#include <string>
 #include <sstream>
 
-#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string.hpp> // for iequals
 
 using namespace std;
 using namespace isc::data;
@@ -841,6 +842,7 @@
 
     if (omit_length) {
         stringbuf *ss2_buf = ss2.rdbuf();
+        ss2_buf->pubseekpos(0);
         if (ss2_buf->in_avail() > 0) {
             ss << ss2_buf;
         }
@@ -867,7 +869,6 @@
 MapElement::toWire(std::stringstream& ss, int omit_length)
 {
     std::stringstream ss2;
-    std::map<std::string, ElementPtr> m;
 
     //
     // If we don't want the length, we will want the protocol header
@@ -877,8 +878,8 @@
         ss2 << PROTOCOL_VERSION[2] << PROTOCOL_VERSION[3];
     }
 
-    m = mapValue();
-    for (std::map<std::string, ElementPtr>::iterator it = m.begin() ;
+    const std::map<std::string, ElementPtr>& m = mapValue();
+    for (std::map<std::string, ElementPtr>::const_iterator it = m.begin() ;
          it != m.end() ; ++it) {
         encode_tag(ss2, (*it).first);
         (*it).second->toWire(ss2, 0);
@@ -889,14 +890,15 @@
     //
     if (omit_length) {
         stringbuf *ss2_buf = ss2.rdbuf();
-        if (ss2_buf->in_avail() > 0) {
+        ss2_buf->pubseekpos(0);
+        if (ss2_buf->in_avail()) {
             ss << ss2_buf;
         }
     } else {
         stringbuf *ss2_buf = ss2.rdbuf();
         ss2_buf->pubseekpos(0);
         ss << encode_length(ss2_buf->in_avail(), ITEM_HASH);
-        if (ss2_buf->in_avail() > 0) {
+        if (ss2_buf->in_avail()) {
             ss << ss2_buf;
         }
     }




More information about the bind10-changes mailing list