BIND 10 trac1774, updated. 3dab9ab4947300e8d5b9cf8d4544d9491c65038c [1774] Added NameOffsets typedef
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Jun 28 02:43:59 UTC 2012
The branch, trac1774 has been updated
via 3dab9ab4947300e8d5b9cf8d4544d9491c65038c (commit)
via 8acfde4201f10d86ee53d2c60701b222896fe088 (commit)
via b574c191d04f51d21c97979546c5641582d1bdf5 (commit)
from 24c9af463a1087f54918f6e1206f72b50b43d9bf (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 3dab9ab4947300e8d5b9cf8d4544d9491c65038c
Author: Mukund Sivaraman <muks at isc.org>
Date: Thu Jun 28 08:09:01 2012 +0530
[1774] Added NameOffsets typedef
commit 8acfde4201f10d86ee53d2c60701b222896fe088
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Thu Jun 28 08:04:39 2012 +0530
[1774] Use uint8_t for name offsets
commit b574c191d04f51d21c97979546c5641582d1bdf5
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Thu Jun 28 08:00:54 2012 +0530
[1774] Use a wrapper to convert string literals to uint8_t*
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/name.cc | 8 ++++----
src/lib/dns/name.h | 4 +++-
src/lib/dns/tests/labelsequence_unittest.cc | 19 ++++++++++++++++---
3 files changed, 23 insertions(+), 8 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/name.cc b/src/lib/dns/name.cc
index 0a92d29..5630435 100644
--- a/src/lib/dns/name.cc
+++ b/src/lib/dns/name.cc
@@ -147,7 +147,7 @@ Name::Name(const std::string &namestring, bool downcase) {
bool is_root = false;
ft_state state = ft_init;
- std::vector<unsigned char> offsets;
+ NameOffsets offsets;
offsets.reserve(Name::MAX_LABELS);
offsets.push_back(0);
@@ -310,7 +310,7 @@ typedef enum {
}
Name::Name(InputBuffer& buffer, bool downcase) {
- std::vector<unsigned char> offsets;
+ NameOffsets offsets;
offsets.reserve(Name::MAX_LABELS);
/*
@@ -663,8 +663,8 @@ Name::reverse() const {
retname.ndata_.reserve(length_);
// Copy the original name, label by label, from tail to head.
- vector<unsigned char>::const_reverse_iterator rit0 = offsets_.rbegin();
- vector<unsigned char>::const_reverse_iterator rit1 = rit0 + 1;
+ NameOffsets::const_reverse_iterator rit0 = offsets_.rbegin();
+ NameOffsets::const_reverse_iterator rit1 = rit0 + 1;
NameString::const_iterator n0 = ndata_.begin();
retname.offsets_.push_back(0);
while (rit1 != offsets_.rend()) {
diff --git a/src/lib/dns/name.h b/src/lib/dns/name.h
index 84c243a..41024fc 100644
--- a/src/lib/dns/name.h
+++ b/src/lib/dns/name.h
@@ -231,6 +231,8 @@ class Name {
private:
/// \brief Name data string
typedef std::basic_string<uint8_t> NameString;
+ /// \brief Name offsets type
+ typedef std::vector<uint8_t> NameOffsets;
/// The default constructor
///
@@ -683,7 +685,7 @@ public:
private:
NameString ndata_;
- std::vector<unsigned char> offsets_;
+ NameOffsets offsets_;
unsigned int length_;
unsigned int labelcount_;
};
diff --git a/src/lib/dns/tests/labelsequence_unittest.cc b/src/lib/dns/tests/labelsequence_unittest.cc
index 6452e84..0e1fd5e 100644
--- a/src/lib/dns/tests/labelsequence_unittest.cc
+++ b/src/lib/dns/tests/labelsequence_unittest.cc
@@ -143,7 +143,7 @@ TEST_F(LabelSequenceTest, equals_insensitive) {
}
void
-getDataCheck(const char* expected_data, size_t expected_len,
+getDataCheck(const uint8_t* expected_data, size_t expected_len,
const LabelSequence& ls)
{
size_t len;
@@ -154,12 +154,25 @@ getDataCheck(const char* expected_data, size_t expected_len,
"Expected data: " << expected_data <<
" name: " << ls.getName().toText();
for (size_t i = 0; i < len; ++i) {
- EXPECT_EQ(static_cast<const uint8_t>(expected_data[i]), data[i]) <<
+ EXPECT_EQ(expected_data[i], data[i]) <<
"Difference at pos " << i << ": Expected data: " << expected_data <<
" name: " << ls.getName().toText();;
}
}
+// Convenient data converter for expected data. Label data must be of
+// uint8_t*, while it's convenient if we can specify some test data in
+// plain string (which is of char*). This wrapper converts the latter to
+// the former in a safer way.
+void
+getDataCheck(const char* expected_char_data, size_t expected_len,
+ const LabelSequence& ls)
+{
+ const vector<uint8_t> expected_data(expected_char_data,
+ expected_char_data + expected_len);
+ getDataCheck(&expected_data[0], expected_len, ls);
+}
+
TEST_F(LabelSequenceTest, getData) {
getDataCheck("\007example\003org\000", 13, ls1);
getDataCheck("\007example\003com\000", 13, ls2);
@@ -259,7 +272,7 @@ TEST_F(LabelSequenceTest, comparePart) {
// Data comparison
size_t len;
const uint8_t* data = ls1.getData(&len);
- getDataCheck((const char*) data, len, ls8);
+ getDataCheck(data, len, ls8);
}
TEST_F(LabelSequenceTest, isAbsolute) {
More information about the bind10-changes
mailing list