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

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Mar 31 18:41:05 UTC 2010


Author: jinmei
Date: Wed Mar 31 18:41:04 2010
New Revision: 1664

Log:
made deocde_blob() exception safe.
additional cleanups:
- unify decode_blob() and decode_utf() since these two are identical.
  moved the XXX comment to the caller side.
- costified the length argument to decode_blob(); it doesn't have to be
  adjusted.
- removed an unnecessary temporary variable (it didn't seem to improve
  readability)

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 Wed Mar 31 18:41:04 2010
@@ -703,40 +703,16 @@
 }
 
 ElementPtr
-decode_blob(std::stringstream& in, int& item_length) {
-    char *buf = new char[item_length + 1];
-
-    in.read(buf, item_length);
+decode_blob(std::stringstream& in, const int item_length) {
+    vector<char> buf(item_length + 1);
+
+    in.read(&buf[0], item_length);
     if (in.fail()) {
-        delete[] buf;
         throw DecodeError();
     }
     buf[item_length] = 0;
 
-    std::string s = std::string(buf, item_length);
-    item_length -= item_length;
-
-    delete [] buf;
-    return Element::create(s);
-}
-
-// XXXMLG currently identical to decode_blob
-ElementPtr
-decode_utf8(std::stringstream& in, int& item_length) {
-    char *buf = new char[item_length + 1];
-
-    in.read(buf, item_length);
-    if (in.fail()) {
-        delete[] buf;
-        throw DecodeError();
-    }
-    buf[item_length] = 0;
-
-    std::string s = std::string(buf, item_length);
-    item_length -= item_length;
-
-    delete [] buf;
-    return Element::create(s);
+    return Element::create(std::string(&buf[0], item_length));
 }
 
 ElementPtr
@@ -810,7 +786,8 @@
         element = decode_blob(in, item_length);
         break;
     case ITEM_UTF8:
-        element = decode_utf8(in, item_length);
+        // XXXMLG currently identical to decode_blob
+        element = decode_blob(in, item_length);
         break;
     case ITEM_HASH:
         element = decode_hash(in, item_length);




More information about the bind10-changes mailing list