From 39eaf766fa3d48e7e6489fd52cbee6c796ff6432 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 20 Apr 2008 03:18:49 +0000 Subject: [PATCH] lazy_bdecode fixes --- include/libtorrent/lazy_entry.hpp | 7 ++++--- src/lazy_bdecode.cpp | 17 +++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/libtorrent/lazy_entry.hpp b/include/libtorrent/lazy_entry.hpp index 5d4eedf06..7a8827887 100644 --- a/include/libtorrent/lazy_entry.hpp +++ b/include/libtorrent/lazy_entry.hpp @@ -125,11 +125,12 @@ namespace libtorrent lazy_entry const* dict_find_dict(char const* name) const; lazy_entry const* dict_find_list(char const* name) const; - std::pair dict_at(int i) const + std::pair dict_at(int i) const { TORRENT_ASSERT(m_type == dict_t); TORRENT_ASSERT(i < m_size); - return std::make_pair(m_data.dict[i].first, &m_data.dict[i].second); + std::pair const& e = m_data.dict[i]; + return std::make_pair(std::string(e.first, e.second.m_begin - e.first), &e.second); } int dict_size() const @@ -183,7 +184,7 @@ namespace libtorrent // returns pointers into the source buffer where // this entry has its bencoded data - std::pair data_section(); + std::pair data_section() const; private: diff --git a/src/lazy_bdecode.cpp b/src/lazy_bdecode.cpp index b5e2b11e7..74b2ed638 100644 --- a/src/lazy_bdecode.cpp +++ b/src/lazy_bdecode.cpp @@ -237,7 +237,7 @@ namespace libtorrent ++str2; --len2; } - return true; + return *str1 == 0; } } @@ -334,7 +334,7 @@ namespace libtorrent m_type = none_t; } - std::pair lazy_entry::data_section() + std::pair lazy_entry::data_section() const { typedef std::pair return_t; return return_t(m_begin, m_end - m_begin); @@ -357,10 +357,11 @@ namespace libtorrent printable = false; break; } - if (printable) return os << e.string_value(); + os << "'"; + if (printable) return os << e.string_value() << "'"; for (int i = 0; i < e.string_length(); ++i) os << std::hex << int((unsigned char)(str[i])); - return os; + return os << "'"; } case lazy_entry::list_t: { @@ -368,7 +369,7 @@ namespace libtorrent bool one_liner = (e.list_size() == 0 || e.list_at(0)->type() == lazy_entry::int_t || (e.list_at(0)->type() == lazy_entry::string_t - && e.list_at(0)->string_length() < 5)) + && e.list_at(0)->string_length() < 10)) && e.list_size() < 5; if (!one_liner) os << "\n"; for (int i = 0; i < e.list_size(); ++i) @@ -386,15 +387,15 @@ namespace libtorrent bool one_liner = (e.dict_size() == 0 || e.dict_at(0).second->type() == lazy_entry::int_t || (e.dict_at(0).second->type() == lazy_entry::string_t - && e.dict_at(0).second->string_length() < 4) - || strlen(e.dict_at(0).first) < 10) + && e.dict_at(0).second->string_length() < 10) + || e.dict_at(0).first.size() < 10) && e.dict_size() < 5; if (!one_liner) os << "\n"; for (int i = 0; i < e.dict_size(); ++i) { if (i == 0 && one_liner) os << " "; - std::pair ent = e.dict_at(i); + std::pair ent = e.dict_at(i); os << "'" << ent.first << "': " << *ent.second; if (i < e.dict_size() - 1) os << (one_liner?", ":",\n"); else os << (one_liner?" ":"\n");