Commit 231bbc39 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

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)


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1664 e5f2f494-b856-4b98-b285-d166d9295462
parent d30412f4
......@@ -703,40 +703,16 @@ decode_real(std::stringstream& in, int& item_length UNUSED_PARAM) {
}
ElementPtr
decode_blob(std::stringstream& in, int& item_length) {
char *buf = new char[item_length + 1];
decode_blob(std::stringstream& in, const int item_length) {
vector<char> buf(item_length + 1);
in.read(buf, item_length);
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 @@ decode_element(std::stringstream& in, int& in_length) {
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);
......
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