1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:37:44 +00:00

AK: Remove Optional::operator bool()

This was causing some obvious-in-hindsight but hard to spot bugs where
we'd implicitly convert the bool to an integer type and carry on with
the number 1 instead of the actual value().
This commit is contained in:
Andreas Kling 2020-03-06 10:26:05 +01:00
parent ae233c1e82
commit 8bb361889c
6 changed files with 9 additions and 12 deletions

View file

@ -1076,9 +1076,9 @@ Ext2FS::BlockIndex Ext2FS::allocate_block(GroupIndex preferred_group_index)
auto block_bitmap = Bitmap::wrap(cached_bitmap.buffer.data(), blocks_in_group);
BlockIndex first_block_in_group = (group_index - 1) * blocks_per_group() + first_block_index();
int first_unset_bit_index = block_bitmap.find_first_unset();
ASSERT(first_unset_bit_index != -1);
BlockIndex block_index = (unsigned)first_unset_bit_index + first_block_in_group;
auto first_unset_bit_index = block_bitmap.find_first_unset();
ASSERT(first_unset_bit_index.has_value());
BlockIndex block_index = first_unset_bit_index.value() + first_block_in_group;
set_block_allocation_state(block_index, true);
return block_index;
}

View file

@ -1228,7 +1228,7 @@ ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
if (!description) {
generated_data = (*read_callback)(identifier());
} else {
if (!description->generator_cache())
if (!description->generator_cache().has_value())
description->generator_cache() = (*read_callback)(identifier());
generated_data = description->generator_cache();
}
@ -1242,7 +1242,7 @@ ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
ssize_t nread = min(static_cast<off_t>(data.value().size() - offset), static_cast<off_t>(count));
memcpy(buffer, data.value().data() + offset, nread);
if (nread == 0 && description && description->generator_cache())
if (nread == 0 && description && description->generator_cache().has_value())
description->generator_cache().clear();
return nread;