1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 16:27:35 +00:00

Everywhere: Rename ASSERT => VERIFY

(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
This commit is contained in:
Andreas Kling 2021-02-23 20:42:32 +01:00
parent b33a6a443e
commit 5d180d1f99
725 changed files with 3448 additions and 3448 deletions

View file

@ -62,7 +62,7 @@ ByteBuffer decode_pem(ReadonlyBytes data)
lexer.consume_all();
break;
default:
ASSERT_NOT_REACHED();
VERIFY_NOT_REACHED();
}
}

View file

@ -40,7 +40,7 @@ size_t SignedBigInteger::export_data(Bytes data, bool remove_leading_zeros) cons
{
// FIXME: Support this:
// m <0XX> -> m <XX> (if remove_leading_zeros)
ASSERT(!remove_leading_zeros);
VERIFY(!remove_leading_zeros);
data[0] = m_sign;
auto bytes_view = data.slice(1, data.size() - 1);

View file

@ -106,7 +106,7 @@ String UnsignedBigInteger::to_base10() const
while (temp != UnsignedBigInteger { 0 }) {
divide_u16_without_allocation(temp, 10, quotient, remainder);
ASSERT(remainder.words()[0] < 10);
VERIFY(remainder.words()[0] < 10);
builder.append(static_cast<char>(remainder.words()[0] + '0'));
temp.set_to(quotient);
}
@ -389,7 +389,7 @@ void UnsignedBigInteger::subtract_without_allocation(
}
// This assertion should not fail, because we verified that *this>=other at the beginning of the function
ASSERT(borrow == 0);
VERIFY(borrow == 0);
}
/**
@ -672,7 +672,7 @@ FLATTEN void UnsignedBigInteger::divide_u16_without_allocation(
UnsignedBigInteger& quotient,
UnsignedBigInteger& remainder)
{
ASSERT(denominator < (1 << 16));
VERIFY(denominator < (1 << 16));
u32 remainder_word = 0;
auto numerator_length = numerator.trimmed_length();
quotient.set_to_0();
@ -717,8 +717,8 @@ ALWAYS_INLINE u32 UnsignedBigInteger::shift_left_get_one_word(
{
// "<= length()" (rather than length() - 1) is intentional,
// The result inedx of length() is used when calculating the carry word
ASSERT(result_word_index <= number.length());
ASSERT(num_bits <= UnsignedBigInteger::BITS_IN_WORD);
VERIFY(result_word_index <= number.length());
VERIFY(num_bits <= UnsignedBigInteger::BITS_IN_WORD);
u32 result = 0;
// we need to check for "num_bits != 0" since shifting right by 32 is apparently undefined behaviour!

View file

@ -65,9 +65,9 @@ void AESCipherKey::expand_encrypt_key(ReadonlyBytes user_key, size_t bits)
u32 temp;
size_t i { 0 };
ASSERT(!user_key.is_null());
ASSERT(is_valid_key_size(bits));
ASSERT(user_key.size() == bits / 8);
VERIFY(!user_key.is_null());
VERIFY(is_valid_key_size(bits));
VERIFY(user_key.size() == bits / 8);
round_key = round_keys();
@ -401,7 +401,7 @@ void AESCipherBlock::overwrite(ReadonlyBytes bytes)
auto data = bytes.data();
auto length = bytes.size();
ASSERT(length <= this->data_size());
VERIFY(length <= this->data_size());
this->bytes().overwrite(0, data, length);
if (length < this->data_size()) {
switch (padding_mode()) {
@ -419,7 +419,7 @@ void AESCipherBlock::overwrite(ReadonlyBytes bytes)
break;
default:
// FIXME: We should handle the rest of the common padding modes
ASSERT_NOT_REACHED();
VERIFY_NOT_REACHED();
break;
}
}

View file

@ -59,7 +59,7 @@ public:
{
}
static size_t block_size() { ASSERT_NOT_REACHED(); }
static size_t block_size() { VERIFY_NOT_REACHED(); }
virtual ReadonlyBytes bytes() const = 0;
@ -74,11 +74,11 @@ public:
template<typename T>
void put(size_t offset, T value)
{
ASSERT(offset + sizeof(T) <= bytes().size());
VERIFY(offset + sizeof(T) <= bytes().size());
auto* ptr = bytes().offset_pointer(offset);
auto index { 0 };
ASSERT(sizeof(T) <= 4);
VERIFY(sizeof(T) <= 4);
if constexpr (sizeof(T) > 3)
ptr[index++] = (u8)(value >> 24);

View file

@ -66,7 +66,7 @@ public:
// FIXME: We should have two of these encrypt/decrypt functions that
// we SFINAE out based on whether the Cipher mode needs an ivec
ASSERT(!ivec.is_empty());
VERIFY(!ivec.is_empty());
const auto* iv = ivec.data();
m_cipher_block.set_padding_mode(cipher.padding_mode());
@ -77,7 +77,7 @@ public:
m_cipher_block.overwrite(in.slice(offset, block_size));
m_cipher_block.apply_initialization_vector(iv);
cipher.encrypt_block(m_cipher_block, m_cipher_block);
ASSERT(offset + block_size <= out.size());
VERIFY(offset + block_size <= out.size());
__builtin_memcpy(out.offset(offset), m_cipher_block.bytes().data(), block_size);
iv = out.offset(offset);
length -= block_size;
@ -88,7 +88,7 @@ public:
m_cipher_block.overwrite(in.slice(offset, length));
m_cipher_block.apply_initialization_vector(iv);
cipher.encrypt_block(m_cipher_block, m_cipher_block);
ASSERT(offset + block_size <= out.size());
VERIFY(offset + block_size <= out.size());
__builtin_memcpy(out.offset(offset), m_cipher_block.bytes().data(), block_size);
iv = out.offset(offset);
}
@ -105,14 +105,14 @@ public:
auto& cipher = this->cipher();
ASSERT(!ivec.is_empty());
VERIFY(!ivec.is_empty());
const auto* iv = ivec.data();
auto block_size = cipher.block_size();
// if the data is not aligned, it's not correct encrypted data
// FIXME (ponder): Should we simply decrypt as much as we can?
ASSERT(length % block_size == 0);
VERIFY(length % block_size == 0);
m_cipher_block.set_padding_mode(cipher.padding_mode());
size_t offset { 0 };
@ -123,7 +123,7 @@ public:
cipher.decrypt_block(m_cipher_block, m_cipher_block);
m_cipher_block.apply_initialization_vector(iv);
auto decrypted = m_cipher_block.bytes();
ASSERT(offset + decrypted.size() <= out.size());
VERIFY(offset + decrypted.size() <= out.size());
__builtin_memcpy(out.offset(offset), decrypted.data(), decrypted.size());
iv = slice;
length -= block_size;

View file

@ -160,7 +160,7 @@ protected:
{
size_t length;
if (in) {
ASSERT(in->size() <= out.size());
VERIFY(in->size() <= out.size());
length = in->size();
if (length == 0)
return;
@ -172,8 +172,8 @@ protected:
// FIXME: We should have two of these encrypt/decrypt functions that
// we SFINAE out based on whether the Cipher mode needs an ivec
ASSERT(!ivec.is_empty());
ASSERT(ivec.size() >= IV_length());
VERIFY(!ivec.is_empty());
VERIFY(ivec.size() >= IV_length());
m_cipher_block.set_padding_mode(cipher.padding_mode());
@ -192,7 +192,7 @@ protected:
}
auto write_size = min(block_size, length);
ASSERT(offset + write_size <= out.size());
VERIFY(offset + write_size <= out.size());
__builtin_memcpy(out.offset(offset), m_cipher_block.bytes().data(), write_size);
increment(iv);

View file

@ -73,7 +73,7 @@ public:
// FIXME: This overload throws away the auth stuff, think up a better way to return more than a single bytebuffer.
virtual void encrypt(ReadonlyBytes in, Bytes& out, ReadonlyBytes ivec = {}, Bytes* = nullptr) override
{
ASSERT(!ivec.is_empty());
VERIFY(!ivec.is_empty());
static ByteBuffer dummy;

View file

@ -98,7 +98,7 @@ protected:
}
default:
// FIXME: support other padding modes
ASSERT_NOT_REACHED();
VERIFY_NOT_REACHED();
break;
}
}

View file

@ -85,7 +85,7 @@ struct MultiHashDigestVariant {
return sha512.value().immutable_data();
default:
case HashKind::None:
ASSERT_NOT_REACHED();
VERIFY_NOT_REACHED();
break;
}
}
@ -103,7 +103,7 @@ struct MultiHashDigestVariant {
return sha512.value().data_length();
default:
case HashKind::None:
ASSERT_NOT_REACHED();
VERIFY_NOT_REACHED();
break;
}
}
@ -179,7 +179,7 @@ public:
inline void initialize(HashKind kind)
{
if (m_kind != HashKind::None) {
ASSERT_NOT_REACHED();
VERIFY_NOT_REACHED();
}
m_kind = kind;
@ -248,7 +248,7 @@ public:
return { m_sha512->peek() };
default:
case HashKind::None:
ASSERT_NOT_REACHED();
VERIFY_NOT_REACHED();
break;
}
}

View file

@ -88,7 +88,7 @@ void MD5::update(const u8* input, size_t length)
index = 0;
}
ASSERT(length < part_length || length - offset <= 64);
VERIFY(length < part_length || length - offset <= 64);
m_buffer.overwrite(index, &input[offset], length - offset);
}
MD5::DigestType MD5::digest()

View file

@ -240,7 +240,7 @@ static bool MR_primality_test(UnsignedBigInteger n, const Vector<UnsignedBigInte
{
// Written using Wikipedia:
// https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test#Miller%E2%80%93Rabin_test
ASSERT(!(n < 4));
VERIFY(!(n < 4));
auto predecessor = n.minus({ 1 });
auto d = predecessor;
size_t r = 0;
@ -259,8 +259,8 @@ static bool MR_primality_test(UnsignedBigInteger n, const Vector<UnsignedBigInte
}
for (auto& a : tests) {
// Technically: ASSERT(2 <= a && a <= n - 2)
ASSERT(a < n);
// Technically: VERIFY(2 <= a && a <= n - 2)
VERIFY(a < n);
auto x = ModularPower(a, d, n);
if (x == 1 || x == predecessor)
continue;
@ -283,13 +283,13 @@ static bool MR_primality_test(UnsignedBigInteger n, const Vector<UnsignedBigInte
UnsignedBigInteger random_number(const UnsignedBigInteger& min, const UnsignedBigInteger& max_excluded)
{
ASSERT(min < max_excluded);
VERIFY(min < max_excluded);
auto range = max_excluded.minus(min);
UnsignedBigInteger base;
auto size = range.trimmed_length() * sizeof(u32) + 2;
// "+2" is intentional (see below).
// Also, if we're about to crash anyway, at least produce a nice error:
ASSERT(size < 8 * MiB);
VERIFY(size < 8 * MiB);
u8 buf[size];
AK::fill_with_random(buf, size);
UnsignedBigInteger random { buf, size };
@ -340,7 +340,7 @@ bool is_probably_prime(const UnsignedBigInteger& p)
UnsignedBigInteger random_big_prime(size_t bits)
{
ASSERT(bits >= 33);
VERIFY(bits >= 33);
UnsignedBigInteger min = UnsignedBigInteger::from_base10("6074001000").shift_left(bits - 33);
UnsignedBigInteger max = UnsignedBigInteger { 1 }.shift_left(bits).minus(1);
for (;;) {

View file

@ -286,7 +286,7 @@ void RSA::import_private_key(ReadonlyBytes bytes, bool pem)
auto key = parse_rsa_key(bytes);
if (!key.private_key.length()) {
dbgln("We expected to see a private key, but we found none");
ASSERT_NOT_REACHED();
VERIFY_NOT_REACHED();
}
m_private_key = key.private_key;
}
@ -302,7 +302,7 @@ void RSA::import_public_key(ReadonlyBytes bytes, bool pem)
auto key = parse_rsa_key(bytes);
if (!key.public_key.length()) {
dbgln("We expected to see a public key, but we found none");
ASSERT_NOT_REACHED();
VERIFY_NOT_REACHED();
}
m_public_key = key.public_key;
}
@ -356,7 +356,7 @@ void RSA_PKCS1_EME::encrypt(ReadonlyBytes in, Bytes& out)
u8 ps[ps_length];
// FIXME: Without this assertion, GCC refuses to compile due to a memcpy overflow(!?)
ASSERT(ps_length < 16384);
VERIFY(ps_length < 16384);
AK::fill_with_random(ps, ps_length);
// since arc4random can create zeros (shocking!)