Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 22, 2024
1 parent e9e36a7 commit 1db9890
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 16 deletions.
23 changes: 14 additions & 9 deletions include/xrpl/beast/utility/instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,27 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

#define ASSERT ALWAYS_OR_UNREACHABLE

// How to use the above macros:
// How to use the instrumentation macros:
//
// ALWAYS if it must be reached during fuzzing
// ASSERT if you expect that it might, or might not, be reached during fuzzing
// REACHABLE if it must be reached during fuzzing
// SOMETIMES a hint for the fuzzer to try to make the condition true
// UNREACHABLE if it must not be reached (in fuzzing or in normal use)
// ALWAYS if cond must be true and the line must be reached during fuzzing
// ASSERT if cond must be true but the line might not be reached during fuzzing
// REACHABLE if the line must be reached during fuzzing
// SOMETIMES a hint for the fuzzer to try to make the cond true
// UNREACHABLE if the line must not be reached (in fuzzing or in normal use)
//
// NOTE: ASSERT has similar semantics as assert macro, with minor differences:
// NOTE: ASSERT has similar semantics as C assert macro, with minor differences:
// * ASSERT must have an unique name (naming convention in CONTRIBUTING.md)
// * the condition (which comes first) must be *implicitly* convertible to bool
// * during fuzzing, the program will continue execution past a failed ASSERT
// We continue to use assert inside unit tests and in constexpr functions.
//
// We continue to use regular C assert inside unit tests and inside constexpr
// functions.
//
// NOTE: UNREACHABLE does *not* have the same semantics as std::unreachable.
// The program will continue execution past an UNREACHABLE in a Release build
// and during fuzzing (similar to ASSERT).
// and during fuzzing (similar to ASSERT). Also the naming convention is subtly
// different from all other macros - name in UNREACHABLE describes the condition
// which was meant to never happen, while name in other macros describe the
// condition that is meant to happen (e.g. as in "assert that this happens").

#endif
3 changes: 3 additions & 0 deletions src/libxrpl/basics/contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ LogicError(std::string const& s) noexcept
{
JLOG(debugLog().fatal()) << s;
std::cerr << "Logic error: " << s << std::endl;
// Use a non-standard contract naming here (without namespace), because
// it's the only location where various unrelated execution paths may
// register an error; this is also why "message" parameter is passed here.
UNREACHABLE("LogicError", {{"message", s}});

Check warning on line 55 in src/libxrpl/basics/contract.cpp

View check run for this annotation

Codecov / codecov/patch

src/libxrpl/basics/contract.cpp#L55

Added line #L55 was not covered by tests
detail::accessViolation();
}
Expand Down
2 changes: 1 addition & 1 deletion src/libxrpl/json/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Array::append(Json::Value const& v)
return;
}
}
UNREACHABLE("Json::Array::append : invalid type");
UNREACHABLE("Json::Array::append : invalid type");

Check warning on line 171 in src/libxrpl/json/Object.cpp

View check run for this annotation

Codecov / codecov/patch

src/libxrpl/json/Object.cpp#L171

Added line #L171 was not covered by tests
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/libxrpl/json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ operator>>(std::istream& sin, Value& root)
Json::Reader reader;
bool ok = reader.parse(sin, root);

// ASSERT( ok );
// ASSERT(ok, "Json::operator>>() : parse succeeded");
if (!ok)
ripple::Throw<std::runtime_error>(reader.getFormatedErrorMessages());

Expand Down
2 changes: 1 addition & 1 deletion src/libxrpl/protocol/Indexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ line(
// There is code in SetTrust that calls us with id0 == id1, to allow users
// to locate and delete such "weird" trustlines. If we remove that code, we
// could enable this assert:
// ASSERT(id0 != id1);
// ASSERT(id0 != id1, "ripple::keylet::line : accounts must be different");

// A trust line is shared between two accounts; while we typically think
// of this as an "issuer" and a "holder" the relationship is actually fully
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/paths/detail/StrandFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ flow(
// running debug builds of rippled. While this issue still needs to
// be resolved, the assert is causing more harm than good at this
// point.
// UNREACHABLE();
// UNREACHABLE("ripple::flow : rounding error");

return {tefEXCEPTION, std::move(ofrsToRmOnFail)};
}
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/tx/detail/OfferStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ TOfferStreamBase<TIn, TOut>::step()
}
UNREACHABLE(

Check warning on line 343 in src/xrpld/app/tx/detail/OfferStream.cpp

View check run for this annotation

Codecov / codecov/patch

src/xrpld/app/tx/detail/OfferStream.cpp#L343

Added line #L343 was not covered by tests
"rippls::TOfferStreamBase::step::rmSmallIncreasedQOffer : XRP "
"vs XRP offer"); // xrp/xrp offer!?! should never happen
"vs XRP offer");
return false;
}();

Expand Down
3 changes: 1 addition & 2 deletions src/xrpld/app/tx/detail/SetSignerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ SetSignerList::doApply()
default:
break;
}
UNREACHABLE(
"ripple::SetSignerList::doApply : invalid operation");
UNREACHABLE("ripple::SetSignerList::doApply : invalid operation");

Check warning on line 131 in src/xrpld/app/tx/detail/SetSignerList.cpp

View check run for this annotation

Codecov / codecov/patch

src/xrpld/app/tx/detail/SetSignerList.cpp#L131

Added line #L131 was not covered by tests
return temMALFORMED;
}

Expand Down

0 comments on commit 1db9890

Please sign in to comment.