From 22feb9d47b9c6d6fcd73ed90243c3e30cea7842a Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 6 Nov 2021 14:12:16 -0600 Subject: [PATCH] AK: Resolve clang-tidy readability-bool-conversion warnings ... In files included by Kernel/Process.cpp and Kernel/Thread.cpp --- AK/Bitmap.h | 2 +- AK/BitmapView.h | 6 +++--- AK/ByteBuffer.h | 2 +- AK/CircularQueue.h | 2 +- AK/HashTable.h | 2 +- AK/StringImpl.h | 2 +- AK/StringView.h | 10 +++++----- AK/Time.h | 4 ++-- AK/TypedTransfer.h | 8 +++----- AK/Userspace.h | 5 ++++- AK/Vector.h | 6 +++--- AK/Weakable.h | 2 +- 12 files changed, 26 insertions(+), 25 deletions(-) diff --git a/AK/Bitmap.h b/AK/Bitmap.h index cb21ea16d7a..a84a33c83e4 100644 --- a/AK/Bitmap.h +++ b/AK/Bitmap.h @@ -91,7 +91,7 @@ public: if (previous_data != nullptr) { __builtin_memcpy(m_data, previous_data, previous_size_bytes); - if (previous_size % 8) + if ((previous_size % 8) != 0) set_range(previous_size, 8 - previous_size % 8, default_value); kfree_sized(previous_data, previous_size_bytes); } diff --git a/AK/BitmapView.h b/AK/BitmapView.h index 3bd155e664b..39ed76ead0e 100644 --- a/AK/BitmapView.h +++ b/AK/BitmapView.h @@ -86,7 +86,7 @@ public: return count; } - [[nodiscard]] bool is_null() const { return !m_data; } + [[nodiscard]] bool is_null() const { return m_data == nullptr; } [[nodiscard]] const u8* data() const { return m_data; } @@ -279,7 +279,7 @@ public: size_t trailing_bits = size() % 32; for (size_t i = 0; i < trailing_bits; ++i) { if (!get(first_trailing_bit + i)) { - if (!free_chunks) + if (free_chunks == 0) *start_of_free_chunks = first_trailing_bit + i; if (++free_chunks >= min_length) return min(free_chunks, max_length); @@ -313,7 +313,7 @@ public: } found_range_size = max_region_size; - if (max_region_size) { + if (max_region_size != 0) { return max_region_start; } return {}; diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h index 416e4d0594b..5387eab9956 100644 --- a/AK/ByteBuffer.h +++ b/AK/ByteBuffer.h @@ -118,7 +118,7 @@ public: return data()[i]; } - [[nodiscard]] bool is_empty() const { return !m_size; } + [[nodiscard]] bool is_empty() const { return m_size == 0; } [[nodiscard]] size_t size() const { return m_size; } [[nodiscard]] u8* data() { return m_inline ? m_inline_buffer : m_outline_buffer; } diff --git a/AK/CircularQueue.h b/AK/CircularQueue.h index 8d996c972b5..8c9a835b615 100644 --- a/AK/CircularQueue.h +++ b/AK/CircularQueue.h @@ -33,7 +33,7 @@ public: m_size = 0; } - bool is_empty() const { return !m_size; } + bool is_empty() const { return m_size == 0; } size_t size() const { return m_size; } size_t capacity() const { return Capacity; } diff --git a/AK/HashTable.h b/AK/HashTable.h index 52a9a6a0606..a9fe6f97597 100644 --- a/AK/HashTable.h +++ b/AK/HashTable.h @@ -181,7 +181,7 @@ public: swap(a.m_collection_data, b.m_collection_data); } - [[nodiscard]] bool is_empty() const { return !m_size; } + [[nodiscard]] bool is_empty() const { return m_size == 0; } [[nodiscard]] size_t size() const { return m_size; } [[nodiscard]] size_t capacity() const { return m_capacity; } diff --git a/AK/StringImpl.h b/AK/StringImpl.h index 6e07c06919c..079e11825d3 100644 --- a/AK/StringImpl.h +++ b/AK/StringImpl.h @@ -60,7 +60,7 @@ public: { if (length() != other.length()) return false; - return !__builtin_memcmp(characters(), other.characters(), length()); + return __builtin_memcmp(characters(), other.characters(), length()) == 0; } unsigned hash() const diff --git a/AK/StringView.h b/AK/StringView.h index 7a8fdd6edef..f03b07c385e 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -52,7 +52,7 @@ public: explicit StringView(String&&) = delete; explicit StringView(FlyString&&) = delete; - [[nodiscard]] constexpr bool is_null() const { return !m_characters; } + [[nodiscard]] constexpr bool is_null() const { return m_characters == nullptr; } [[nodiscard]] constexpr bool is_empty() const { return m_length == 0; } [[nodiscard]] constexpr char const* characters_without_null_termination() const { return m_characters; } @@ -151,18 +151,18 @@ public: constexpr bool operator==(const char* cstring) const { if (is_null()) - return !cstring; + return cstring == nullptr; if (!cstring) return false; // NOTE: `m_characters` is not guaranteed to be null-terminated, but `cstring` is. const char* cp = cstring; for (size_t i = 0; i < m_length; ++i) { - if (!*cp) + if (*cp == '\0') return false; if (m_characters[i] != *(cp++)) return false; } - return !*cp; + return *cp == '\0'; } constexpr bool operator!=(const char* cstring) const @@ -180,7 +180,7 @@ public: return false; if (length() != other.length()) return false; - return !__builtin_memcmp(m_characters, other.m_characters, m_length); + return __builtin_memcmp(m_characters, other.m_characters, m_length) == 0; } constexpr bool operator!=(StringView other) const diff --git a/AK/Time.h b/AK/Time.h index 7995dfb2a41..29fb458e31c 100644 --- a/AK/Time.h +++ b/AK/Time.h @@ -50,7 +50,7 @@ inline bool is_leap_year(int year) inline int days_in_year(int year) { - return 365 + is_leap_year(year); + return 365 + (is_leap_year(year) ? 1 : 0); } inline int years_to_days_since_epoch(int year) @@ -163,7 +163,7 @@ public: // Rounds towards -inf (it was the easiest to implement). [[nodiscard]] timeval to_timeval() const; - [[nodiscard]] bool is_zero() const { return !m_seconds && !m_nanoseconds; } + [[nodiscard]] bool is_zero() const { return (m_seconds == 0) && (m_nanoseconds == 0); } [[nodiscard]] bool is_negative() const { return m_seconds < 0; } bool operator==(const Time& other) const { return this->m_seconds == other.m_seconds && this->m_nanoseconds == other.m_nanoseconds; } diff --git a/AK/TypedTransfer.h b/AK/TypedTransfer.h index 96325aa5281..91045a9da95 100644 --- a/AK/TypedTransfer.h +++ b/AK/TypedTransfer.h @@ -15,7 +15,7 @@ class TypedTransfer { public: static void move(T* destination, T* source, size_t count) { - if (!count) + if (count == 0) return; if constexpr (Traits::is_trivial()) { @@ -29,13 +29,11 @@ public: else new (&destination[count - i - 1]) T(std::move(source[count - i - 1])); } - - return; } static size_t copy(T* destination, const T* source, size_t count) { - if (!count) + if (count == 0) return 0; if constexpr (Traits::is_trivial()) { @@ -55,7 +53,7 @@ public: static bool compare(const T* a, const T* b, size_t count) { - if (!count) + if (count == 0) return true; if constexpr (Traits::is_trivial()) diff --git a/AK/Userspace.h b/AK/Userspace.h index 04bc1236541..8d99a541725 100644 --- a/AK/Userspace.h +++ b/AK/Userspace.h @@ -20,7 +20,6 @@ class Userspace { public: Userspace() = default; - operator bool() const { return m_ptr; } operator FlatPtr() const { return (FlatPtr)m_ptr; } // Disable default implementations that would use surprising integer promotion. @@ -36,6 +35,8 @@ public: { } + explicit operator bool() const { return m_ptr != 0; } + FlatPtr ptr() const { return m_ptr; } T unsafe_userspace_ptr() const { return (T)m_ptr; } #else @@ -44,6 +45,8 @@ public: { } + explicit operator bool() const { return m_ptr != nullptr; } + T ptr() const { return m_ptr; } #endif diff --git a/AK/Vector.h b/AK/Vector.h index dcb7beed200..22749d61222 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -520,7 +520,7 @@ public: ErrorOr try_append(StorageType const* values, size_t count) { - if (!count) + if (count == 0) return {}; TRY(try_grow_capacity(size() + count)); TypedTransfer::copy(slot(m_size), values, count); @@ -569,7 +569,7 @@ public: ErrorOr try_prepend(StorageType const* values, size_t count) { - if (!count) + if (count == 0) return {}; TRY(try_grow_capacity(size() + count)); TypedTransfer::move(slot(count), slot(0), m_size); @@ -645,7 +645,7 @@ public: if (new_size == size()) return; - if (!new_size) { + if (new_size == 0) { if (keep_capacity) clear_with_capacity(); else diff --git a/AK/Weakable.h b/AK/Weakable.h index 5a98b24a62d..f74b47f77e8 100644 --- a/AK/Weakable.h +++ b/AK/Weakable.h @@ -66,7 +66,7 @@ public: bool is_null() const { - return !unsafe_ptr(); + return unsafe_ptr() == nullptr; } void revoke()