produce valid bencoded strings for undefined/uninitialized entry objects (#756)

This commit is contained in:
Arvid Norberg 2016-05-26 03:33:05 -04:00
parent 98eabc63e9
commit d0a870b3dd
2 changed files with 19 additions and 3 deletions

View File

@ -215,9 +215,12 @@ namespace libtorrent
ret += e.preformatted().size();
break;
case entry::undefined_t:
// trying to encode a structure with uninitialized values!
// TORRENT_ASSERT_VAL(false, e.type());
// do nothing
// empty string
write_char(out, '0');
write_char(out, ':');
ret += 2;
break;
}
return ret;

View File

@ -121,6 +121,19 @@ TORRENT_TEST(preformatted_node)
TEST_EQUAL(encode(e), "d4:infofoobare");
}
TORRENT_TEST(undefined_node)
{
entry e(entry::undefined_t);
TEST_EQUAL(encode(e), "0:");
}
TORRENT_TEST(undefined_node2)
{
entry e(entry::dictionary_t);
e["info"] = entry(entry::undefined_t);
TEST_EQUAL(encode(e), "d4:info0:e");
}
#ifndef TORRENT_NO_DEPRECATE
TORRENT_TEST(lazy_entry)
{