factor out error handling in lazy_bdecode

This commit is contained in:
Arvid Norberg 2014-05-04 20:47:16 +00:00
parent f015c0604a
commit e0e5a55f10
1 changed files with 22 additions and 13 deletions

View File

@ -44,20 +44,29 @@ namespace
namespace libtorrent namespace libtorrent
{ {
#define TORRENT_FAIL_BDECODE(code) \ namespace
{ \ {
ec = make_error_code(code); \ int fail(int* error_pos
while (!stack.empty()) { \ , std::vector<lazy_entry*>& stack
top = stack.back(); \ , char const* start
if (top->type() == lazy_entry::dict_t || top->type() == lazy_entry::list_t) { \ , char const* orig_start)
top->pop(); \ {
break; \ while (!stack.empty()) {
} \ lazy_entry* top = stack.back();
stack.pop_back(); \ if (top->type() == lazy_entry::dict_t || top->type() == lazy_entry::list_t)
} \ {
if (error_pos) *error_pos = start - orig_start; \ top->pop();
return -1; \ break;
}
stack.pop_back();
}
if (error_pos) *error_pos = start - orig_start;
return -1;
}
} }
#define TORRENT_FAIL_BDECODE(code) do { ec = make_error_code(code); return fail(error_pos, stack, start, orig_start); } while (false)
namespace { bool numeric(char c) { return c >= '0' && c <= '9'; } } namespace { bool numeric(char c) { return c >= '0' && c <= '9'; } }
// fills in 'val' with what the string between start and the // fills in 'val' with what the string between start and the