mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 03:22:43 +00:00 
			
		
		
		
	More moving towards using signed types.
I'm still feeling this out, but I am starting to like the general idea.
This commit is contained in:
		
							parent
							
								
									beda478821
								
							
						
					
					
						commit
						9624b54703
					
				
					 48 changed files with 234 additions and 250 deletions
				
			
		|  | @ -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<String> 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); } | ||||
|  |  | |||
							
								
								
									
										18
									
								
								AK/Bitmap.h
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								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<byte*>(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 }; | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										46
									
								
								AK/Buffer.h
									
										
									
									
									
								
							
							
						
						
									
										46
									
								
								AK/Buffer.h
									
										
									
									
									
								
							|  | @ -11,10 +11,10 @@ namespace AK { | |||
| template<typename T> | ||||
| class Buffer : public Retainable<Buffer<T>> { | ||||
| public: | ||||
|     static Retained<Buffer> create_uninitialized(size_t count); | ||||
|     static Retained<Buffer> copy(const T*, size_t count); | ||||
|     static Retained<Buffer> wrap(T*, size_t count); | ||||
|     static Retained<Buffer> adopt(T*, size_t count); | ||||
|     static Retained<Buffer> create_uninitialized(ssize_t count); | ||||
|     static Retained<Buffer> copy(const T*, ssize_t count); | ||||
|     static Retained<Buffer> wrap(T*, ssize_t count); | ||||
|     static Retained<Buffer> 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<typename T> | ||||
| inline Buffer<T>::Buffer(size_t size) | ||||
| inline Buffer<T>::Buffer(ssize_t size) | ||||
|     : m_size(size) | ||||
| { | ||||
|     m_elements = static_cast<T*>(kmalloc(size * sizeof(T))); | ||||
|  | @ -70,7 +70,7 @@ inline Buffer<T>::Buffer(size_t size) | |||
| } | ||||
| 
 | ||||
| template<typename T> | ||||
| inline Buffer<T>::Buffer(const T* elements, size_t size, ConstructionMode mode) | ||||
| inline Buffer<T>::Buffer(const T* elements, ssize_t size, ConstructionMode mode) | ||||
|     : m_size(size) | ||||
| { | ||||
|     ASSERT(mode == Copy); | ||||
|  | @ -80,7 +80,7 @@ inline Buffer<T>::Buffer(const T* elements, size_t size, ConstructionMode mode) | |||
| } | ||||
| 
 | ||||
| template<typename T> | ||||
| inline Buffer<T>::Buffer(T* elements, size_t size, ConstructionMode mode) | ||||
| inline Buffer<T>::Buffer(T* elements, ssize_t size, ConstructionMode mode) | ||||
|     : m_elements(elements) | ||||
|     , m_size(size) | ||||
| { | ||||
|  | @ -92,7 +92,7 @@ inline Buffer<T>::Buffer(T* elements, size_t size, ConstructionMode mode) | |||
| } | ||||
| 
 | ||||
| template<typename T> | ||||
| inline void Buffer<T>::grow(size_t size) | ||||
| inline void Buffer<T>::grow(ssize_t size) | ||||
| { | ||||
|     ASSERT(size > m_size); | ||||
|     ASSERT(m_owned); | ||||
|  | @ -105,25 +105,25 @@ inline void Buffer<T>::grow(size_t size) | |||
| } | ||||
| 
 | ||||
| template<typename T> | ||||
| inline Retained<Buffer<T>> Buffer<T>::create_uninitialized(size_t size) | ||||
| inline Retained<Buffer<T>> Buffer<T>::create_uninitialized(ssize_t size) | ||||
| { | ||||
|     return ::adopt(*new Buffer<T>(size)); | ||||
| } | ||||
| 
 | ||||
| template<typename T> | ||||
| inline Retained<Buffer<T>> Buffer<T>::copy(const T* elements, size_t size) | ||||
| inline Retained<Buffer<T>> Buffer<T>::copy(const T* elements, ssize_t size) | ||||
| { | ||||
|     return ::adopt(*new Buffer<T>(elements, size, Copy)); | ||||
| } | ||||
| 
 | ||||
| template<typename T> | ||||
| inline Retained<Buffer<T>> Buffer<T>::wrap(T* elements, size_t size) | ||||
| inline Retained<Buffer<T>> Buffer<T>::wrap(T* elements, ssize_t size) | ||||
| { | ||||
|     return ::adopt(*new Buffer<T>(elements, size, Wrap)); | ||||
| } | ||||
| 
 | ||||
| template<typename T> | ||||
| inline Retained<Buffer<T>> Buffer<T>::adopt(T* elements, size_t size) | ||||
| inline Retained<Buffer<T>> Buffer<T>::adopt(T* elements, ssize_t size) | ||||
| { | ||||
|     return ::adopt(*new Buffer<T>(elements, size, Adopt)); | ||||
| } | ||||
|  |  | |||
|  | @ -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 }; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -30,10 +30,10 @@ public: | |||
|         return *this; | ||||
|     } | ||||
| 
 | ||||
