Skip to content

Commit

Permalink
Userland: Resolve tautological-constant-out-of-range-compare warnings
Browse files Browse the repository at this point in the history
Stop comparing platform-specific sized integer types to max() values of
other interger types. Enable the warning everywhere.
  • Loading branch information
ADKaster authored and bgianfo committed Jan 4, 2022
1 parent a103a85 commit d809637
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions Userland/Libraries/LibC/stdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<off_t>::max());
off_t had_buffered = m_buffer.buffered_size();
if constexpr (sizeof(size_t) >= sizeof(off_t))
VERIFY(m_buffer.buffered_size() <= NumericLimits<off_t>::max());
off_t had_buffered = static_cast<off_t>(m_buffer.buffered_size());
m_buffer.drop();
// Attempt to reset the underlying file position to what the user
// expects.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ class MemoryInstance {
{
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;
Expand Down
8 changes: 4 additions & 4 deletions Userland/Libraries/LibWebSocket/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>::max()) {
// FIXME: We can technically stream this via non-final packets.
TODO();
} else if (payload.size() > NumericLimits<u16>::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<u16>::max()) {
// Send (the 'mask' flag + 127) + the 8-byte payload length
if constexpr (sizeof(size_t) >= 8) {
u8 payload_length[9] = {
Expand Down

0 comments on commit d809637

Please sign in to comment.