Boost library min/max guidance:

fix #170
This commit is contained in:
Vinnie Falco
2016-11-08 13:03:20 -05:00
parent 1eb673dd7d
commit 6d2195514d
13 changed files with 21 additions and 19 deletions

View File

@@ -1,5 +1,7 @@
1.0.0-b19 1.0.0-b19
* Boost library min/max guidance
HTTP HTTP
* Make chunk_encode public * Make chunk_encode public

View File

@@ -250,7 +250,7 @@ public:
size_type size_type
max_size() const max_size() const
{ {
return std::numeric_limits<std::size_t>::max(); return (std::numeric_limits<std::size_t>::max)();
} }
/// Returns the maximum sum of the sizes of the input sequence and output sequence the buffer can hold without requiring reallocation. /// Returns the maximum sum of the sizes of the input sequence and output sequence the buffer can hold without requiring reallocation.

View File

@@ -19,8 +19,8 @@ static
std::size_t std::size_t
clamp(UInt x) clamp(UInt x)
{ {
if(x >= std::numeric_limits<std::size_t>::max()) if(x >= (std::numeric_limits<std::size_t>::max)())
return std::numeric_limits<std::size_t>::max(); return (std::numeric_limits<std::size_t>::max)();
return static_cast<std::size_t>(x); return static_cast<std::size_t>(x);
} }

View File

@@ -249,7 +249,7 @@ update(sha1_context& ctx,
std::uint8_t const*>(message); std::uint8_t const*>(message);
for(;;) for(;;)
{ {
auto const n = std::min( auto const n = (std::min)(
size, sizeof(ctx.buf) - ctx.buflen); size, sizeof(ctx.buf) - ctx.buflen);
std::memcpy(ctx.buf + ctx.buflen, p, n); std::memcpy(ctx.buf + ctx.buflen, p, n);
ctx.buflen += n; ctx.buflen += n;

View File

@@ -657,7 +657,7 @@ basic_streambuf<Allocator>::commit(size_type n)
debug_check(); debug_check();
} }
n = std::min(n, out_end_ - out_pos_); n = (std::min)(n, out_end_ - out_pos_);
out_pos_ += n; out_pos_ += n;
in_size_ += n; in_size_ += n;
if(out_pos_ == out_->size()) if(out_pos_ == out_->size())
@@ -862,13 +862,13 @@ read_size_helper(basic_streambuf<
// buffer, try to fill that up first // buffer, try to fill that up first
auto const avail = streambuf.capacity() - streambuf.size(); auto const avail = streambuf.capacity() - streambuf.size();
if (avail > 0) if (avail > 0)
return std::min(avail, max_size); return (std::min)(avail, max_size);
// Try to have just one new block allocated // Try to have just one new block allocated
constexpr std::size_t low = 512; constexpr std::size_t low = 512;
if (streambuf.alloc_size_ > low) 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. // ...but enforce a 512 byte minimum.
return std::min(max_size, low); return (std::min)(max_size, low);
} }
template<class Alloc, class T> template<class Alloc, class T>

View File

@@ -444,7 +444,7 @@ buffers_adapter<MutableBufferSequence>::commit(std::size_t n)
max_size_ -= avail; max_size_ -= avail;
} }
n = std::min(n, out_end_ - out_pos_); n = (std::min)(n, out_end_ - out_pos_);
out_pos_ += n; out_pos_ += n;
in_size_ += n; in_size_ += n;
max_size_ -= n; max_size_ -= n;

View File

@@ -31,7 +31,7 @@ prepare_buffer(std::size_t n,
using boost::asio::buffer_cast; using boost::asio::buffer_cast;
using boost::asio::buffer_size; using boost::asio::buffer_size;
return { buffer_cast<void const*>(buffer), return { buffer_cast<void const*>(buffer),
std::min(n, buffer_size(buffer)) }; (std::min)(n, buffer_size(buffer)) };
} }
/** Get a trimmed mutable 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_cast;
using boost::asio::buffer_size; using boost::asio::buffer_size;
return { buffer_cast<void*>(buffer), return { buffer_cast<void*>(buffer),
std::min(n, buffer_size(buffer)) }; (std::min)(n, buffer_size(buffer)) };
} }
/** Wrapper to produce a trimmed buffer sequence. /** Wrapper to produce a trimmed buffer sequence.

View File

@@ -125,7 +125,7 @@ enum class body_what
/// The value returned when no content length is known or applicable. /// The value returned when no content length is known or applicable.
static std::uint64_t constexpr no_content_length = static std::uint64_t constexpr no_content_length =
std::numeric_limits<std::uint64_t>::max(); (std::numeric_limits<std::uint64_t>::max)();
/** A parser for decoding HTTP/1 wire format messages. /** A parser for decoding HTTP/1 wire format messages.

View File

@@ -356,8 +356,8 @@ read_fh2(DynamicBuffer& db, close_code::value& code)
} }
else else
{ {
if(rd_size_ > std::numeric_limits< if(rd_size_ > (std::numeric_limits<
std::uint64_t>::max() - rd_fh_.len) std::uint64_t>::max)() - rd_fh_.len)
{ {
code = close_code::too_big; code = close_code::too_big;
return; return;

View File

@@ -230,7 +230,7 @@ utf8_checker_t<_>::write(std::uint8_t const* in, std::size_t size)
auto const end = in + size; auto const end = in + size;
if (need_ > 0) if (need_ > 0)
{ {
auto n = std::min(size, need_); auto n = (std::min)(size, need_);
size -= n; size -= n;
need_ -= n; need_ -= n;
while(n--) while(n--)

View File

@@ -20,8 +20,8 @@ public:
void testClamp() void testClamp()
{ {
BEAST_EXPECT(clamp( BEAST_EXPECT(clamp(
std::numeric_limits<std::uint64_t>::max()) == (std::numeric_limits<std::uint64_t>::max)()) ==
std::numeric_limits<std::size_t>::max()); (std::numeric_limits<std::size_t>::max)());
} }
void run() override void run() override

View File

@@ -514,7 +514,7 @@ public:
write(db, "Transfer-Encoding: chunked\r\n\r\n"); write(db, "Transfer-Encoding: chunked\r\n\r\n");
while(len > 0) while(len > 0)
{ {
auto n = std::min(1 + rand(300), len); auto n = (std::min)(1 + rand(300), len);
len -= n; len -= n;
write(db, to_hex(n), "\r\n"); write(db, to_hex(n), "\r\n");
for(auto const& b : db.prepare(n)) for(auto const& b : db.prepare(n))

View File

@@ -289,7 +289,7 @@ public:
streambuf sb(size); streambuf sb(size);
while(n) while(n)
{ {
auto const amount = std::min(n, size); auto const amount = (std::min)(n, size);
sb.commit(buffer_copy(sb.prepare(amount), cb)); sb.commit(buffer_copy(sb.prepare(amount), cb));
cb.consume(amount); cb.consume(amount);
n -= amount; n -= amount;