|     static ByteBuffer create_uninitialized(size_t size) { return ByteBuffer(Buffer<byte>::create_uninitialized(size)); } | ||||
|     static ByteBuffer copy(const byte* data, size_t size) { return ByteBuffer(Buffer<byte>::copy(data, size)); } | ||||
|     static ByteBuffer wrap(byte* data, size_t size) { return ByteBuffer(Buffer<byte>::wrap(data, size)); } | ||||
|     static ByteBuffer adopt(byte* data, size_t size) { return ByteBuffer(Buffer<byte>::adopt(data, size)); } | ||||
|     static ByteBuffer create_uninitialized(ssize_t size) { return ByteBuffer(Buffer<byte>::create_uninitialized(size)); } | ||||
|     static ByteBuffer copy(const byte* data, ssize_t size) { return ByteBuffer(Buffer<byte>::copy(data, size)); } | ||||
|     static ByteBuffer wrap(byte* data, ssize_t size) { return ByteBuffer(Buffer<byte>::wrap(data, size)); } | ||||
|     static ByteBuffer adopt(byte* data, ssize_t size) { return ByteBuffer(Buffer<byte>::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<byte>::create_uninitialized(size); | ||||
|  |  | |||
|  | @ -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> String::split(const char separator) const | |||
|         return { }; | ||||
| 
 | ||||
|     Vector<String> 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; | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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 }; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -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> StringImpl::create_uninitialized(size_t length, char*& buffer) | ||||
| Retained<StringImpl> StringImpl::create_uninitialized(ssize_t length, char*& buffer) | ||||
| { | ||||
|     ASSERT(length); | ||||
|     void* slot = kmalloc(allocation_size_for_stringimpl(length)); | ||||
|  | @ -66,7 +66,7 @@ Retained<StringImpl> StringImpl::create_uninitialized(size_t length, char*& buff | |||
|     return new_stringimpl; | ||||
| } | ||||
| 
 | ||||
| RetainPtr<StringImpl> StringImpl::create(const char* cstring, size_t length, ShouldChomp shouldChomp) | ||||
| RetainPtr<StringImpl> 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> 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> 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> 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> 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); | ||||
|  |  | |||
|  | @ -10,9 +10,9 @@ enum ShouldChomp { NoChomp, Chomp }; | |||
| 
 | ||||
| class StringImpl : public Retainable<StringImpl> { | ||||
| public: | ||||
|     static Retained<StringImpl> create_uninitialized(size_t length, char*& buffer); | ||||
|     static Retained<StringImpl> create_uninitialized(ssize_t length, char*& buffer); | ||||
|     static RetainPtr<StringImpl> create(const char* cstring, ShouldChomp = NoChomp); | ||||
|     static RetainPtr<StringImpl> create(const char* cstring, size_t length, ShouldChomp = NoChomp); | ||||
|     static RetainPtr<StringImpl> create(const char* cstring, ssize_t length, ShouldChomp = NoChomp); | ||||
|     Retained<StringImpl> to_lowercase() const; | ||||
|     Retained<StringImpl> 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 }; | ||||
|  |  | |||
							
								
								
									
										78
									
								
								AK/Vector.h
									
										
									
									
									
								
							
							
						
						
									
										78
									
								
								AK/Vector.h
									
										
									
									
									
								
							|  | @ -9,12 +9,12 @@ namespace AK { | |||
| template<typename T, typename Allocator> 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<typename T, typename Allocator> | |||
| 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<T, Allocator>; | ||||
| 
 | ||||
|     VectorImpl(size_t capacity) : m_capacity(capacity) { } | ||||
|     VectorImpl(ssize_t capacity) : m_capacity(capacity) { } | ||||
| 
 | ||||
|     T* tail() { return reinterpret_cast<T*>(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<const T*>(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<typename T, typename Allocator = KmallocAllocator> | ||||
|  | @ -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<T, Allocator>::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<T, Allocator>* m_impl { nullptr }; | ||||
|  |  | |||
|  | @ -138,7 +138,7 @@ void DirectoryView::paint_event(GPaintEvent&) | |||
|     int painted_item_index = 0; | ||||
| 
 | ||||
|     auto process_entries = [&] (const Vector<Entry>& 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()); | ||||
|  |  | |||
|  | @ -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]; | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -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("))"); | ||||
|  |  | |||
|  | @ -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<DiskDevice>&&); | ||||
|  | @ -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<DiskDevice> m_device; | ||||
| }; | ||||
|  |  | |||
|  | @ -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<Inode> 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<off_t>(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<size_t>(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, Vector<DirectoryEntr | |||
|     LOCKER(m_lock); | ||||
|     dbgprintf("Ext2FS: New directory inode %u contents to write:\n", directoryInode); | ||||
| 
 | ||||
|     unsigned directory_size = 0; | ||||
|     int directory_size = 0; | ||||
|     for (auto& entry : entries) { | ||||
|         //kprintf("  - %08u %s\n", entry.inode.index(), entry.name);
 | ||||
|         directory_size += EXT2_DIR_REC_LEN(entry.name_length); | ||||
|     } | ||||
| 
 | ||||
|     unsigned blocks_needed = ceil_div(directory_size, block_size()); | ||||
|     unsigned occupied_size = blocks_needed * block_size(); | ||||
|     int blocks_needed = ceil_div(directory_size, block_size()); | ||||
|     int occupied_size = blocks_needed * block_size(); | ||||
| 
 | ||||
|     dbgprintf("Ext2FS: directory size: %u (occupied: %u)\n", directory_size, occupied_size); | ||||
| 
 | ||||
|     auto directory_data = ByteBuffer::create_uninitialized(occupied_size); | ||||
| 
 | ||||
|     BufferStream stream(directory_data); | ||||
|     for (unsigned i = 0; i < entries.size(); ++i) { | ||||
|     for (int i = 0; i < entries.size(); ++i) { | ||||
|         auto& entry = entries[i]; | ||||
| 
 | ||||
|         unsigned record_length = EXT2_DIR_REC_LEN(entry.name_length); | ||||
|         int record_length = EXT2_DIR_REC_LEN(entry.name_length); | ||||
|         if (i == entries.size() - 1) | ||||
|             record_length += occupied_size - directory_size; | ||||
| 
 | ||||
|  | @ -735,27 +735,13 @@ bool Ext2FS::write_directory_inode(unsigned directoryInode, Vector<DirectoryEntr | |||
|         stream << byte(entry.file_type); | ||||
|         stream << entry.name; | ||||
| 
 | ||||
|         unsigned padding = record_length - entry.name_length - 8; | ||||
|         //dbgprintf("  *** pad %u bytes\n", padding);
 | ||||
|         for (unsigned j = 0; j < padding; ++j) { | ||||
|         int padding = record_length - entry.name_length - 8; | ||||
|         for (int j = 0; j < padding; ++j) | ||||
|             stream << byte(0); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     stream.fill_to_end(0); | ||||
| 
 | ||||
| #if 0 | ||||
|     kprintf("data to write (%u):\n", directory_data.size()); | ||||
|     for (unsigned i = 0; i < directory_data.size(); ++i) { | ||||
|         kprintf("%02x ", directory_data[i]); | ||||
|         if ((i + 1) % 8 == 0) | ||||
|             kprintf(" "); | ||||
|         if ((i + 1) % 16 == 0) | ||||
|             kprintf("\n"); | ||||
|     } | ||||
|     kprintf("\n"); | ||||
| #endif | ||||
| 
 | ||||
|     auto directory_inode = get_inode({ fsid(), directoryInode }); | ||||
|     ssize_t nwritten = directory_inode->write_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::BlockIndex> Ext2FS::allocate_blocks(unsigned group, unsigned coun | |||
|     // FIXME: Implement a scan that finds consecutive blocks if possible.
 | ||||
|     Vector<BlockIndex> 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); | ||||
|  |  | |||
|  | @ -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<bool(const FS::DirectoryEntry&)>) 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<Inode> parent() const override; | ||||
|  |  | |||
|  | @ -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<Inode>(), offset, size, data); | ||||
|  |  | |||
|  | @ -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<bool(const FS::DirectoryEntry&)>) 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<Inode> 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; | ||||
|  |  | |||
|  | @ -791,6 +791,7 @@ void VMObject::for_each_region(Callback callback) | |||
| 
 | ||||
| void VMObject::inode_size_changed(Badge<Inode>, 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<Inode>, size_t old_size, size_t new_size | |||
|     }); | ||||
| } | ||||
| 
 | ||||
| void VMObject::inode_contents_changed(Badge<Inode>, off_t offset, size_t size, const byte* data) | ||||
| void VMObject::inode_contents_changed(Badge<Inode>, off_t offset, ssize_t size, const byte* data) | ||||
| { | ||||
|     (void)size; | ||||
|     (void)data; | ||||
|  |  | |||
|  | @ -107,7 +107,7 @@ public: | |||
|     const Vector<RetainPtr<PhysicalPage>>& physical_pages() const { return m_physical_pages; } | ||||
|     Vector<RetainPtr<PhysicalPage>>& physical_pages() { return m_physical_pages; } | ||||
| 
 | ||||
|     void inode_contents_changed(Badge<Inode>, off_t, size_t, const byte*); | ||||
|     void inode_contents_changed(Badge<Inode>, off_t, ssize_t, const byte*); | ||||
|     void inode_size_changed(Badge<Inode>, size_t old_size, size_t new_size); | ||||
| 
 | ||||
|     size_t size() const { return m_size; } | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
|  | @ -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<bool(const FS::DirectoryEntry&)>) 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<Inode> parent() const override; | ||||
|  |  | |||
|  | @ -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<String> arguments, Vector<String> 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<String> arguments, Vector<String> 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; | ||||
| } | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
|  | @ -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<bool(const FS::DirectoryEntry&)>) 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<Inode> parent() const override; | ||||
|  |  | |||
|  | @ -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(); | ||||
|  |  | |||
|  | @ -512,7 +512,7 @@ KResultOr<InodeIdentifier> 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()) | ||||
|  |  | |||
|  | @ -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()); | ||||
|     } | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ public: | |||
| 
 | ||||
