From 9624b54703f87a690dab7d5c59c37f53ad47594e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 25 Feb 2019 22:06:55 +0100 Subject: [PATCH] More moving towards using signed types. I'm still feeling this out, but I am starting to like the general idea. --- AK/AKString.h | 8 +-- AK/Bitmap.h | 18 ++--- AK/Buffer.h | 46 ++++++------- AK/BufferStream.h | 13 ++-- AK/ByteBuffer.h | 24 +++---- AK/String.cpp | 12 ++-- AK/StringBuilder.cpp | 8 +-- AK/StringBuilder.h | 8 +-- AK/StringImpl.cpp | 18 ++--- AK/StringImpl.h | 12 ++-- AK/Vector.h | 78 +++++++++++----------- Applications/FileManager/DirectoryView.cpp | 2 +- Applications/FileManager/DirectoryView.h | 2 +- Applications/FontEditor/FontEditor.cpp | 4 +- Applications/Terminal/Terminal.cpp | 10 +-- Kernel/DiskBackedFileSystem.h | 4 +- Kernel/Ext2FileSystem.cpp | 58 ++++++---------- Kernel/Ext2FileSystem.h | 4 +- Kernel/FileSystem.cpp | 2 +- Kernel/FileSystem.h | 8 +-- Kernel/MemoryManager.cpp | 3 +- Kernel/MemoryManager.h | 2 +- Kernel/ProcFS.cpp | 4 +- Kernel/ProcFS.h | 4 +- Kernel/Process.cpp | 24 +++---- Kernel/Process.h | 4 +- Kernel/SyntheticFileSystem.cpp | 9 ++- Kernel/SyntheticFileSystem.h | 4 +- Kernel/Syscall.cpp | 4 +- Kernel/VirtualFileSystem.cpp | 2 +- LibC/grp.cpp | 2 +- LibGUI/GEventLoop.cpp | 2 +- LibGUI/GMenu.cpp | 8 +-- LibGUI/GMenu.h | 2 +- LibGUI/GObject.cpp | 2 +- LibGUI/GTextBox.cpp | 6 +- LibGUI/GTextBox.h | 2 +- LibGUI/GWindow.cpp | 10 +-- SharedGraphics/DisjointRectSet.cpp | 4 +- SharedGraphics/Font.cpp | 2 +- SharedGraphics/Painter.cpp | 2 +- Userland/df.cpp | 3 + Userland/kill.cpp | 4 +- Userland/ls.cpp | 16 ++--- Userland/sleep.cpp | 2 +- WindowServer/WSAPITypes.h | 4 +- WindowServer/WSClientConnection.cpp | 4 +- WindowServer/WSMessageLoop.cpp | 10 +-- 48 files changed, 234 insertions(+), 250 deletions(-) diff --git a/AK/AKString.h b/AK/AKString.h index 1dfc924915e..59c81188ddc 100644 --- a/AK/AKString.h +++ b/AK/AKString.h @@ -29,7 +29,7 @@ public: { } - String(const char* cstring, size_t length, ShouldChomp shouldChomp = NoChomp) + String(const char* cstring, ssize_t length, ShouldChomp shouldChomp = NoChomp) : m_impl(StringImpl::create(cstring, length, shouldChomp)) { } @@ -66,13 +66,13 @@ public: } Vector split(char separator) const; - String substring(size_t start, size_t length) const; + String substring(ssize_t start, ssize_t length) const; bool is_null() const { return !m_impl; } bool is_empty() const { return length() == 0; } - size_t length() const { return m_impl ? m_impl->length() : 0; } + ssize_t length() const { return m_impl ? m_impl->length() : 0; } const char* characters() const { return m_impl ? m_impl->characters() : nullptr; } - char operator[](size_t i) const { ASSERT(m_impl); return (*m_impl)[i]; } + char operator[](ssize_t i) const { ASSERT(m_impl); return (*m_impl)[i]; } bool operator==(const String&) const; bool operator!=(const String& other) const { return !(*this == other); } diff --git a/AK/Bitmap.h b/AK/Bitmap.h index 270b25bf2b7..5ff9ad232ad 100644 --- a/AK/Bitmap.h +++ b/AK/Bitmap.h @@ -10,12 +10,12 @@ namespace AK { class Bitmap { public: // NOTE: A wrapping Bitmap won't try to free the wrapped data. - static Bitmap wrap(byte* data, unsigned size) + static Bitmap wrap(byte* data, int size) { return Bitmap(data, size); } - static Bitmap create(unsigned size, bool default_value = 0) + static Bitmap create(int size, bool default_value = 0) { return Bitmap(size, default_value); } @@ -27,13 +27,13 @@ public: m_data = nullptr; } - unsigned size() const { return m_size; } - bool get(unsigned index) const + int size() const { return m_size; } + bool get(int index) const { ASSERT(index < m_size); return 0 != (m_data[index / 8] & (1u << (index % 8))); } - void set(unsigned index, bool value) const + void set(int index, bool value) const { ASSERT(index < m_size); if (value) @@ -46,17 +46,17 @@ public: const byte* data() const { return m_data; } private: - explicit Bitmap(unsigned size, bool default_value) + explicit Bitmap(int size, bool default_value) : m_size(size) , m_owned(true) { ASSERT(m_size != 0); - size_t size_to_allocate = ceil_div(size, 8u); + int size_to_allocate = ceil_div(size, 8); m_data = reinterpret_cast(kmalloc(size_to_allocate)); memset(m_data, default_value ? 0xff : 0x00, size_to_allocate); } - Bitmap(byte* data, unsigned size) + Bitmap(byte* data, int size) : m_data(data) , m_size(size) , m_owned(false) @@ -64,7 +64,7 @@ private: } byte* m_data { nullptr }; - unsigned m_size { 0 }; + int m_size { 0 }; bool m_owned { false }; }; diff --git a/AK/Buffer.h b/AK/Buffer.h index 1c812049f0f..25bd4d00da8 100644 --- a/AK/Buffer.h +++ b/AK/Buffer.h @@ -11,10 +11,10 @@ namespace AK { template class Buffer : public Retainable> { public: - static Retained create_uninitialized(size_t count); - static Retained copy(const T*, size_t count); - static Retained wrap(T*, size_t count); - static Retained adopt(T*, size_t count); + static Retained create_uninitialized(ssize_t count); + static Retained copy(const T*, ssize_t count); + static Retained wrap(T*, ssize_t count); + static Retained adopt(T*, ssize_t count); ~Buffer() { clear(); } @@ -27,42 +27,42 @@ public: m_elements = nullptr; } - T& operator[](size_t i) { ASSERT(i < m_size); return m_elements[i]; } - const T& operator[](size_t i) const { ASSERT(i < m_size); return m_elements[i]; } + T& operator[](ssize_t i) { ASSERT(i < m_size); return m_elements[i]; } + const T& operator[](ssize_t i) const { ASSERT(i < m_size); return m_elements[i]; } bool is_empty() const { return !m_size; } - size_t size() const { return m_size; } + ssize_t size() const { return m_size; } T* pointer() { return m_elements; } const T* pointer() const { return m_elements; } - T* offset_pointer(size_t offset) { return m_elements + offset; } - const T* offset_pointer(size_t offset) const { return m_elements + offset; } + T* offset_pointer(ssize_t offset) { return m_elements + offset; } + const T* offset_pointer(ssize_t offset) const { return m_elements + offset; } const void* end_pointer() const { return m_elements + m_size; } // NOTE: trim() does not reallocate. - void trim(size_t size) + void trim(ssize_t size) { ASSERT(size <= m_size); m_size = size; } - void grow(size_t size); + void grow(ssize_t size); private: enum ConstructionMode { Uninitialized, Copy, Wrap, Adopt }; - explicit Buffer(size_t); // For ConstructionMode=Uninitialized - Buffer(const T*, size_t, ConstructionMode); // For ConstructionMode=Copy - Buffer(T*, size_t, ConstructionMode); // For ConstructionMode=Wrap/Adopt + explicit Buffer(ssize_t); // For ConstructionMode=Uninitialized + Buffer(const T*, ssize_t, ConstructionMode); // For ConstructionMode=Copy + Buffer(T*, ssize_t, ConstructionMode); // For ConstructionMode=Wrap/Adopt Buffer() { } T* m_elements { nullptr }; - size_t m_size { 0 }; + ssize_t m_size { 0 }; bool m_owned { false }; }; template -inline Buffer::Buffer(size_t size) +inline Buffer::Buffer(ssize_t size) : m_size(size) { m_elements = static_cast(kmalloc(size * sizeof(T))); @@ -70,7 +70,7 @@ inline Buffer::Buffer(size_t size) } template -inline Buffer::Buffer(const T* elements, size_t size, ConstructionMode mode) +inline Buffer::Buffer(const T* elements, ssize_t size, ConstructionMode mode) : m_size(size) { ASSERT(mode == Copy); @@ -80,7 +80,7 @@ inline Buffer::Buffer(const T* elements, size_t size, ConstructionMode mode) } template -inline Buffer::Buffer(T* elements, size_t size, ConstructionMode mode) +inline Buffer::Buffer(T* elements, ssize_t size, ConstructionMode mode) : m_elements(elements) , m_size(size) { @@ -92,7 +92,7 @@ inline Buffer::Buffer(T* elements, size_t size, ConstructionMode mode) } template -inline void Buffer::grow(size_t size) +inline void Buffer::grow(ssize_t size) { ASSERT(size > m_size); ASSERT(m_owned); @@ -105,25 +105,25 @@ inline void Buffer::grow(size_t size) } template -inline Retained> Buffer::create_uninitialized(size_t size) +inline Retained> Buffer::create_uninitialized(ssize_t size) { return ::adopt(*new Buffer(size)); } template -inline Retained> Buffer::copy(const T* elements, size_t size) +inline Retained> Buffer::copy(const T* elements, ssize_t size) { return ::adopt(*new Buffer(elements, size, Copy)); } template -inline Retained> Buffer::wrap(T* elements, size_t size) +inline Retained> Buffer::wrap(T* elements, ssize_t size) { return ::adopt(*new Buffer(elements, size, Wrap)); } template -inline Retained> Buffer::adopt(T* elements, size_t size) +inline Retained> Buffer::adopt(T* elements, ssize_t size) { return ::adopt(*new Buffer(elements, size, Adopt)); } diff --git a/AK/BufferStream.h b/AK/BufferStream.h index d2f99c9ac24..daa037750d1 100644 --- a/AK/BufferStream.h +++ b/AK/BufferStream.h @@ -37,20 +37,21 @@ public: void operator<<(const char* str) { - size_t len = strlen(str); - for (unsigned i = 0; i < len; ++i) + ssize_t len = strlen(str); + ASSERT(len >= 0); + for (ssize_t i = 0; i < len; ++i) m_buffer[m_offset++] = str[i]; } void operator<<(const String& value) { - for (unsigned i = 0; i < value.length(); ++i) + for (ssize_t i = 0; i < value.length(); ++i) m_buffer[m_offset++] = value[i]; } void operator<<(const ByteBuffer& value) { - for (size_t i = 0; i < value.size(); ++i) + for (ssize_t i = 0; i < value.size(); ++i) m_buffer[m_offset++] = value[i]; } @@ -65,11 +66,11 @@ public: m_buffer[m_offset++] = ch; } - size_t offset() const { return m_offset; } + ssize_t offset() const { return m_offset; } private: ByteBuffer& m_buffer; - size_t m_offset { 0 }; + ssize_t m_offset { 0 }; }; } diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h index 33267f347a6..e0e53d3ac5e 100644 --- a/AK/ByteBuffer.h +++ b/AK/ByteBuffer.h @@ -30,10 +30,10 @@ public: return *this; } - static ByteBuffer create_uninitialized(size_t size) { return ByteBuffer(Buffer::create_uninitialized(size)); } - static ByteBuffer copy(const byte* data, size_t size) { return ByteBuffer(Buffer::copy(data, size)); } - static ByteBuffer wrap(byte* data, size_t size) { return ByteBuffer(Buffer::wrap(data, size)); } - static ByteBuffer adopt(byte* data, size_t size) { return ByteBuffer(Buffer::adopt(data, size)); } + static ByteBuffer create_uninitialized(ssize_t size) { return ByteBuffer(Buffer::create_uninitialized(size)); } + static ByteBuffer copy(const byte* data, ssize_t size) { return ByteBuffer(Buffer::copy(data, size)); } + static ByteBuffer wrap(byte* data, ssize_t size) { return ByteBuffer(Buffer::wrap(data, size)); } + static ByteBuffer adopt(byte* data, ssize_t size) { return ByteBuffer(Buffer::adopt(data, size)); } ~ByteBuffer() { clear(); } void clear() { m_impl = nullptr; } @@ -42,27 +42,27 @@ public: bool operator!() const { return is_null(); } bool is_null() const { return m_impl == nullptr; } - byte& operator[](size_t i) { ASSERT(m_impl); return (*m_impl)[i]; } - byte operator[](size_t i) const { ASSERT(m_impl); return (*m_impl)[i]; } + byte& operator[](ssize_t i) { ASSERT(m_impl); return (*m_impl)[i]; } + byte operator[](ssize_t i) const { ASSERT(m_impl); return (*m_impl)[i]; } bool is_empty() const { return !m_impl || m_impl->is_empty(); } - size_t size() const { return m_impl ? m_impl->size() : 0; } + ssize_t size() const { return m_impl ? m_impl->size() : 0; } byte* pointer() { return m_impl ? m_impl->pointer() : nullptr; } const byte* pointer() const { return m_impl ? m_impl->pointer() : nullptr; } - byte* offset_pointer(size_t offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; } - const byte* offset_pointer(size_t offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; } + byte* offset_pointer(ssize_t offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; } + const byte* offset_pointer(ssize_t offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; } const void* end_pointer() const { return m_impl ? m_impl->end_pointer() : nullptr; } // NOTE: trim() does not reallocate. - void trim(size_t size) + void trim(ssize_t size) { if (m_impl) m_impl->trim(size); } - ByteBuffer slice(size_t offset, size_t size) const + ByteBuffer slice(ssize_t offset, ssize_t size) const { if (is_null()) return { }; @@ -73,7 +73,7 @@ public: return copy(offset_pointer(offset), size); } - void grow(size_t size) + void grow(ssize_t size) { if (!m_impl) m_impl = Buffer::create_uninitialized(size); diff --git a/AK/String.cpp b/AK/String.cpp index 421bcb89a9f..8fd8e2fec23 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -36,7 +36,7 @@ String String::isolated_copy() const return String(move(*impl)); } -String String::substring(size_t start, size_t length) const +String String::substring(ssize_t start, ssize_t length) const { ASSERT(m_impl); ASSERT(start + length <= m_impl->length()); @@ -54,17 +54,17 @@ Vector String::split(const char separator) const return { }; Vector v; - size_t substart = 0; - for (size_t i = 0; i < length(); ++i) { + ssize_t substart = 0; + for (ssize_t i = 0; i < length(); ++i) { char ch = characters()[i]; if (ch == separator) { - size_t sublen = i - substart; + ssize_t sublen = i - substart; if (sublen != 0) v.append(substring(substart, sublen)); substart = i + 1; } } - size_t taillen = length() - substart; + ssize_t taillen = length() - substart; if (taillen != 0) v.append(substring(substart, taillen)); if (characters()[length() - 1] == separator) @@ -82,7 +82,7 @@ ByteBuffer String::to_byte_buffer() const unsigned String::to_uint(bool& ok) const { unsigned value = 0; - for (size_t i = 0; i < length(); ++i) { + for (ssize_t i = 0; i < length(); ++i) { if (characters()[i] < '0' || characters()[i] > '9') { ok = false; return 0; diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index 1a929d4dd9a..8eb7479aeac 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -5,13 +5,13 @@ namespace AK { -inline void StringBuilder::will_append(size_t size) +inline void StringBuilder::will_append(ssize_t size) { if ((m_length + size) > m_buffer.size()) - m_buffer.grow(max((size_t)16, m_buffer.size() * 2 + size)); + m_buffer.grow(max((ssize_t)16, m_buffer.size() * 2 + size)); } -StringBuilder::StringBuilder(size_t initial_capacity) +StringBuilder::StringBuilder(ssize_t initial_capacity) { m_buffer.grow(initial_capacity); } @@ -25,7 +25,7 @@ void StringBuilder::append(const String& str) m_length += str.length(); } -void StringBuilder::append(const char* characters, size_t length) +void StringBuilder::append(const char* characters, ssize_t length) { if (!length) return; diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h index 9aa83c6357c..f6c17dbf85c 100644 --- a/AK/StringBuilder.h +++ b/AK/StringBuilder.h @@ -8,12 +8,12 @@ namespace AK { class StringBuilder { public: - explicit StringBuilder(size_t initial_capacity = 16); + explicit StringBuilder(ssize_t initial_capacity = 16); ~StringBuilder() { } void append(const String&); void append(char); - void append(const char*, size_t); + void append(const char*, ssize_t); void appendf(const char*, ...); void appendvf(const char*, va_list); @@ -21,10 +21,10 @@ public: ByteBuffer to_byte_buffer(); private: - void will_append(size_t); + void will_append(ssize_t); ByteBuffer m_buffer; - size_t m_length { 0 }; + ssize_t m_length { 0 }; }; } diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp index dedf4ac909f..3a11a1a74e3 100644 --- a/AK/StringImpl.cpp +++ b/AK/StringImpl.cpp @@ -30,7 +30,7 @@ StringImpl& StringImpl::the_empty_stringimpl() return *s_the_empty_stringimpl; } -StringImpl::StringImpl(ConstructWithInlineBufferTag, size_t length) +StringImpl::StringImpl(ConstructWithInlineBufferTag, ssize_t length) : m_length(length) , m_characters(m_inline_buffer) { @@ -50,12 +50,12 @@ StringImpl::~StringImpl() #endif } -static inline size_t allocation_size_for_stringimpl(size_t length) +static inline ssize_t allocation_size_for_stringimpl(ssize_t length) { return sizeof(StringImpl) + (sizeof(char) * length) + sizeof(char); } -Retained StringImpl::create_uninitialized(size_t length, char*& buffer) +Retained StringImpl::create_uninitialized(ssize_t length, char*& buffer) { ASSERT(length); void* slot = kmalloc(allocation_size_for_stringimpl(length)); @@ -66,7 +66,7 @@ Retained StringImpl::create_uninitialized(size_t length, char*& buff return new_stringimpl; } -RetainPtr StringImpl::create(const char* cstring, size_t length, ShouldChomp shouldChomp) +RetainPtr StringImpl::create(const char* cstring, ssize_t length, ShouldChomp shouldChomp) { if (!cstring) return nullptr; @@ -123,7 +123,7 @@ static inline char to_ascii_uppercase(char c) Retained StringImpl::to_lowercase() const { - for (size_t i = 0; i < m_length; ++i) { + for (ssize_t i = 0; i < m_length; ++i) { if (!is_ascii_lowercase(m_characters[i])) goto slow_path; } @@ -132,14 +132,14 @@ Retained StringImpl::to_lowercase() const slow_path: char* buffer; auto lowercased = create_uninitialized(m_length, buffer); - for (size_t i = 0; i < m_length; ++i) + for (ssize_t i = 0; i < m_length; ++i) buffer[i] = to_ascii_lowercase(m_characters[i]); return lowercased; } Retained StringImpl::to_uppercase() const { - for (size_t i = 0; i < m_length; ++i) { + for (ssize_t i = 0; i < m_length; ++i) { if (!is_ascii_uppercase(m_characters[i])) goto slow_path; } @@ -148,7 +148,7 @@ Retained StringImpl::to_uppercase() const slow_path: char* buffer; auto uppercased = create_uninitialized(m_length, buffer); - for (size_t i = 0; i < m_length; ++i) + for (ssize_t i = 0; i < m_length; ++i) buffer[i] = to_ascii_uppercase(m_characters[i]); return uppercased; } @@ -159,7 +159,7 @@ void StringImpl::compute_hash() const m_hash = 0; } else { unsigned hash = 0; - for (size_t i = 0; i < m_length; ++i) { + for (ssize_t i = 0; i < m_length; ++i) { hash += m_characters[i]; hash += (hash << 10); hash ^= (hash >> 6); diff --git a/AK/StringImpl.h b/AK/StringImpl.h index c2a1fdf78f0..9a4405cadcb 100644 --- a/AK/StringImpl.h +++ b/AK/StringImpl.h @@ -10,9 +10,9 @@ enum ShouldChomp { NoChomp, Chomp }; class StringImpl : public Retainable { public: - static Retained create_uninitialized(size_t length, char*& buffer); + static Retained create_uninitialized(ssize_t length, char*& buffer); static RetainPtr create(const char* cstring, ShouldChomp = NoChomp); - static RetainPtr create(const char* cstring, size_t length, ShouldChomp = NoChomp); + static RetainPtr create(const char* cstring, ssize_t length, ShouldChomp = NoChomp); Retained to_lowercase() const; Retained to_uppercase() const; @@ -20,9 +20,9 @@ public: ~StringImpl(); - size_t length() const { return m_length; } + ssize_t length() const { return m_length; } const char* characters() const { return m_characters; } - char operator[](size_t i) const { ASSERT(i < m_length); return m_characters[i]; } + char operator[](ssize_t i) const { ASSERT(i >= 0 && i < m_length); return m_characters[i]; } unsigned hash() const { @@ -36,11 +36,11 @@ private: explicit StringImpl(ConstructTheEmptyStringImplTag) : m_characters("") { } enum ConstructWithInlineBufferTag { ConstructWithInlineBuffer }; - StringImpl(ConstructWithInlineBufferTag, size_t length); + StringImpl(ConstructWithInlineBufferTag, ssize_t length); void compute_hash() const; - size_t m_length { 0 }; + ssize_t m_length { 0 }; mutable bool m_hasHash { false }; const char* m_characters { nullptr }; mutable unsigned m_hash { 0 }; diff --git a/AK/Vector.h b/AK/Vector.h index 4e6ae118797..a44bfadf7c4 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -9,12 +9,12 @@ namespace AK { template class Vector; struct KmallocAllocator { - static void* allocate(size_t size) { return kmalloc(size); } + static void* allocate(ssize_t size) { return kmalloc(size); } static void deallocate(void* ptr) { kfree(ptr); } }; struct KmallocEternalAllocator { - static void* allocate(size_t size) { return kmalloc_eternal(size); } + static void* allocate(ssize_t size) { return kmalloc_eternal(size); } static void deallocate(void*) { } }; @@ -22,25 +22,25 @@ template class VectorImpl { public: ~VectorImpl() { } - static VectorImpl* create(size_t capacity) + static VectorImpl* create(ssize_t capacity) { - size_t size = sizeof(VectorImpl) + sizeof(T) * capacity; + ssize_t size = sizeof(VectorImpl) + sizeof(T) * capacity; void* slot = Allocator::allocate(size); new (slot) VectorImpl(capacity); return (VectorImpl*)slot; } - size_t size() const { return m_size; } - size_t capacity() const { return m_capacity; } + ssize_t size() const { return m_size; } + ssize_t capacity() const { return m_capacity; } - T& at(size_t i) { ASSERT(i < m_size); return *slot(i); } - const T& at(size_t i) const { ASSERT(i < m_size); return *slot(i); } + T& at(ssize_t i) { ASSERT(i < m_size); return *slot(i); } + const T& at(ssize_t i) const { ASSERT(i < m_size); return *slot(i); } - void remove(size_t index) + void remove(ssize_t index) { ASSERT(index < m_size); at(index).~T(); - for (size_t i = index + 1; i < m_size; ++i) { + for (ssize_t i = index + 1; i < m_size; ++i) { new (slot(i - 1)) T(move(at(i))); at(i).~T(); } @@ -51,16 +51,16 @@ public: //private: friend class Vector; - VectorImpl(size_t capacity) : m_capacity(capacity) { } + VectorImpl(ssize_t capacity) : m_capacity(capacity) { } T* tail() { return reinterpret_cast(this + 1); } - T* slot(size_t i) { return &tail()[i]; } + T* slot(ssize_t i) { return &tail()[i]; } const T* tail() const { return reinterpret_cast(this + 1); } - const T* slot(size_t i) const { return &tail()[i]; } + const T* slot(ssize_t i) const { return &tail()[i]; } - size_t m_size { 0 }; - size_t m_capacity; + ssize_t m_size { 0 }; + ssize_t m_capacity; }; template @@ -78,7 +78,7 @@ public: Vector(const Vector& other) { ensure_capacity(other.size()); - for (size_t i = 0; i < other.size(); ++i) + for (ssize_t i = 0; i < other.size(); ++i) unchecked_append(other[i]); } @@ -93,7 +93,7 @@ public: void clear() { - for (size_t i = 0; i < size(); ++i) { + for (ssize_t i = 0; i < size(); ++i) { at(i).~T(); } Allocator::deallocate(m_impl); @@ -104,14 +104,14 @@ public: { if (!m_impl) return; - for (size_t i = 0; i < size(); ++i) + for (ssize_t i = 0; i < size(); ++i) at(i).~T(); m_impl->m_size = 0; } bool contains_slow(const T& value) const { - for (size_t i = 0; i < size(); ++i) { + for (ssize_t i = 0; i < size(); ++i) { if (at(i) == value) return true; } @@ -119,17 +119,17 @@ public: } bool is_empty() const { return size() == 0; } - size_t size() const { return m_impl ? m_impl->size() : 0; } - size_t capacity() const { return m_impl ? m_impl->capacity() : 0; } + ssize_t size() const { return m_impl ? m_impl->size() : 0; } + ssize_t capacity() const { return m_impl ? m_impl->capacity() : 0; } T* data() { return m_impl ? m_impl->slot(0) : nullptr; } const T* data() const { return m_impl ? m_impl->slot(0) : nullptr; } - const T& at(size_t i) const { return m_impl->at(i); } - T& at(size_t i) { return m_impl->at(i); } + const T& at(ssize_t i) const { return m_impl->at(i); } + T& at(ssize_t i) { return m_impl->at(i); } - const T& operator[](size_t i) const { return at(i); } - T& operator[](size_t i) { return at(i); } + const T& operator[](ssize_t i) const { return at(i); } + T& operator[](ssize_t i) { return at(i); } const T& first() const { return at(0); } T& first() { return at(0); } @@ -154,7 +154,7 @@ public: return value; } - void remove(size_t index) + void remove(ssize_t index) { m_impl->remove(index); } @@ -211,23 +211,23 @@ public: ++m_impl->m_size; } - void append(const T* values, size_t count) + void append(const T* values, ssize_t count) { ensure_capacity(size() + count); - for (size_t i = 0; i < count; ++i) + for (ssize_t i = 0; i < count; ++i) new (m_impl->slot(m_impl->m_size + i)) T(values[i]); m_impl->m_size += count; } - void ensure_capacity(size_t neededCapacity) + void ensure_capacity(ssize_t neededCapacity) { if (capacity() >= neededCapacity) return; - size_t new_capacity = padded_capacity(neededCapacity); + ssize_t new_capacity = padded_capacity(neededCapacity); auto new_impl = VectorImpl::create(new_capacity); if (m_impl) { new_impl->m_size = m_impl->m_size; - for (size_t i = 0; i < size(); ++i) { + for (ssize_t i = 0; i < size(); ++i) { new (new_impl->slot(i)) T(move(m_impl->at(i))); m_impl->at(i).~T(); } @@ -236,13 +236,13 @@ public: m_impl = new_impl; } - void resize(size_t new_size) + void resize(ssize_t new_size) { ASSERT(new_size >= size()); if (!new_size) return; ensure_capacity(new_size); - for (size_t i = size(); i < new_size; ++i) + for (ssize_t i = size(); i < new_size; ++i) new (m_impl->slot(i)) T; m_impl->m_size = new_size; } @@ -254,9 +254,9 @@ public: T& operator*() { return m_vector[m_index]; } private: friend class Vector; - Iterator(Vector& vector, size_t index) : m_vector(vector), m_index(index) { } + Iterator(Vector& vector, ssize_t index) : m_vector(vector), m_index(index) { } Vector& m_vector; - size_t m_index { 0 }; + ssize_t m_index { 0 }; }; Iterator begin() { return Iterator(*this, 0); } @@ -269,18 +269,18 @@ public: const T& operator*() const { return m_vector[m_index]; } private: friend class Vector; - ConstIterator(const Vector& vector, const size_t index) : m_vector(vector), m_index(index) { } + ConstIterator(const Vector& vector, const ssize_t index) : m_vector(vector), m_index(index) { } const Vector& m_vector; - size_t m_index { 0 }; + ssize_t m_index { 0 }; }; ConstIterator begin() const { return ConstIterator(*this, 0); } ConstIterator end() const { return ConstIterator(*this, size()); } //private: - static size_t padded_capacity(size_t capacity) + static ssize_t padded_capacity(ssize_t capacity) { - return max(size_t(4), capacity + (capacity / 4) + 4); + return max(ssize_t(4), capacity + (capacity / 4) + 4); } VectorImpl* m_impl { nullptr }; diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp index 363821ea2a5..e7cff999f57 100644 --- a/Applications/FileManager/DirectoryView.cpp +++ b/Applications/FileManager/DirectoryView.cpp @@ -138,7 +138,7 @@ void DirectoryView::paint_event(GPaintEvent&) int painted_item_index = 0; auto process_entries = [&] (const Vector& entries) { - for (size_t i = 0; i < entries.size(); ++i, ++painted_item_index) { + for (int i = 0; i < entries.size(); ++i, ++painted_item_index) { auto& entry = entries[i]; int y = painted_item_index * item_height(); Rect icon_rect(horizontal_padding, y, icon_size, item_height()); diff --git a/Applications/FileManager/DirectoryView.h b/Applications/FileManager/DirectoryView.h index 34f331580b7..234a18eb812 100644 --- a/Applications/FileManager/DirectoryView.h +++ b/Applications/FileManager/DirectoryView.h @@ -37,7 +37,7 @@ private: bool is_directory() const { return S_ISDIR(mode); } }; - const Entry& entry(size_t index) const + const Entry& entry(int index) const { if (index < m_directories.size()) return m_directories[index]; diff --git a/Applications/FontEditor/FontEditor.cpp b/Applications/FontEditor/FontEditor.cpp index 1fd1431762f..33670a02299 100644 --- a/Applications/FontEditor/FontEditor.cpp +++ b/Applications/FontEditor/FontEditor.cpp @@ -227,8 +227,8 @@ void GlyphEditorWidget::draw_at_mouse(const GMouseEvent& event) int x = (event.x() - 1) / m_scale; int y = (event.y() - 1) / m_scale; auto bitmap = font().glyph_bitmap(m_glyph); - ASSERT((unsigned)x < bitmap.width()); - ASSERT((unsigned)y < bitmap.height()); + ASSERT(x < bitmap.width()); + ASSERT(y < bitmap.height()); if (bitmap.bit_at(x, y) == set) return; bitmap.set_bit_at(x, y, set); diff --git a/Applications/Terminal/Terminal.cpp b/Applications/Terminal/Terminal.cpp index 4b63cd2d919..a5cfa600027 100644 --- a/Applications/Terminal/Terminal.cpp +++ b/Applications/Terminal/Terminal.cpp @@ -84,7 +84,7 @@ void Terminal::Line::clear(Attribute attribute) Terminal::~Terminal() { - for (size_t i = 0; i < m_rows; ++i) + for (int i = 0; i < m_rows; ++i) delete m_lines[i]; delete [] m_lines; free(m_horizontal_tabs); @@ -115,7 +115,7 @@ inline bool is_valid_final_character(byte ch) unsigned parse_uint(const String& str, bool& ok) { unsigned value = 0; - for (size_t i = 0; i < str.length(); ++i) { + for (int i = 0; i < str.length(); ++i) { if (str[i] < '0' || str[i] > '9') { ok = false; return 0; @@ -552,7 +552,7 @@ void Terminal::on_char(byte ch) void Terminal::inject_string(const String& str) { - for (size_t i = 0; i < str.length(); ++i) + for (int i = 0; i < str.length(); ++i) on_char(str[i]); } @@ -562,12 +562,12 @@ void Terminal::unimplemented_escape() builder.appendf("((Unimplemented escape: %c", m_final); if (!m_parameters.is_empty()) { builder.append(" parameters:"); - for (size_t i = 0; i < m_parameters.size(); ++i) + for (int i = 0; i < m_parameters.size(); ++i) builder.append((char)m_parameters[i]); } if (!m_intermediates.is_empty()) { builder.append(" intermediates:"); - for (size_t i = 0; i < m_intermediates.size(); ++i) + for (int i = 0; i < m_intermediates.size(); ++i) builder.append((char)m_intermediates[i]); } builder.append("))"); diff --git a/Kernel/DiskBackedFileSystem.h b/Kernel/DiskBackedFileSystem.h index 75448d9c16c..75d3f8f8fc2 100644 --- a/Kernel/DiskBackedFileSystem.h +++ b/Kernel/DiskBackedFileSystem.h @@ -10,7 +10,7 @@ public: DiskDevice& device() { return *m_device; } const DiskDevice& device() const { return *m_device; } - size_t block_size() const { return m_block_size; } + int block_size() const { return m_block_size; } protected: explicit DiskBackedFS(Retained&&); @@ -24,6 +24,6 @@ protected: bool write_blocks(unsigned index, unsigned count, const ByteBuffer&); private: - size_t m_block_size { 0 }; + int m_block_size { 0 }; Retained m_device; }; diff --git a/Kernel/Ext2FileSystem.cpp b/Kernel/Ext2FileSystem.cpp index 866974a9b81..0de3c4fbe09 100644 --- a/Kernel/Ext2FileSystem.cpp +++ b/Kernel/Ext2FileSystem.cpp @@ -190,7 +190,7 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in { LOCKER(m_lock); - dbgprintf("Ext2FS: writing %u block(s) to i_block array\n", min((size_t)EXT2_NDIR_BLOCKS, blocks.size())); + dbgprintf("Ext2FS: writing %u block(s) to i_block array\n", min(EXT2_NDIR_BLOCKS, blocks.size())); auto old_shape = compute_block_list_shape(e2inode.i_blocks / (2 << super_block().s_log_block_size)); auto new_shape = compute_block_list_shape(blocks.size()); @@ -429,7 +429,7 @@ RetainPtr Ext2FS::get_inode(InodeIdentifier inode) const return new_inode; } -ssize_t Ext2FSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileDescriptor*) const +ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescriptor*) const { Locker inode_locker(m_lock); ASSERT(offset >= 0); @@ -441,7 +441,7 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileDe static const unsigned max_inline_symlink_length = 60; if (is_symlink() && size() < max_inline_symlink_length) { ssize_t nread = min((off_t)size() - offset, static_cast(count)); - memcpy(buffer, m_raw_inode.i_block + offset, nread); + memcpy(buffer, m_raw_inode.i_block + offset, (size_t)nread); return nread; } @@ -494,7 +494,7 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileDe return nread; } -ssize_t Ext2FSInode::write_bytes(off_t offset, size_t count, const byte* data, FileDescriptor*) +ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const byte* data, FileDescriptor*) { Locker inode_locker(m_lock); Locker fs_locker(fs().m_lock); @@ -504,7 +504,7 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, size_t count, const byte* data, F ASSERT(offset >= 0); - const size_t block_size = fs().block_size(); + const ssize_t block_size = fs().block_size(); size_t old_size = size(); size_t new_size = max(static_cast(offset) + count, size()); @@ -539,8 +539,8 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, size_t count, const byte* data, F auto buffer_block = ByteBuffer::create_uninitialized(block_size); for (dword bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) { - dword offset_into_block = (bi == first_block_logical_index) ? offset_into_first_block : 0; - dword 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((size_t)block_size - offset_into_block, remaining_count); ByteBuffer block; if (offset_into_block != 0) { @@ -702,24 +702,24 @@ bool Ext2FS::write_directory_inode(unsigned directoryInode, Vectorwrite_bytes(0, directory_data.size(), directory_data.pointer(), nullptr); return nwritten == directory_data.size(); @@ -806,7 +792,7 @@ void Ext2FS::dump_inode_bitmap(unsigned groupIndex) const { LOCKER(m_lock); traverse_inode_bitmap(groupIndex, [] (unsigned, const Bitmap& bitmap) { - for (unsigned i = 0; i < bitmap.size(); ++i) + for (int i = 0; i < bitmap.size(); ++i) kprintf("%c", bitmap.get(i) ? '1' : '0'); return true; }); @@ -882,7 +868,7 @@ Vector Ext2FS::allocate_blocks(unsigned group, unsigned coun // FIXME: Implement a scan that finds consecutive blocks if possible. Vector blocks; traverse_block_bitmap(group, [&blocks, count] (unsigned first_block_in_bitmap, const Bitmap& bitmap) { - for (unsigned i = 0; i < bitmap.size(); ++i) { + for (int i = 0; i < bitmap.size(); ++i) { if (!bitmap.get(i)) { blocks.append(first_block_in_bitmap + i); if (blocks.size() == count) @@ -931,23 +917,23 @@ unsigned Ext2FS::allocate_inode(unsigned preferred_group, unsigned expected_size dbgprintf("Ext2FS: allocate_inode: found suitable group [%u] for new inode with %u blocks needed :^)\n", groupIndex, needed_blocks); - unsigned firstFreeInodeInGroup = 0; - traverse_inode_bitmap(groupIndex, [&firstFreeInodeInGroup] (unsigned firstInodeInBitmap, const Bitmap& bitmap) { - for (unsigned i = 0; i < bitmap.size(); ++i) { + unsigned first_free_inode_in_group = 0; + traverse_inode_bitmap(groupIndex, [&first_free_inode_in_group] (unsigned firstInodeInBitmap, const Bitmap& bitmap) { + for (int i = 0; i < bitmap.size(); ++i) { if (!bitmap.get(i)) { - firstFreeInodeInGroup = firstInodeInBitmap + i; + first_free_inode_in_group = firstInodeInBitmap + i; return false; } } return true; }); - if (!firstFreeInodeInGroup) { + if (!first_free_inode_in_group) { kprintf("Ext2FS: first_free_inode_in_group returned no inode, despite bgd claiming there are inodes :(\n"); return 0; } - unsigned inode = firstFreeInodeInGroup; + unsigned inode = first_free_inode_in_group; dbgprintf("Ext2FS: found suitable inode %u\n", inode); ASSERT(get_inode_allocation_state(inode) == false); diff --git a/Kernel/Ext2FileSystem.h b/Kernel/Ext2FileSystem.h index 1b0c8aecd9a..737ff65dee4 100644 --- a/Kernel/Ext2FileSystem.h +++ b/Kernel/Ext2FileSystem.h @@ -25,13 +25,13 @@ public: private: // ^Inode - virtual ssize_t read_bytes(off_t, size_t, byte* buffer, FileDescriptor*) const override; + virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescriptor*) const override; virtual InodeMetadata metadata() const override; virtual bool traverse_as_directory(Function) const override; virtual InodeIdentifier lookup(const String& name) override; virtual String reverse_lookup(InodeIdentifier) override; virtual void flush_metadata() override; - virtual ssize_t write_bytes(off_t, size_t, const byte* data, FileDescriptor*) override; + virtual ssize_t write_bytes(off_t, ssize_t, const byte* data, FileDescriptor*) override; virtual bool add_child(InodeIdentifier child_id, const String& name, byte file_type, int& error) override; virtual bool remove_child(const String& name, int& error) override; virtual RetainPtr parent() const override; diff --git a/Kernel/FileSystem.cpp b/Kernel/FileSystem.cpp index 85c23f5389c..2b6758a9bfa 100644 --- a/Kernel/FileSystem.cpp +++ b/Kernel/FileSystem.cpp @@ -104,7 +104,7 @@ void Inode::will_be_destroyed() flush_metadata(); } -void Inode::inode_contents_changed(off_t offset, size_t size, const byte* data) +void Inode::inode_contents_changed(off_t offset, ssize_t size, const byte* data) { if (m_vmo) m_vmo->inode_contents_changed(Badge(), offset, size, data); diff --git a/Kernel/FileSystem.h b/Kernel/FileSystem.h index b3081e32692..44414de856d 100644 --- a/Kernel/FileSystem.h +++ b/Kernel/FileSystem.h @@ -47,7 +47,7 @@ public: DirectoryEntry(const char* name, InodeIdentifier, byte file_type); DirectoryEntry(const char* name, size_t name_length, InodeIdentifier, byte file_type); char name[256]; - size_t name_length { 0 }; + int name_length { 0 }; InodeIdentifier inode; byte file_type { 0 }; }; @@ -88,11 +88,11 @@ public: ByteBuffer read_entire(FileDescriptor* = nullptr) const; - virtual ssize_t read_bytes(off_t, size_t, byte* buffer, FileDescriptor*) const = 0; + virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescriptor*) const = 0; virtual bool traverse_as_directory(Function) const = 0; virtual InodeIdentifier lookup(const String& name) = 0; virtual String reverse_lookup(InodeIdentifier) = 0; - virtual ssize_t write_bytes(off_t, size_t, const byte* data, FileDescriptor*) = 0; + virtual ssize_t write_bytes(off_t, ssize_t, const byte* data, FileDescriptor*) = 0; virtual bool add_child(InodeIdentifier child_id, const String& name, byte file_type, int& error) = 0; virtual bool remove_child(const String& name, int& error) = 0; virtual RetainPtr parent() const = 0; @@ -123,7 +123,7 @@ public: protected: Inode(FS& fs, unsigned index); void set_metadata_dirty(bool b) { m_metadata_dirty = b; } - void inode_contents_changed(off_t, size_t, const byte*); + void inode_contents_changed(off_t, ssize_t, const byte*); void inode_size_changed(size_t old_size, size_t new_size); mutable Lock m_lock; diff --git a/Kernel/MemoryManager.cpp b/Kernel/MemoryManager.cpp index dfe86d7b629..ad9241d201b 100644 --- a/Kernel/MemoryManager.cpp +++ b/Kernel/MemoryManager.cpp @@ -791,6 +791,7 @@ void VMObject::for_each_region(Callback callback) void VMObject::inode_size_changed(Badge, size_t old_size, size_t new_size) { + (void)old_size; InterruptDisabler disabler; size_t old_page_count = page_count(); @@ -813,7 +814,7 @@ void VMObject::inode_size_changed(Badge, size_t old_size, size_t new_size }); } -void VMObject::inode_contents_changed(Badge, off_t offset, size_t size, const byte* data) +void VMObject::inode_contents_changed(Badge, off_t offset, ssize_t size, const byte* data) { (void)size; (void)data; diff --git a/Kernel/MemoryManager.h b/Kernel/MemoryManager.h index cb983e09512..25d03a004f6 100644 --- a/Kernel/MemoryManager.h +++ b/Kernel/MemoryManager.h @@ -107,7 +107,7 @@ public: const Vector>& physical_pages() const { return m_physical_pages; } Vector>& physical_pages() { return m_physical_pages; } - void inode_contents_changed(Badge, off_t, size_t, const byte*); + void inode_contents_changed(Badge, off_t, ssize_t, const byte*); void inode_size_changed(Badge, size_t old_size, size_t new_size); size_t size() const { return m_size; } diff --git a/Kernel/ProcFS.cpp b/Kernel/ProcFS.cpp index 0b26b30102a..5e50163f908 100644 --- a/Kernel/ProcFS.cpp +++ b/Kernel/ProcFS.cpp @@ -808,7 +808,7 @@ InodeMetadata ProcFSInode::metadata() const return metadata; } -ssize_t ProcFSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileDescriptor* descriptor) const +ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescriptor* descriptor) const { #ifdef PROCFS_DEBUG dbgprintf("ProcFS: read_bytes %u\n", index()); @@ -1034,7 +1034,7 @@ void ProcFSInode::flush_metadata() { } -ssize_t ProcFSInode::write_bytes(off_t offset, size_t size, const byte* buffer, FileDescriptor*) +ssize_t ProcFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, FileDescriptor*) { auto* directory_entry = fs().get_directory_entry(identifier()); if (!directory_entry || !directory_entry->write_callback) diff --git a/Kernel/ProcFS.h b/Kernel/ProcFS.h index f2b0e0a0e0f..bc4d139cb81 100644 --- a/Kernel/ProcFS.h +++ b/Kernel/ProcFS.h @@ -76,13 +76,13 @@ public: private: // ^Inode - virtual ssize_t read_bytes(off_t, size_t, byte* buffer, FileDescriptor*) const override; + virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescriptor*) const override; virtual InodeMetadata metadata() const override; virtual bool traverse_as_directory(Function) const override; virtual InodeIdentifier lookup(const String& name) override; virtual String reverse_lookup(InodeIdentifier) override; virtual void flush_metadata() override; - virtual ssize_t write_bytes(off_t, size_t, const byte* buffer, FileDescriptor*) override; + virtual ssize_t write_bytes(off_t, ssize_t, const byte* buffer, FileDescriptor*) override; virtual bool add_child(InodeIdentifier child_id, const String& name, byte file_type, int& error) override; virtual bool remove_child(const String& name, int& error) override; virtual RetainPtr parent() const override; diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index f7309930bc3..435b781e149 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -121,7 +121,7 @@ Region* Process::allocate_region_with_vmo(LinearAddress laddr, size_t size, Reta bool Process::deallocate_region(Region& region) { InterruptDisabler disabler; - for (size_t i = 0; i < m_regions.size(); ++i) { + for (int i = 0; i < m_regions.size(); ++i) { if (m_regions[i].ptr() == ®ion) { MM.unmap_region(region); m_regions.remove(i); @@ -367,7 +367,7 @@ int Process::do_exec(String path, Vector arguments, Vector envir m_signal_mask = 0xffffffff; m_pending_signals = 0; - for (size_t i = 0; i < m_fds.size(); ++i) { + for (int i = 0; i < m_fds.size(); ++i) { auto& daf = m_fds[i]; if (daf.descriptor && daf.flags & FD_CLOEXEC) { daf.descriptor->close(); @@ -441,21 +441,19 @@ void Process::make_userspace_stack(Vector arguments, Vector envi // FIXME: It would be better if this didn't make us panic. ASSERT((total_blob_size + total_meta_size) < default_userspace_stack_size); - for (size_t i = 0; i < arguments.size(); ++i) { + for (int i = 0; i < arguments.size(); ++i) { argv[i] = bufptr; memcpy(bufptr, arguments[i].characters(), arguments[i].length()); bufptr += arguments[i].length(); *(bufptr++) = '\0'; - printf("argv[%u] = %p (%s)\n", i, argv[i], argv[i]); } argv[arguments.size()] = nullptr; - for (size_t i = 0; i < environment.size(); ++i) { + for (int i = 0; i < environment.size(); ++i) { env[i] = bufptr; memcpy(bufptr, environment[i].characters(), environment[i].length()); bufptr += environment[i].length(); *(bufptr++) = '\0'; - printf("env[%u] = %p (%s)\n", i, env[i], env[i]); } env[environment.size()] = nullptr; @@ -623,7 +621,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring if (fork_parent) { m_fds.resize(fork_parent->m_fds.size()); - for (size_t i = 0; i < fork_parent->m_fds.size(); ++i) { + for (int i = 0; i < fork_parent->m_fds.size(); ++i) { if (!fork_parent->m_fds[i].descriptor) continue; #ifdef FORK_DEBUG @@ -959,7 +957,7 @@ FileDescriptor* Process::file_descriptor(int fd) { if (fd < 0) return nullptr; - if ((size_t)fd < m_fds.size()) + if (fd < m_fds.size()) return m_fds[fd].descriptor.ptr(); return nullptr; } @@ -968,7 +966,7 @@ const FileDescriptor* Process::file_descriptor(int fd) const { if (fd < 0) return nullptr; - if ((size_t)fd < m_fds.size()) + if (fd < m_fds.size()) return m_fds[fd].descriptor.ptr(); return nullptr; } @@ -1894,7 +1892,7 @@ int Process::sys$sigaction(int signum, const sigaction* act, sigaction* old_act) return 0; } -int Process::sys$getgroups(int count, gid_t* gids) +int Process::sys$getgroups(ssize_t count, gid_t* gids) { if (count < 0) return -EINVAL; @@ -1911,8 +1909,10 @@ int Process::sys$getgroups(int count, gid_t* gids) return 0; } -int Process::sys$setgroups(size_t count, const gid_t* gids) +int Process::sys$setgroups(ssize_t count, const gid_t* gids) { + if (count < 0) + return -EINVAL; if (!is_superuser()) return -EPERM; if (count >= MAX_PROCESS_GIDS) @@ -1921,7 +1921,7 @@ int Process::sys$setgroups(size_t count, const gid_t* gids) return -EFAULT; m_gids.clear(); m_gids.set(m_gid); - for (size_t i = 0; i < count; ++i) + for (int i = 0; i < count; ++i) m_gids.set(gids[i]); return 0; } diff --git a/Kernel/Process.h b/Kernel/Process.h index 480d8f2229f..8c5cd4eaeb9 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -198,8 +198,8 @@ public: int sys$sigaction(int signum, const sigaction* act, sigaction* old_act); int sys$sigprocmask(int how, const sigset_t* set, sigset_t* old_set); int sys$sigpending(sigset_t*); - int sys$getgroups(int size, gid_t*); - int sys$setgroups(size_t, const gid_t*); + int sys$getgroups(ssize_t, gid_t*); + int sys$setgroups(ssize_t, const gid_t*); int sys$pipe(int* pipefd); int sys$killpg(int pgrp, int sig); int sys$setgid(gid_t); diff --git a/Kernel/SyntheticFileSystem.cpp b/Kernel/SyntheticFileSystem.cpp index bfdf6a8c8eb..51a4c52ebe9 100644 --- a/Kernel/SyntheticFileSystem.cpp +++ b/Kernel/SyntheticFileSystem.cpp @@ -112,10 +112,9 @@ bool SynthFS::remove_file(InodeIndex inode) if (pit == m_inodes.end()) return false; auto& parent = *(*pit).value; - for (size_t i = 0; i < parent.m_children.size(); ++i) { - if (parent.m_children[i]->m_metadata.inode.index() != inode) { + for (ssize_t i = 0; i < parent.m_children.size(); ++i) { + if (parent.m_children[i]->m_metadata.inode.index() != inode) continue; - } parent.m_children.remove(i); break; } @@ -193,7 +192,7 @@ InodeMetadata SynthFSInode::metadata() const return m_metadata; } -ssize_t SynthFSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileDescriptor* descriptor) const +ssize_t SynthFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescriptor* descriptor) const { LOCKER(m_lock); #ifdef SYNTHFS_DEBUG @@ -269,7 +268,7 @@ void SynthFSInode::flush_metadata() { } -ssize_t SynthFSInode::write_bytes(off_t offset, size_t size, const byte* buffer, FileDescriptor*) +ssize_t SynthFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, FileDescriptor*) { LOCKER(m_lock); if (!m_write_callback) diff --git a/Kernel/SyntheticFileSystem.h b/Kernel/SyntheticFileSystem.h index fe4b312941e..65f27e1f2ec 100644 --- a/Kernel/SyntheticFileSystem.h +++ b/Kernel/SyntheticFileSystem.h @@ -56,13 +56,13 @@ public: private: // ^Inode - virtual ssize_t read_bytes(off_t, size_t, byte* buffer, FileDescriptor*) const override; + virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescriptor*) const override; virtual InodeMetadata metadata() const override; virtual bool traverse_as_directory(Function) const override; virtual InodeIdentifier lookup(const String& name) override; virtual String reverse_lookup(InodeIdentifier) override; virtual void flush_metadata() override; - virtual ssize_t write_bytes(off_t, size_t, const byte* buffer, FileDescriptor*) override; + virtual ssize_t write_bytes(off_t, ssize_t, const byte* buffer, FileDescriptor*) override; virtual bool add_child(InodeIdentifier child_id, const String& name, byte file_type, int& error) override; virtual bool remove_child(const String& name, int& error) override; virtual RetainPtr parent() const override; diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index ecad66090d4..524ce87c4b2 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -154,9 +154,9 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2, case Syscall::SC_umask: return current->sys$umask((mode_t)arg1); case Syscall::SC_getgroups: - return current->sys$getgroups((int)arg1, (gid_t*)arg2); + return current->sys$getgroups((ssize_t)arg1, (gid_t*)arg2); case Syscall::SC_setgroups: - return current->sys$setgroups((size_t)arg1, (const gid_t*)arg2); + return current->sys$setgroups((ssize_t)arg1, (const gid_t*)arg2); case Syscall::SC_sigreturn: current->sys$sigreturn(); ASSERT_NOT_REACHED(); diff --git a/Kernel/VirtualFileSystem.cpp b/Kernel/VirtualFileSystem.cpp index a144640bb60..96a9df0849e 100644 --- a/Kernel/VirtualFileSystem.cpp +++ b/Kernel/VirtualFileSystem.cpp @@ -512,7 +512,7 @@ KResultOr VFS::resolve_path(const String& path, InodeIdentifier if (parent_id) *parent_id = crumb_id; - for (unsigned i = 0; i < parts.size(); ++i) { + for (int i = 0; i < parts.size(); ++i) { bool inode_was_root_at_head_of_loop = crumb_id.is_root_inode(); auto& part = parts[i]; if (part.is_empty()) diff --git a/LibC/grp.cpp b/LibC/grp.cpp index cd0de5f1522..700abf4fb01 100644 --- a/LibC/grp.cpp +++ b/LibC/grp.cpp @@ -107,7 +107,7 @@ next_entry: __grdb_entry->gr_gid = e_gid; __grdb_entry->gr_name = __grdb_entry->name_buffer; __grdb_entry->gr_passwd = __grdb_entry->passwd_buffer; - for (size_t i = 0; i < members.size(); ++i) { + for (ssize_t i = 0; i < members.size(); ++i) { __grdb_entry->members[i] = __grdb_entry->members_buffer[i]; strcpy(__grdb_entry->members_buffer[i], members[i].characters()); } diff --git a/LibGUI/GEventLoop.cpp b/LibGUI/GEventLoop.cpp index c1de3e52fa5..2765fc9d2fa 100644 --- a/LibGUI/GEventLoop.cpp +++ b/LibGUI/GEventLoop.cpp @@ -426,7 +426,7 @@ bool GEventLoop::wait_for_specific_event(WSAPI_ServerMessage::Type type, WSAPI_S bool success = drain_messages_from_server(); if (!success) return false; - for (size_t i = 0; i < m_unprocessed_messages.size(); ++i) { + for (ssize_t i = 0; i < m_unprocessed_messages.size(); ++i) { if (m_unprocessed_messages[i].type == type) { event = move(m_unprocessed_messages[i]); m_unprocessed_messages.remove(i); diff --git a/LibGUI/GMenu.cpp b/LibGUI/GMenu.cpp index 0a859d5978f..cb5ae39c1e3 100644 --- a/LibGUI/GMenu.cpp +++ b/LibGUI/GMenu.cpp @@ -43,14 +43,14 @@ int GMenu::realize_menu() { WSAPI_ClientMessage request; request.type = WSAPI_ClientMessage::Type::CreateMenu; - ASSERT(m_name.length() < sizeof(request.text)); + ASSERT(m_name.length() < (ssize_t)sizeof(request.text)); strcpy(request.text, m_name.characters()); request.text_length = m_name.length(); auto response = GEventLoop::main().sync_request(request, WSAPI_ServerMessage::Type::DidCreateMenu); m_menu_id = response.menu.menu_id; ASSERT(m_menu_id > 0); - for (size_t i = 0; i < m_items.size(); ++i) { + for (int i = 0; i < m_items.size(); ++i) { auto& item = *m_items[i]; if (item.type() == GMenuItem::Separator) { WSAPI_ClientMessage request; @@ -65,7 +65,7 @@ int GMenu::realize_menu() request.type = WSAPI_ClientMessage::Type::AddMenuItem; request.menu.menu_id = m_menu_id; request.menu.identifier = i; - ASSERT(action.text().length() < sizeof(request.text)); + ASSERT(action.text().length() < (ssize_t)sizeof(request.text)); strcpy(request.text, action.text().characters()); request.text_length = action.text().length(); GEventLoop::main().sync_request(request, WSAPI_ServerMessage::Type::DidAddMenuItem); @@ -87,7 +87,7 @@ void GMenu::unrealize_menu() m_menu_id = 0; } -GAction* GMenu::action_at(size_t index) +GAction* GMenu::action_at(int index) { if (index >= m_items.size()) return nullptr; diff --git a/LibGUI/GMenu.h b/LibGUI/GMenu.h index 6a93f03f0b5..7896bfe6f14 100644 --- a/LibGUI/GMenu.h +++ b/LibGUI/GMenu.h @@ -13,7 +13,7 @@ public: static GMenu* from_menu_id(int); - GAction* action_at(size_t); + GAction* action_at(int); void add_action(RetainPtr&&); void add_separator(); diff --git a/LibGUI/GObject.cpp b/LibGUI/GObject.cpp index 985d459c007..f033ec86dc4 100644 --- a/LibGUI/GObject.cpp +++ b/LibGUI/GObject.cpp @@ -43,7 +43,7 @@ void GObject::add_child(GObject& object) void GObject::remove_child(GObject& object) { - for (unsigned i = 0; i < m_children.size(); ++i) { + for (ssize_t i = 0; i < m_children.size(); ++i) { if (m_children[i] == &object) { m_children.remove(i); return; diff --git a/LibGUI/GTextBox.cpp b/LibGUI/GTextBox.cpp index fd8adbae4f6..45bdb3daeca 100644 --- a/LibGUI/GTextBox.cpp +++ b/LibGUI/GTextBox.cpp @@ -35,13 +35,13 @@ void GTextBox::paint_event(GPaintEvent&) Rect inner_rect = rect(); inner_rect.shrink(6, 6); - size_t max_chars_to_paint = inner_rect.width() / font().glyph_width(); + ssize_t max_chars_to_paint = inner_rect.width() / font().glyph_width(); int first_visible_char = max((int)m_cursor_position - (int)max_chars_to_paint, 0); - size_t chars_to_paint = min(m_text.length() - first_visible_char, max_chars_to_paint); + ssize_t chars_to_paint = min(m_text.length() - first_visible_char, max_chars_to_paint); int y = inner_rect.center().y() - font().glyph_height() / 2; - for (size_t i = 0; i < chars_to_paint; ++i) { + for (ssize_t i = 0; i < chars_to_paint; ++i) { char ch = m_text[first_visible_char + i]; if (ch == ' ') continue; diff --git a/LibGUI/GTextBox.h b/LibGUI/GTextBox.h index 8c203155acd..ed14745b934 100644 --- a/LibGUI/GTextBox.h +++ b/LibGUI/GTextBox.h @@ -27,7 +27,7 @@ private: void handle_backspace(); String m_text; - unsigned m_cursor_position { 0 }; + int m_cursor_position { 0 }; bool m_cursor_blink_state { false }; }; diff --git a/LibGUI/GWindow.cpp b/LibGUI/GWindow.cpp index 75bfc71ccb6..18d08c1c849 100644 --- a/LibGUI/GWindow.cpp +++ b/LibGUI/GWindow.cpp @@ -63,7 +63,7 @@ void GWindow::show() request.window.opacity = m_opacity_when_windowless; request.window.size_increment = m_size_increment; request.window.base_size = m_base_size; - ASSERT(m_title_when_windowless.length() < sizeof(request.text)); + ASSERT(m_title_when_windowless.length() < (ssize_t)sizeof(request.text)); strcpy(request.text, m_title_when_windowless.characters()); request.text_length = m_title_when_windowless.length(); auto response = GEventLoop::main().sync_request(request, WSAPI_ServerMessage::Type::DidCreateWindow); @@ -81,9 +81,6 @@ void GWindow::hide() WSAPI_ClientMessage request; request.type = WSAPI_ClientMessage::Type::DestroyWindow; request.window_id = m_window_id; - ASSERT(m_title_when_windowless.length() < sizeof(request.text)); - strcpy(request.text, m_title_when_windowless.characters()); - request.text_length = m_title_when_windowless.length(); GEventLoop::main().post_message_to_server(request); } @@ -96,7 +93,7 @@ void GWindow::set_title(String&& title) WSAPI_ClientMessage request; request.type = WSAPI_ClientMessage::Type::SetWindowTitle; request.window_id = m_window_id; - ASSERT(m_title_when_windowless.length() < sizeof(request.text)); + ASSERT(m_title_when_windowless.length() < (ssize_t)sizeof(request.text)); strcpy(request.text, m_title_when_windowless.characters()); request.text_length = m_title_when_windowless.length(); GEventLoop::main().post_message_to_server(request); @@ -110,9 +107,6 @@ String GWindow::title() const WSAPI_ClientMessage request; request.type = WSAPI_ClientMessage::Type::GetWindowTitle; request.window_id = m_window_id; - ASSERT(m_title_when_windowless.length() < sizeof(request.text)); - strcpy(request.text, m_title_when_windowless.characters()); - request.text_length = m_title_when_windowless.length(); auto response = GEventLoop::main().sync_request(request, WSAPI_ServerMessage::Type::DidGetWindowTitle); return String(response.text, response.text_length); } diff --git a/SharedGraphics/DisjointRectSet.cpp b/SharedGraphics/DisjointRectSet.cpp index 4966984c359..a811899d769 100644 --- a/SharedGraphics/DisjointRectSet.cpp +++ b/SharedGraphics/DisjointRectSet.cpp @@ -20,9 +20,9 @@ void DisjointRectSet::shatter() do { pass_had_intersections = false; output.clear_with_capacity(); - for (size_t i = 0; i < m_rects.size(); ++i) { + for (int i = 0; i < m_rects.size(); ++i) { auto& r1 = m_rects[i]; - for (size_t j = 0; j < m_rects.size(); ++j) { + for (int j = 0; j < m_rects.size(); ++j) { if (i == j) continue; auto& r2 = m_rects[j]; diff --git a/SharedGraphics/Font.cpp b/SharedGraphics/Font.cpp index 3b68b6d6f63..2b60ca05aec 100644 --- a/SharedGraphics/Font.cpp +++ b/SharedGraphics/Font.cpp @@ -120,7 +120,7 @@ bool Font::write_to_file(const String& path) header.glyph_width = m_glyph_width; header.glyph_height = m_glyph_height; header.type = 0; - memcpy(header.name, m_name.characters(), min(m_name.length(), (size_t)63)); + memcpy(header.name, m_name.characters(), min(m_name.length(), 63)); size_t bytes_per_glyph = sizeof(unsigned) * m_glyph_height; diff --git a/SharedGraphics/Painter.cpp b/SharedGraphics/Painter.cpp index d2796682b91..f6c1c2e00bc 100644 --- a/SharedGraphics/Painter.cpp +++ b/SharedGraphics/Painter.cpp @@ -336,7 +336,7 @@ void Painter::draw_text(const Rect& rect, const String& text, TextAlignment alig ASSERT_NOT_REACHED(); } - for (unsigned i = 0; i < text.length(); ++i, point.move_by(font().glyph_width(), 0)) { + for (ssize_t i = 0; i < text.length(); ++i, point.move_by(font().glyph_width(), 0)) { byte ch = text[i]; if (ch == ' ') continue; diff --git a/Userland/df.cpp b/Userland/df.cpp index bce2e2268ab..62572921aab 100644 --- a/Userland/df.cpp +++ b/Userland/df.cpp @@ -42,6 +42,9 @@ int main(int, char**) ASSERT(ok); String mount_point = parts[5]; + (void)total_inode_count; + (void)free_inode_count; + printf("% 10s", fs.characters()); printf("%10u ", total_block_count); printf("%10u ", total_block_count - free_block_count); diff --git a/Userland/kill.cpp b/Userland/kill.cpp index 3f1bb0248ab..dba82068c1e 100644 --- a/Userland/kill.cpp +++ b/Userland/kill.cpp @@ -11,13 +11,13 @@ static unsigned parse_uint(const String& str, bool& ok) return 0; } unsigned value = 0; - for (size_t i = 0; i < str.length(); ++i) { + for (int i = 0; i < str.length(); ++i) { if (str[i] < '0' || str[i] > '9') { ok = false; return 0; } value = value * 10; - value += str[i] - '0'; + value += (unsigned)(str[i] - '0'); } ok = true; return value; diff --git a/Userland/ls.cpp b/Userland/ls.cpp index ed1c48e855b..4b9560562cc 100644 --- a/Userland/ls.cpp +++ b/Userland/ls.cpp @@ -55,7 +55,7 @@ int main(int argc, char** argv) return do_dir_short(path); } -void get_geometry(unsigned& rows, unsigned& columns) +void get_geometry(int& rows, int& columns) { struct winsize ws; ioctl(0, TIOCGWINSZ, &ws); @@ -187,8 +187,8 @@ int do_dir(const char* path) int do_dir_short(const char* path) { - unsigned rows; - unsigned columns; + int rows; + int columns; get_geometry(rows, columns); DIR* dirp = opendir(path); @@ -198,7 +198,7 @@ int do_dir_short(const char* path) } Vector names; - size_t longest_name = 0; + int longest_name = 0; while (auto* de = readdir(dirp)) { if (de->d_name[0] == '.' && !flag_show_dotfiles) continue; @@ -210,7 +210,7 @@ int do_dir_short(const char* path) int printed_on_row = 0; - for (size_t i = 0; i < names.size(); ++i) { + for (int i = 0; i < names.size(); ++i) { auto& name = names[i]; struct stat st; char pathbuf[256]; @@ -221,11 +221,11 @@ int do_dir_short(const char* path) return 2; } - unsigned nprinted = print_name(st, name.characters()); - unsigned column_width = 14; + int nprinted = print_name(st, name.characters()); + int column_width = 14; printed_on_row += column_width; - for (unsigned i = nprinted; i < column_width; ++i) + for (int i = nprinted; i < column_width; ++i) printf(" "); if ((printed_on_row + column_width) >= columns) { if (i != names.size() - 1) diff --git a/Userland/sleep.cpp b/Userland/sleep.cpp index 1a44e9b0278..dba5f1874a8 100644 --- a/Userland/sleep.cpp +++ b/Userland/sleep.cpp @@ -6,7 +6,7 @@ static unsigned parse_uint(const String& str, bool& ok) { unsigned value = 0; - for (size_t i = 0; i < str.length(); ++i) { + for (int i = 0; i < str.length(); ++i) { if (str[i] < '0' || str[i] > '9') { ok = false; return 0; diff --git a/WindowServer/WSAPITypes.h b/WindowServer/WSAPITypes.h index 9cd0fea2d88..9084190ad7f 100644 --- a/WindowServer/WSAPITypes.h +++ b/WindowServer/WSAPITypes.h @@ -88,7 +88,7 @@ struct WSAPI_ServerMessage { }; Type type { Invalid }; int window_id { -1 }; - size_t text_length; + int text_length { 0 }; char text[256]; union { @@ -156,7 +156,7 @@ struct WSAPI_ClientMessage { }; Type type { Invalid }; int window_id { -1 }; - size_t text_length; + int text_length { 0 }; char text[256]; int value { 0 }; diff --git a/WindowServer/WSClientConnection.cpp b/WindowServer/WSClientConnection.cpp index da599719958..ffb2e6856ac 100644 --- a/WindowServer/WSClientConnection.cpp +++ b/WindowServer/WSClientConnection.cpp @@ -63,7 +63,7 @@ void WSClientConnection::post_error(const String& error_message) dbgprintf("WSClientConnection::post_error: client_id=%d: %s\n", m_client_id, error_message.characters()); WSAPI_ServerMessage message; message.type = WSAPI_ServerMessage::Type::Error; - ASSERT(error_message.length() < sizeof(message.text)); + ASSERT(error_message.length() < (ssize_t)sizeof(message.text)); strcpy(message.text, error_message.characters()); message.text_length = error_message.length(); post_message(message); @@ -277,7 +277,7 @@ void WSClientConnection::handle_request(WSAPIGetWindowTitleRequest& request) WSAPI_ServerMessage response; response.type = WSAPI_ServerMessage::Type::DidGetWindowTitle; response.window_id = window.window_id(); - ASSERT(window.title().length() < sizeof(response.text)); + ASSERT(window.title().length() < (ssize_t)sizeof(response.text)); strcpy(response.text, window.title().characters()); response.text_length = window.title().length(); post_message(response); diff --git a/WindowServer/WSMessageLoop.cpp b/WindowServer/WSMessageLoop.cpp index f189e733544..0f13468812f 100644 --- a/WindowServer/WSMessageLoop.cpp +++ b/WindowServer/WSMessageLoop.cpp @@ -290,29 +290,29 @@ void WSMessageLoop::on_receive_from_client(int client_id, const WSAPI_ClientMess post_message(client, make(client_id, message.menu.menubar_id, message.menu.menu_id)); break; case WSAPI_ClientMessage::Type::CreateMenu: - ASSERT(message.text_length < sizeof(message.text)); + ASSERT(message.text_length < (ssize_t)sizeof(message.text)); post_message(client, make(client_id, String(message.text, message.text_length))); break; case WSAPI_ClientMessage::Type::DestroyMenu: post_message(client, make(client_id, message.menu.menu_id)); break; case WSAPI_ClientMessage::Type::AddMenuItem: - ASSERT(message.text_length < sizeof(message.text)); + ASSERT(message.text_length < (ssize_t)sizeof(message.text)); post_message(client, make(client_id, message.menu.menu_id, message.menu.identifier, String(message.text, message.text_length))); break; case WSAPI_ClientMessage::Type::CreateWindow: - ASSERT(message.text_length < sizeof(message.text)); + ASSERT(message.text_length < (ssize_t)sizeof(message.text)); post_message(client, make(client_id, message.window.rect, String(message.text, message.text_length), message.window.has_alpha_channel, message.window.opacity, message.window.base_size, message.window.size_increment)); break; case WSAPI_ClientMessage::Type::DestroyWindow: post_message(client, make(client_id, message.window_id)); break; case WSAPI_ClientMessage::Type::SetWindowTitle: - ASSERT(message.text_length < sizeof(message.text)); + ASSERT(message.text_length < (ssize_t)sizeof(message.text)); post_message(client, make(client_id, message.window_id, String(message.text, message.text_length))); break; case WSAPI_ClientMessage::Type::GetWindowTitle: - ASSERT(message.text_length < sizeof(message.text)); + ASSERT(message.text_length < (ssize_t)sizeof(message.text)); post_message(client, make(client_id, message.window_id)); break; case WSAPI_ClientMessage::Type::SetWindowRect: