1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:37:46 +00:00

AK/ByteBuffer+Everywhere: Handle errors in ByteBuffer::slice()

This commit is contained in:
Matthias Zimmerman 2022-06-13 05:20:42 -07:00 committed by Linus Groh
parent c0486f93d4
commit c10d48b72c
12 changed files with 45 additions and 34 deletions

View file

@ -69,9 +69,9 @@ static bool test_single(Testcase const& testcase)
// Checking the results:
bool return_ok = actual_return == testcase.src_n;
bool canary_1_ok = actual.slice(0, SANDBOX_CANARY_SIZE) == expected.slice(0, SANDBOX_CANARY_SIZE);
bool main_ok = actual.slice(SANDBOX_CANARY_SIZE, testcase.dest_n) == expected.slice(SANDBOX_CANARY_SIZE, testcase.dest_n);
bool canary_2_ok = actual.slice(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE) == expected.slice(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE);
bool canary_1_ok = MUST(actual.slice(0, SANDBOX_CANARY_SIZE)) == MUST(expected.slice(0, SANDBOX_CANARY_SIZE));
bool main_ok = MUST(actual.slice(SANDBOX_CANARY_SIZE, testcase.dest_n)) == MUST(expected.slice(SANDBOX_CANARY_SIZE, testcase.dest_n));
bool canary_2_ok = MUST(actual.slice(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE)) == MUST(expected.slice(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE));
bool buf_ok = actual == expected;
// Evaluate gravity:
@ -82,20 +82,20 @@ static bool test_single(Testcase const& testcase)
if (!canary_1_ok) {
warnln("Canary 1 overwritten: Expected canary {}\n"
" instead got {}",
show(expected.slice(0, SANDBOX_CANARY_SIZE)),
show(actual.slice(0, SANDBOX_CANARY_SIZE)));
show(MUST(expected.slice(0, SANDBOX_CANARY_SIZE))),
show(MUST(actual.slice(0, SANDBOX_CANARY_SIZE))));
}
if (!main_ok) {
warnln("Wrong output: Expected {}\n"
" instead got {}",
show(expected.slice(SANDBOX_CANARY_SIZE, testcase.dest_n)),
show(actual.slice(SANDBOX_CANARY_SIZE, testcase.dest_n)));
show(MUST(expected.slice(SANDBOX_CANARY_SIZE, testcase.dest_n))),
show(MUST(actual.slice(SANDBOX_CANARY_SIZE, testcase.dest_n))));
}
if (!canary_2_ok) {
warnln("Canary 2 overwritten: Expected {}\n"
" instead got {}",
show(expected.slice(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE)),
show(actual.slice(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE)));
show(MUST(expected.slice(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE))),
show(MUST(actual.slice(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE))));
}
if (!return_ok) {
warnln("Wrong return value: Expected {}, got {} instead!", testcase.src_n, actual_return);