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
* Boost library min/max guidance
HTTP
* Make chunk_encode public

View File

@@ -250,7 +250,7 @@ public:
size_type
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.

View File

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

View File

@@ -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;

View File

@@ -657,7 +657,7 @@ basic_streambuf<Allocator>::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<class Alloc, class T>

View File

@@ -444,7 +444,7 @@ buffers_adapter<MutableBufferSequence>::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;

View File

@@ -31,7 +31,7 @@ prepare_buffer(std::size_t n,
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
return { buffer_cast<void const*>(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<void*>(buffer),
std::min(n, buffer_size(buffer)) };
(std::min)(n, buffer_size(buffer)) };
}
/** 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.
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.

View File

@@ -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;

View File

@@ -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--)

View File

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

View File

@@ -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))

View File

@@ -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;