From d809637023296924c197bb869497cedf9da8db0e Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Mon, 3 Jan 2022 02:50:55 -0700 Subject: [PATCH] Userland: Resolve tautological-constant-out-of-range-compare warnings Stop comparing platform-specific sized integer types to max() values of other interger types. Enable the warning everywhere. --- CMakeLists.txt | 1 - Userland/Libraries/LibC/stdio.cpp | 5 +++-- .../Libraries/LibWasm/AbstractMachine/AbstractMachine.h | 2 +- Userland/Libraries/LibWebSocket/WebSocket.cpp | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c13259290c..99464d9f4dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -199,7 +199,6 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang$") add_compile_options(-Wno-atomic-alignment) add_compile_options(-Wno-implicit-const-int-float-conversion) add_compile_options(-Wno-null-pointer-subtraction) - add_compile_options(-Wno-tautological-constant-out-of-range-compare) add_compile_options(-Wno-unneeded-internal-declaration) add_compile_options(-Wno-unused-but-set-variable) add_compile_options(-Wno-unused-const-variable) diff --git a/Userland/Libraries/LibC/stdio.cpp b/Userland/Libraries/LibC/stdio.cpp index b6658b13b68..861e20e5ec8 100644 --- a/Userland/Libraries/LibC/stdio.cpp +++ b/Userland/Libraries/LibC/stdio.cpp @@ -63,8 +63,9 @@ bool FILE::flush() } if (m_mode & O_RDONLY) { // When open for reading, just drop the buffered data. - VERIFY(m_buffer.buffered_size() <= NumericLimits::max()); - off_t had_buffered = m_buffer.buffered_size(); + if constexpr (sizeof(size_t) >= sizeof(off_t)) + VERIFY(m_buffer.buffered_size() <= NumericLimits::max()); + off_t had_buffered = static_cast(m_buffer.buffered_size()); m_buffer.drop(); // Attempt to reset the underlying file position to what the user // expects. diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h index 4527bb4a10d..d94478e5ef9 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h @@ -346,7 +346,7 @@ public: { if (size_to_grow == 0) return true; - auto new_size = m_data.size() + size_to_grow; + u64 new_size = m_data.size() + size_to_grow; // Can't grow past 2^16 pages. if (new_size >= Constants::page_size * 65536) return false; diff --git a/Userland/Libraries/LibWebSocket/WebSocket.cpp b/Userland/Libraries/LibWebSocket/WebSocket.cpp index ed7825c0b58..860e0c812fa 100644 --- a/Userland/Libraries/LibWebSocket/WebSocket.cpp +++ b/Userland/Libraries/LibWebSocket/WebSocket.cpp @@ -488,10 +488,10 @@ void WebSocket::send_frame(WebSocket::OpCode op_code, ReadonlyBytes payload, boo m_impl->send(ReadonlyBytes(frame_head, 1)); // Section 5.1 : a client MUST mask all frames that it sends to the server bool has_mask = true; - if (payload.size() > NumericLimits::max()) { - // FIXME: We can technically stream this via non-final packets. - TODO(); - } else if (payload.size() > NumericLimits::max()) { + // FIXME: If the payload has a size > size_t max on a 32-bit platform, we could + // technically stream it via non-final packets. However, the size was already + // truncated earlier in the call stack when stuffing into a ReadonlyBytes + if (payload.size() > NumericLimits::max()) { // Send (the 'mask' flag + 127) + the 8-byte payload length if constexpr (sizeof(size_t) >= 8) { u8 payload_length[9] = {