mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:57:35 +00:00
AK: Make Vector use size_t for its size and capacity
This commit is contained in:
parent
9c6f7d3e7d
commit
ceec1a7d38
94 changed files with 323 additions and 317 deletions
|
@ -668,15 +668,15 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
|
|||
|
||||
const int block_size = fs().block_size();
|
||||
|
||||
int first_block_logical_index = offset / block_size;
|
||||
int last_block_logical_index = (offset + count) / block_size;
|
||||
size_t first_block_logical_index = offset / block_size;
|
||||
size_t last_block_logical_index = (offset + count) / block_size;
|
||||
if (last_block_logical_index >= m_block_list.size())
|
||||
last_block_logical_index = m_block_list.size() - 1;
|
||||
|
||||
int offset_into_first_block = offset % block_size;
|
||||
|
||||
ssize_t nread = 0;
|
||||
int remaining_count = min((off_t)count, (off_t)size() - offset);
|
||||
size_t remaining_count = min((off_t)count, (off_t)size() - offset);
|
||||
u8* out = buffer;
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
|
@ -685,7 +685,7 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
|
|||
|
||||
u8 block[max_block_size];
|
||||
|
||||
for (int bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
|
||||
for (size_t bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
|
||||
auto block_index = m_block_list[bi];
|
||||
ASSERT(block_index);
|
||||
bool success = fs().read_block(block_index, block, description);
|
||||
|
@ -694,8 +694,8 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
int offset_into_block = (bi == first_block_logical_index) ? offset_into_first_block : 0;
|
||||
int num_bytes_to_copy = min(block_size - offset_into_block, remaining_count);
|
||||
size_t offset_into_block = (bi == first_block_logical_index) ? offset_into_first_block : 0;
|
||||
size_t num_bytes_to_copy = min(block_size - offset_into_block, remaining_count);
|
||||
memcpy(out, block + offset_into_block, num_bytes_to_copy);
|
||||
remaining_count -= num_bytes_to_copy;
|
||||
nread += num_bytes_to_copy;
|
||||
|
@ -712,8 +712,8 @@ KResult Ext2FSInode::resize(u64 new_size)
|
|||
return KSuccess;
|
||||
|
||||
u64 block_size = fs().block_size();
|
||||
int blocks_needed_before = ceil_div(old_size, block_size);
|
||||
int blocks_needed_after = ceil_div(new_size, block_size);
|
||||
size_t blocks_needed_before = ceil_div(old_size, block_size);
|
||||
size_t blocks_needed_after = ceil_div(new_size, block_size);
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
dbgprintf("Ext2FSInode::resize(): blocks needed before (size was %Q): %d\n", old_size, blocks_needed_before);
|
||||
|
@ -777,7 +777,7 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const u8* data, Fi
|
|||
}
|
||||
}
|
||||
|
||||
const ssize_t block_size = fs().block_size();
|
||||
const size_t block_size = fs().block_size();
|
||||
u64 old_size = size();
|
||||
u64 new_size = max(static_cast<u64>(offset) + count, (u64)size());
|
||||
|
||||
|
@ -793,17 +793,17 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const u8* data, Fi
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
int first_block_logical_index = offset / block_size;
|
||||
int last_block_logical_index = (offset + count) / block_size;
|
||||
size_t first_block_logical_index = offset / block_size;
|
||||
size_t last_block_logical_index = (offset + count) / block_size;
|
||||
if (last_block_logical_index >= m_block_list.size())
|
||||
last_block_logical_index = m_block_list.size() - 1;
|
||||
|
||||
int offset_into_first_block = offset % block_size;
|
||||
size_t offset_into_first_block = offset % block_size;
|
||||
|
||||
int last_logical_block_index_in_file = new_size / block_size;
|
||||
size_t last_logical_block_index_in_file = new_size / block_size;
|
||||
|
||||
ssize_t nwritten = 0;
|
||||
int remaining_count = min((off_t)count, (off_t)new_size - offset);
|
||||
size_t remaining_count = min((off_t)count, (off_t)new_size - offset);
|
||||
const u8* in = data;
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
|
@ -811,9 +811,9 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const u8* data, Fi
|
|||
#endif
|
||||
|
||||
auto buffer_block = ByteBuffer::create_uninitialized(block_size);
|
||||
for (int bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
|
||||
int offset_into_block = (bi == first_block_logical_index) ? offset_into_first_block : 0;
|
||||
int num_bytes_to_copy = min(block_size - offset_into_block, remaining_count);
|
||||
for (size_t bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
|
||||
size_t offset_into_block = (bi == first_block_logical_index) ? offset_into_first_block : 0;
|
||||
size_t num_bytes_to_copy = min(block_size - offset_into_block, remaining_count);
|
||||
|
||||
ByteBuffer block;
|
||||
if (offset_into_block != 0 || num_bytes_to_copy != block_size) {
|
||||
|
@ -828,8 +828,8 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const u8* data, Fi
|
|||
|
||||
memcpy(block.data() + offset_into_block, in, num_bytes_to_copy);
|
||||
if (bi == last_logical_block_index_in_file && num_bytes_to_copy < block_size) {
|
||||
int padding_start = new_size % block_size;
|
||||
int padding_bytes = block_size - padding_start;
|
||||
size_t padding_start = new_size % block_size;
|
||||
size_t padding_bytes = block_size - padding_start;
|
||||
#ifdef EXT2_DEBUG
|
||||
dbg() << "Ext2FS: Padding last block of file with zero x " << padding_bytes << " (new_size=" << new_size << ", offset_into_block=" << offset_into_block << ", num_bytes_to_copy=" << num_bytes_to_copy << ")";
|
||||
#endif
|
||||
|
@ -905,7 +905,7 @@ bool Ext2FSInode::write_directory(const Vector<FS::DirectoryEntry>& entries)
|
|||
auto directory_data = ByteBuffer::create_uninitialized(occupied_size);
|
||||
|
||||
BufferStream stream(directory_data);
|
||||
for (int i = 0; i < entries.size(); ++i) {
|
||||
for (size_t i = 0; i < entries.size(); ++i) {
|
||||
auto& entry = entries[i];
|
||||
|
||||
int record_length = EXT2_DIR_REC_LEN(entry.name_length);
|
||||
|
@ -1087,7 +1087,7 @@ Ext2FS::BlockIndex Ext2FS::allocate_block(GroupIndex preferred_group_index)
|
|||
return block_index;
|
||||
}
|
||||
|
||||
Vector<Ext2FS::BlockIndex> Ext2FS::allocate_blocks(GroupIndex preferred_group_index, int count)
|
||||
Vector<Ext2FS::BlockIndex> Ext2FS::allocate_blocks(GroupIndex preferred_group_index, size_t count)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
#ifdef EXT2_DEBUG
|
||||
|
@ -1424,7 +1424,7 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FS::create_inode(InodeIdentifier parent_id,
|
|||
dbgprintf("Ext2FS: Adding inode '%s' (mode %o) to parent directory %u:\n", name.characters(), mode, parent_inode->identifier().index());
|
||||
#endif
|
||||
|
||||
auto needed_blocks = ceil_div(size, block_size());
|
||||
size_t needed_blocks = ceil_div(size, block_size());
|
||||
if ((size_t)needed_blocks > super_block().s_free_blocks_count) {
|
||||
dbg() << "Ext2FS: create_inode: not enough free blocks";
|
||||
return KResult(-ENOSPC);
|
||||
|
|
|
@ -135,7 +135,7 @@ private:
|
|||
|
||||
BlockIndex first_block_index() const;
|
||||
InodeIndex find_a_free_inode(GroupIndex preferred_group, off_t expected_size);
|
||||
Vector<BlockIndex> allocate_blocks(GroupIndex preferred_group_index, int count);
|
||||
Vector<BlockIndex> allocate_blocks(GroupIndex preferred_group_index, size_t count);
|
||||
BlockIndex allocate_block(GroupIndex preferred_group_index);
|
||||
GroupIndex group_index_from_inode(InodeIndex) const;
|
||||
GroupIndex group_index_from_block_index(BlockIndex) const;
|
||||
|
|
|
@ -145,7 +145,7 @@ static inline int to_fd(const InodeIdentifier& identifier)
|
|||
return (identifier.index() & 0xff) - FI_MaxStaticFileIndex;
|
||||
}
|
||||
|
||||
static inline int to_sys_index(const InodeIdentifier& identifier)
|
||||
static inline size_t to_sys_index(const InodeIdentifier& identifier)
|
||||
{
|
||||
ASSERT(to_proc_parent_directory(identifier) == PDI_Root_sys);
|
||||
ASSERT(to_proc_file_type(identifier) == FI_Root_sys_variable);
|
||||
|
@ -1271,7 +1271,7 @@ bool ProcFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)
|
|||
break;
|
||||
|
||||
case FI_Root_sys:
|
||||
for (int i = 1; i < sys_variables().size(); ++i) {
|
||||
for (size_t i = 1; i < sys_variables().size(); ++i) {
|
||||
auto& variable = sys_variables()[i];
|
||||
callback({ variable.name.characters(), variable.name.length(), sys_var_to_identifier(fsid(), i), 0 });
|
||||
}
|
||||
|
@ -1356,7 +1356,7 @@ RefPtr<Inode> ProcFSInode::lookup(StringView name)
|
|||
}
|
||||
|
||||
if (proc_file_type == FI_Root_sys) {
|
||||
for (int i = 1; i < sys_variables().size(); ++i) {
|
||||
for (size_t i = 1; i < sys_variables().size(); ++i) {
|
||||
auto& variable = sys_variables()[i];
|
||||
if (name == variable.name)
|
||||
return fs().get_inode(sys_var_to_identifier(fsid(), i));
|
||||
|
|
|
@ -93,7 +93,7 @@ KResult VFS::unmount(InodeIdentifier guest_inode_id)
|
|||
LOCKER(m_lock);
|
||||
dbg() << "VFS: unmount called with inode " << guest_inode_id;
|
||||
|
||||
for (int i = 0; i < m_mounts.size(); ++i) {
|
||||
for (size_t i = 0; i < m_mounts.size(); ++i) {
|
||||
auto& mount = m_mounts.at(i);
|
||||
if (mount.guest() == guest_inode_id) {
|
||||
auto result = mount.guest_fs().prepare_to_unmount();
|
||||
|
@ -788,7 +788,7 @@ KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path(StringView path, Custody& ba
|
|||
|
||||
NonnullRefPtr<Custody> custody = path[0] == '/' ? current_root : base;
|
||||
|
||||
for (int i = 0; i < parts.size(); ++i) {
|
||||
for (size_t i = 0; i < parts.size(); ++i) {
|
||||
Custody& parent = custody;
|
||||
auto parent_metadata = parent.inode().metadata();
|
||||
if (!parent_metadata.is_directory())
|
||||
|
|
|
@ -128,7 +128,7 @@ KResult IPv4Socket::bind(const sockaddr* user_address, socklen_t address_size)
|
|||
return protocol_bind();
|
||||
}
|
||||
|
||||
KResult IPv4Socket::listen(int backlog)
|
||||
KResult IPv4Socket::listen(size_t backlog)
|
||||
{
|
||||
int rc = allocate_local_port_if_needed();
|
||||
if (rc < 0)
|
||||
|
@ -138,7 +138,7 @@ KResult IPv4Socket::listen(int backlog)
|
|||
m_role = Role::Listener;
|
||||
|
||||
#ifdef IPV4_SOCKET_DEBUG
|
||||
kprintf("IPv4Socket{%p} listening with backlog=%d\n", this, backlog);
|
||||
kprintf("IPv4Socket{%p} listening with backlog=%zu\n", this, backlog);
|
||||
#endif
|
||||
|
||||
return protocol_listen();
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
virtual void close() override;
|
||||
virtual KResult bind(const sockaddr*, socklen_t) override;
|
||||
virtual KResult connect(FileDescription&, const sockaddr*, socklen_t, ShouldBlock = ShouldBlock::Yes) override;
|
||||
virtual KResult listen(int) override;
|
||||
virtual KResult listen(size_t) override;
|
||||
virtual void get_local_address(sockaddr*, socklen_t*) override;
|
||||
virtual void get_peer_address(sockaddr*, socklen_t*) override;
|
||||
virtual void attach(FileDescription&) override;
|
||||
|
|
|
@ -192,7 +192,7 @@ KResult LocalSocket::connect(FileDescription& description, const sockaddr* addre
|
|||
return KSuccess;
|
||||
}
|
||||
|
||||
KResult LocalSocket::listen(int backlog)
|
||||
KResult LocalSocket::listen(size_t backlog)
|
||||
{
|
||||
LOCKER(lock());
|
||||
if (type() != SOCK_STREAM)
|
||||
|
@ -200,7 +200,7 @@ KResult LocalSocket::listen(int backlog)
|
|||
set_backlog(backlog);
|
||||
m_connect_side_role = m_role = Role::Listener;
|
||||
#ifdef DEBUG_LOCAL_SOCKET
|
||||
kprintf("LocalSocket{%p} listening with backlog=%d\n", this, backlog);
|
||||
kprintf("LocalSocket{%p} listening with backlog=%zu\n", this, backlog);
|
||||
#endif
|
||||
return KSuccess;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
// ^Socket
|
||||
virtual KResult bind(const sockaddr*, socklen_t) override;
|
||||
virtual KResult connect(FileDescription&, const sockaddr*, socklen_t, ShouldBlock = ShouldBlock::Yes) override;
|
||||
virtual KResult listen(int) override;
|
||||
virtual KResult listen(size_t) override;
|
||||
virtual void get_local_address(sockaddr*, socklen_t*) override;
|
||||
virtual void get_peer_address(sockaddr*, socklen_t*) override;
|
||||
virtual void attach(FileDescription&) override;
|
||||
|
|
|
@ -99,7 +99,7 @@ public:
|
|||
|
||||
virtual KResult bind(const sockaddr*, socklen_t) = 0;
|
||||
virtual KResult connect(FileDescription&, const sockaddr*, socklen_t, ShouldBlock) = 0;
|
||||
virtual KResult listen(int) = 0;
|
||||
virtual KResult listen(size_t) = 0;
|
||||
virtual void get_local_address(sockaddr*, socklen_t*) = 0;
|
||||
virtual void get_peer_address(sockaddr*, socklen_t*) = 0;
|
||||
virtual bool is_local() const { return false; }
|
||||
|
@ -138,8 +138,8 @@ protected:
|
|||
|
||||
KResult queue_connection_from(NonnullRefPtr<Socket>);
|
||||
|
||||
int backlog() const { return m_backlog; }
|
||||
void set_backlog(int backlog) { m_backlog = backlog; }
|
||||
size_t backlog() const { return m_backlog; }
|
||||
void set_backlog(size_t backlog) { m_backlog = backlog; }
|
||||
|
||||
virtual const char* class_name() const override { return "Socket"; }
|
||||
|
||||
|
@ -160,7 +160,7 @@ private:
|
|||
int m_domain { 0 };
|
||||
int m_type { 0 };
|
||||
int m_protocol { 0 };
|
||||
int m_backlog { 0 };
|
||||
size_t m_backlog { 0 };
|
||||
SetupState m_setup_state { SetupState::Unstarted };
|
||||
bool m_connected { false };
|
||||
bool m_shut_down_for_reading { false };
|
||||
|
|
|
@ -255,7 +255,7 @@ bool Process::deallocate_region(Region& region)
|
|||
InterruptDisabler disabler;
|
||||
if (m_region_lookup_cache.region == ®ion)
|
||||
m_region_lookup_cache.region = nullptr;
|
||||
for (int i = 0; i < m_regions.size(); ++i) {
|
||||
for (size_t i = 0; i < m_regions.size(); ++i) {
|
||||
if (&m_regions[i] == ®ion) {
|
||||
m_regions.unstable_remove(i);
|
||||
return true;
|
||||
|
@ -956,7 +956,7 @@ int Process::do_exec(NonnullRefPtr<FileDescription> main_program_description, Ve
|
|||
|
||||
disown_all_shared_buffers();
|
||||
|
||||
for (int i = 0; i < m_fds.size(); ++i) {
|
||||
for (size_t i = 0; i < m_fds.size(); ++i) {
|
||||
auto& daf = m_fds[i];
|
||||
if (daf.description && daf.flags & FD_CLOEXEC) {
|
||||
daf.description->close();
|
||||
|
@ -1522,7 +1522,7 @@ RefPtr<FileDescription> Process::file_description(int fd) const
|
|||
{
|
||||
if (fd < 0)
|
||||
return nullptr;
|
||||
if (fd < m_fds.size())
|
||||
if (static_cast<size_t>(fd) < m_fds.size())
|
||||
return m_fds[fd].description.ptr();
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -1531,7 +1531,7 @@ int Process::fd_flags(int fd) const
|
|||
{
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
if (fd < m_fds.size())
|
||||
if (static_cast<size_t>(fd) < m_fds.size())
|
||||
return m_fds[fd].flags;
|
||||
return -1;
|
||||
}
|
||||
|
@ -3189,6 +3189,8 @@ int Process::sys$bind(int sockfd, const sockaddr* address, socklen_t address_len
|
|||
|
||||
int Process::sys$listen(int sockfd, int backlog)
|
||||
{
|
||||
if (backlog < 0)
|
||||
return -EINVAL;
|
||||
auto description = file_description(sockfd);
|
||||
if (!description)
|
||||
return -EBADF;
|
||||
|
@ -4761,7 +4763,7 @@ int Process::sys$unveil(const Syscall::SC_unveil_params* user_params)
|
|||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_unveiled_paths.size(); ++i) {
|
||||
for (size_t i = 0; i < m_unveiled_paths.size(); ++i) {
|
||||
auto& unveiled_path = m_unveiled_paths[i];
|
||||
if (unveiled_path.path == path.value()) {
|
||||
if (new_permissions & ~unveiled_path.permissions)
|
||||
|
|
|
@ -122,7 +122,7 @@ void SharedBuffer::share_with(pid_t peer_pid)
|
|||
void SharedBuffer::deref_for_process(Process& process)
|
||||
{
|
||||
LOCKER(shared_buffers().lock());
|
||||
for (int i = 0; i < m_refs.size(); ++i) {
|
||||
for (size_t i = 0; i < m_refs.size(); ++i) {
|
||||
auto& ref = m_refs[i];
|
||||
if (ref.pid == process.pid()) {
|
||||
ref.count--;
|
||||
|
@ -150,7 +150,7 @@ void SharedBuffer::deref_for_process(Process& process)
|
|||
void SharedBuffer::disown(pid_t pid)
|
||||
{
|
||||
LOCKER(shared_buffers().lock());
|
||||
for (int i = 0; i < m_refs.size(); ++i) {
|
||||
for (size_t i = 0; i < m_refs.size(); ++i) {
|
||||
auto& ref = m_refs[i];
|
||||
if (ref.pid == pid) {
|
||||
#ifdef SHARED_BUFFER_DEBUG
|
||||
|
|
|
@ -644,7 +644,7 @@ u32 Thread::make_userspace_stack_for_main_thread(Vector<String> arguments, Vecto
|
|||
|
||||
SmapDisabler disabler;
|
||||
|
||||
for (int i = 0; i < arguments.size(); ++i) {
|
||||
for (size_t i = 0; i < arguments.size(); ++i) {
|
||||
argv[i] = bufptr;
|
||||
memcpy(bufptr, arguments[i].characters(), arguments[i].length());
|
||||
bufptr += arguments[i].length();
|
||||
|
@ -652,7 +652,7 @@ u32 Thread::make_userspace_stack_for_main_thread(Vector<String> arguments, Vecto
|
|||
}
|
||||
argv[arguments.size()] = nullptr;
|
||||
|
||||
for (int i = 0; i < environment.size(); ++i) {
|
||||
for (size_t i = 0; i < environment.size(); ++i) {
|
||||
env[i] = bufptr;
|
||||
memcpy(bufptr, environment[i].characters(), environment[i].length());
|
||||
bufptr += environment[i].length();
|
||||
|
|
|
@ -108,7 +108,7 @@ Range RangeAllocator::allocate_anywhere(size_t size, size_t alignment)
|
|||
size_t offset_from_effective_base = 0;
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < m_available_ranges.size(); ++i) {
|
||||
for (size_t i = 0; i < m_available_ranges.size(); ++i) {
|
||||
auto& available_range = m_available_ranges[i];
|
||||
// FIXME: This check is probably excluding some valid candidates when using a large alignment.
|
||||
if (available_range.size() < (effective_size + alignment))
|
||||
|
@ -142,7 +142,7 @@ Range RangeAllocator::allocate_specific(VirtualAddress base, size_t size)
|
|||
return {};
|
||||
|
||||
Range allocated_range(base, size);
|
||||
for (int i = 0; i < m_available_ranges.size(); ++i) {
|
||||
for (size_t i = 0; i < m_available_ranges.size(); ++i) {
|
||||
auto& available_range = m_available_ranges[i];
|
||||
if (!available_range.contains(base, size))
|
||||
continue;
|
||||
|
@ -181,7 +181,7 @@ void RangeAllocator::deallocate(Range range)
|
|||
},
|
||||
&nearby_index);
|
||||
|
||||
int inserted_index = 0;
|
||||
size_t inserted_index = 0;
|
||||
if (existing_range) {
|
||||
existing_range->m_size += range.size();
|
||||
inserted_index = nearby_index;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue