diff options
author | Andrew Kaster <akaster@serenityos.org> | 2021-11-06 14:12:16 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-14 22:52:35 +0100 |
commit | 22feb9d47b9c6d6fcd73ed90243c3e30cea7842a (patch) | |
tree | 9891a404af45ac33d1bc70b9ccc3b2aae0986d3c /AK | |
parent | 10d0cac73c84fc065c43326a813a16a970046ac9 (diff) | |
download | serenity-22feb9d47b9c6d6fcd73ed90243c3e30cea7842a.zip |
AK: Resolve clang-tidy readability-bool-conversion warnings
... In files included by Kernel/Process.cpp and Kernel/Thread.cpp
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Bitmap.h | 2 | ||||
-rw-r--r-- | AK/BitmapView.h | 6 | ||||
-rw-r--r-- | AK/ByteBuffer.h | 2 | ||||
-rw-r--r-- | AK/CircularQueue.h | 2 | ||||
-rw-r--r-- | AK/HashTable.h | 2 | ||||
-rw-r--r-- | AK/StringImpl.h | 2 | ||||
-rw-r--r-- | AK/StringView.h | 10 | ||||
-rw-r--r-- | AK/Time.h | 4 | ||||
-rw-r--r-- | AK/TypedTransfer.h | 8 | ||||
-rw-r--r-- | AK/Userspace.h | 5 | ||||
-rw-r--r-- | AK/Vector.h | 6 | ||||
-rw-r--r-- | AK/Weakable.h | 2 |
12 files changed, 26 insertions, 25 deletions
diff --git a/AK/Bitmap.h b/AK/Bitmap.h index cb21ea16d7..a84a33c83e 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 3bd155e664..39ed76ead0 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 416e4d0594..5387eab995 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 8d996c972b..8c9a835b61 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 52a9a6a060..a9fe6f9759 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 6e07c06919..079e11825d 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 7a8fdd6ede..f03b07c385 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 @@ -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 96325aa528..91045a9da9 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<T>::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<T>::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<T>::is_trivial()) diff --git a/AK/Userspace.h b/AK/Userspace.h index 04bc123654..8d99a54172 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 dcb7beed20..22749d6122 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -520,7 +520,7 @@ public: ErrorOr<void> try_append(StorageType const* values, size_t count) { - if (!count) + if (count == 0) return {}; TRY(try_grow_capacity(size() + count)); TypedTransfer<StorageType>::copy(slot(m_size), values, count); @@ -569,7 +569,7 @@ public: ErrorOr<void> try_prepend(StorageType const* values, size_t count) { - if (!count) + if (count == 0) return {}; TRY(try_grow_capacity(size() + count)); TypedTransfer<StorageType>::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 5a98b24a62..f74b47f77e 100644 --- a/AK/Weakable.h +++ b/AK/Weakable.h @@ -66,7 +66,7 @@ public: bool is_null() const { - return !unsafe_ptr<void>(); + return unsafe_ptr<void>() == nullptr; } void revoke() |