From 88b9fcb9764bba777fe18bb28114a3743bb971a4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 20 Feb 2020 12:54:15 +0100 Subject: AK: Use size_t for ByteBuffer sizes This matches what we already do for string types. --- Kernel/FileSystem/Ext2FileSystem.cpp | 4 +++- Kernel/FileSystem/FileDescription.cpp | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'Kernel/FileSystem') diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 8778c2ca05..5bfb9cd4aa 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -923,8 +923,10 @@ bool Ext2FSInode::write_directory(const Vector& entries) stream.fill_to_end(0); ssize_t nwritten = write_bytes(0, directory_data.size(), directory_data.data(), nullptr); + if (nwritten < 0) + return false; set_metadata_dirty(true); - return nwritten == directory_data.size(); + return static_cast(nwritten) == directory_data.size(); } KResult Ext2FSInode::add_child(InodeIdentifier child_id, const StringView& name, mode_t mode) diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp index 30cba4dd13..1bd1659563 100644 --- a/Kernel/FileSystem/FileDescription.cpp +++ b/Kernel/FileSystem/FileDescription.cpp @@ -182,7 +182,10 @@ ssize_t FileDescription::get_dir_entries(u8* buffer, ssize_t size) if (!metadata.is_valid()) return -EIO; - int size_to_allocate = max(PAGE_SIZE, metadata.size); + if (size < 0) + return -EINVAL; + + size_t size_to_allocate = max(PAGE_SIZE, metadata.size); auto temp_buffer = ByteBuffer::create_uninitialized(size_to_allocate); BufferStream stream(temp_buffer); @@ -195,8 +198,8 @@ ssize_t FileDescription::get_dir_entries(u8* buffer, ssize_t size) }); stream.snip(); - if (size < temp_buffer.size()) - return -1; + if (static_cast(size) < temp_buffer.size()) + return -EINVAL; copy_to_user(buffer, temp_buffer.data(), temp_buffer.size()); return stream.offset(); -- cgit v1.2.3