Skip to content

Commit

Permalink
Change asserts to use typed exceptions
Browse files Browse the repository at this point in the history
Summary: As title.

Reviewed By: ssj933

Differential Revision: D66473889

fbshipit-source-id: de8800fbba85f0c924904401fcb2eff8268ce040
  • Loading branch information
agampe authored and facebook-github-bot committed Nov 26, 2024
1 parent d04f42b commit 69a3b8b
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions libredex/DexLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ struct AssertHelper {
// Yeah, it's not good form to throw in a destructor. But...
// NOLINTNEXTLINE(bugprone-exception-escape)
~AssertHelper() noexcept(false) {
throw RedexException(
RedexError::INVALID_DEX, message ? *message : std::string(""),
assert_or_throw(
false, RedexError::INVALID_DEX, message ? *message : std::string(""),
extra_info ? *extra_info : std::map<std::string, std::string>());
}

Expand Down Expand Up @@ -88,18 +88,17 @@ void dex_range_assert(uint64_t offset,
const std::string& msg_invalid,
const std::string& msg_invalid_extent,
const std::string& offset_name) {
if (offset >= dexsize) {
throw RedexException(RedexError::INVALID_DEX, msg_invalid,
{{offset_name, std::to_string(offset)},
{"extent", std::to_string(extent)},
{"dex_size", std::to_string(dexsize)}});
}
if (extent > dexsize || offset > dexsize - extent) {
throw RedexException(RedexError::INVALID_DEX, msg_invalid_extent,
{{offset_name, std::to_string(offset)},
{"extent", std::to_string(extent)},
{"dex_size", std::to_string(dexsize)}});
}
assert_or_throw(offset < dexsize, RedexError::INVALID_DEX, msg_invalid,
{{offset_name, std::to_string(offset)},
{"extent", std::to_string(extent)},
{"dex_size", std::to_string(dexsize)}});

assert_or_throw(extent <= dexsize && offset <= dexsize - extent,
RedexError::INVALID_DEX,
msg_invalid_extent,
{{offset_name, std::to_string(offset)},
{"extent", std::to_string(extent)},
{"dex_size", std::to_string(dexsize)}});
}

template <typename T>
Expand Down

0 comments on commit 69a3b8b

Please sign in to comment.