|     static GMenu* from_menu_id(int); | ||||
| 
 | ||||
|     GAction* action_at(size_t); | ||||
|     GAction* action_at(int); | ||||
| 
 | ||||
|     void add_action(RetainPtr<GAction>&&); | ||||
|     void add_separator(); | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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 }; | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -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); | ||||
| } | ||||
|  |  | |||
|  | @ -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]; | ||||
|  |  | |||
|  | @ -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; | ||||
| 
 | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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<String> 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) | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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 }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -290,29 +290,29 @@ void WSMessageLoop::on_receive_from_client(int client_id, const WSAPI_ClientMess | |||
|         post_message(client, make<WSAPIAddMenuToMenubarRequest>(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<WSAPICreateMenuRequest>(client_id, String(message.text, message.text_length))); | ||||
|         break; | ||||
|     case WSAPI_ClientMessage::Type::DestroyMenu: | ||||
|         post_message(client, make<WSAPIDestroyMenuRequest>(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<WSAPIAddMenuItemRequest>(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<WSAPICreateWindowRequest>(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<WSAPIDestroyWindowRequest>(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<WSAPISetWindowTitleRequest>(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<WSAPIGetWindowTitleRequest>(client_id, message.window_id)); | ||||
|         break; | ||||
|     case WSAPI_ClientMessage::Type::SetWindowRect: | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling