From 6d2195514d93a866968f7dc1ddc758fd8a6d5278 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Tue, 8 Nov 2016 13:03:20 -0500 Subject: [PATCH] Boost library min/max guidance: fix #170 --- CHANGELOG.md | 2 ++ include/beast/core/basic_streambuf.hpp | 2 +- include/beast/core/detail/clamp.hpp | 4 ++-- include/beast/core/detail/sha1.hpp | 2 +- include/beast/core/impl/basic_streambuf.ipp | 8 ++++---- include/beast/core/impl/buffers_adapter.ipp | 2 +- include/beast/core/prepare_buffers.hpp | 4 ++-- include/beast/http/basic_parser_v1.hpp | 2 +- include/beast/websocket/detail/stream_base.hpp | 4 ++-- include/beast/websocket/detail/utf8_checker.hpp | 2 +- test/core/clamp.cpp | 4 ++-- test/http/message_fuzz.hpp | 2 +- test/websocket/utf8_checker.cpp | 2 +- 13 files changed, 21 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cb43fff..a8a26f0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ 1.0.0-b19 +* Boost library min/max guidance + HTTP * Make chunk_encode public diff --git a/include/beast/core/basic_streambuf.hpp b/include/beast/core/basic_streambuf.hpp index 8c57678d..9dac4c06 100644 --- a/include/beast/core/basic_streambuf.hpp +++ b/include/beast/core/basic_streambuf.hpp @@ -250,7 +250,7 @@ public: size_type max_size() const { - return std::numeric_limits::max(); + return (std::numeric_limits::max)(); } /// Returns the maximum sum of the sizes of the input sequence and output sequence the buffer can hold without requiring reallocation. diff --git a/include/beast/core/detail/clamp.hpp b/include/beast/core/detail/clamp.hpp index 3a72f3a0..7c158da1 100644 --- a/include/beast/core/detail/clamp.hpp +++ b/include/beast/core/detail/clamp.hpp @@ -19,8 +19,8 @@ static std::size_t clamp(UInt x) { - if(x >= std::numeric_limits::max()) - return std::numeric_limits::max(); + if(x >= (std::numeric_limits::max)()) + return (std::numeric_limits::max)(); return static_cast(x); } diff --git a/include/beast/core/detail/sha1.hpp b/include/beast/core/detail/sha1.hpp index 4aa83037..28a744ec 100644 --- a/include/beast/core/detail/sha1.hpp +++ b/include/beast/core/detail/sha1.hpp @@ -249,7 +249,7 @@ update(sha1_context& ctx, std::uint8_t const*>(message); for(;;) { - auto const n = std::min( + auto const n = (std::min)( size, sizeof(ctx.buf) - ctx.buflen); std::memcpy(ctx.buf + ctx.buflen, p, n); ctx.buflen += n; diff --git a/include/beast/core/impl/basic_streambuf.ipp b/include/beast/core/impl/basic_streambuf.ipp index e1f51e50..c70d646b 100644 --- a/include/beast/core/impl/basic_streambuf.ipp +++ b/include/beast/core/impl/basic_streambuf.ipp @@ -657,7 +657,7 @@ basic_streambuf::commit(size_type n) debug_check(); } - n = std::min(n, out_end_ - out_pos_); + n = (std::min)(n, out_end_ - out_pos_); out_pos_ += n; in_size_ += n; if(out_pos_ == out_->size()) @@ -862,13 +862,13 @@ read_size_helper(basic_streambuf< // buffer, try to fill that up first auto const avail = streambuf.capacity() - streambuf.size(); if (avail > 0) - return std::min(avail, max_size); + return (std::min)(avail, max_size); // Try to have just one new block allocated constexpr std::size_t low = 512; if (streambuf.alloc_size_ > low) - return std::min(max_size, streambuf.alloc_size_); + return (std::min)(max_size, streambuf.alloc_size_); // ...but enforce a 512 byte minimum. - return std::min(max_size, low); + return (std::min)(max_size, low); } template diff --git a/include/beast/core/impl/buffers_adapter.ipp b/include/beast/core/impl/buffers_adapter.ipp index d7dc132a..cf537d6e 100644 --- a/include/beast/core/impl/buffers_adapter.ipp +++ b/include/beast/core/impl/buffers_adapter.ipp @@ -444,7 +444,7 @@ buffers_adapter::commit(std::size_t n) max_size_ -= avail; } - n = std::min(n, out_end_ - out_pos_); + n = (std::min)(n, out_end_ - out_pos_); out_pos_ += n; in_size_ += n; max_size_ -= n; diff --git a/include/beast/core/prepare_buffers.hpp b/include/beast/core/prepare_buffers.hpp index 9b113ae3..06e83741 100644 --- a/include/beast/core/prepare_buffers.hpp +++ b/include/beast/core/prepare_buffers.hpp @@ -31,7 +31,7 @@ prepare_buffer(std::size_t n, using boost::asio::buffer_cast; using boost::asio::buffer_size; return { buffer_cast(buffer), - std::min(n, buffer_size(buffer)) }; + (std::min)(n, buffer_size(buffer)) }; } /** Get a trimmed mutable buffer. @@ -48,7 +48,7 @@ prepare_buffer(std::size_t n, using boost::asio::buffer_cast; using boost::asio::buffer_size; return { buffer_cast(buffer), - std::min(n, buffer_size(buffer)) }; + (std::min)(n, buffer_size(buffer)) }; } /** Wrapper to produce a trimmed buffer sequence. diff --git a/include/beast/http/basic_parser_v1.hpp b/include/beast/http/basic_parser_v1.hpp index 0a5290a5..9db48bf3 100644 --- a/include/beast/http/basic_parser_v1.hpp +++ b/include/beast/http/basic_parser_v1.hpp @@ -125,7 +125,7 @@ enum class body_what /// The value returned when no content length is known or applicable. static std::uint64_t constexpr no_content_length = - std::numeric_limits::max(); + (std::numeric_limits::max)(); /** A parser for decoding HTTP/1 wire format messages. diff --git a/include/beast/websocket/detail/stream_base.hpp b/include/beast/websocket/detail/stream_base.hpp index d62375e2..2256d140 100644 --- a/include/beast/websocket/detail/stream_base.hpp +++ b/include/beast/websocket/detail/stream_base.hpp @@ -356,8 +356,8 @@ read_fh2(DynamicBuffer& db, close_code::value& code) } else { - if(rd_size_ > std::numeric_limits< - std::uint64_t>::max() - rd_fh_.len) + if(rd_size_ > (std::numeric_limits< + std::uint64_t>::max)() - rd_fh_.len) { code = close_code::too_big; return; diff --git a/include/beast/websocket/detail/utf8_checker.hpp b/include/beast/websocket/detail/utf8_checker.hpp index 355ec03c..b7ffe26a 100644 --- a/include/beast/websocket/detail/utf8_checker.hpp +++ b/include/beast/websocket/detail/utf8_checker.hpp @@ -230,7 +230,7 @@ utf8_checker_t<_>::write(std::uint8_t const* in, std::size_t size) auto const end = in + size; if (need_ > 0) { - auto n = std::min(size, need_); + auto n = (std::min)(size, need_); size -= n; need_ -= n; while(n--) diff --git a/test/core/clamp.cpp b/test/core/clamp.cpp index a429f7f9..e63f526b 100644 --- a/test/core/clamp.cpp +++ b/test/core/clamp.cpp @@ -20,8 +20,8 @@ public: void testClamp() { BEAST_EXPECT(clamp( - std::numeric_limits::max()) == - std::numeric_limits::max()); + (std::numeric_limits::max)()) == + (std::numeric_limits::max)()); } void run() override diff --git a/test/http/message_fuzz.hpp b/test/http/message_fuzz.hpp index 6f38b750..2e0287fb 100644 --- a/test/http/message_fuzz.hpp +++ b/test/http/message_fuzz.hpp @@ -514,7 +514,7 @@ public: write(db, "Transfer-Encoding: chunked\r\n\r\n"); while(len > 0) { - auto n = std::min(1 + rand(300), len); + auto n = (std::min)(1 + rand(300), len); len -= n; write(db, to_hex(n), "\r\n"); for(auto const& b : db.prepare(n)) diff --git a/test/websocket/utf8_checker.cpp b/test/websocket/utf8_checker.cpp index 20ac7996..c52e894f 100644 --- a/test/websocket/utf8_checker.cpp +++ b/test/websocket/utf8_checker.cpp @@ -289,7 +289,7 @@ public: streambuf sb(size); while(n) { - auto const amount = std::min(n, size); + auto const amount = (std::min)(n, size); sb.commit(buffer_copy(sb.prepare(amount), cb)); cb.consume(amount); n -= amount;