2
0
mirror of https://github.com/boostorg/mysql.git synced 2026-02-15 13:12:21 +00:00

Fixed uint64_t->size_t warnings in 32 bits

This commit is contained in:
ruben
2020-04-03 10:43:31 +01:00
parent 09d06f945c
commit 53bca255b8
2 changed files with 22 additions and 6 deletions

View File

@@ -2,6 +2,7 @@
#define INCLUDE_MYSQL_IMPL_NETWORK_ALGORITHMS_READ_RESULTSET_HEAD_IPP_
#include <boost/asio/yield.hpp>
#include <limits>
namespace boost {
namespace mysql {
@@ -13,7 +14,7 @@ class execute_processor
deserialize_row_fn deserializer_;
channel<StreamType>& channel_;
bytestring buffer_;
std::uint64_t field_count_ {};
std::size_t field_count_ {};
ok_packet ok_packet_;
std::vector<field_metadata> fields_;
std::vector<bytestring> field_buffers_;
@@ -66,9 +67,17 @@ public:
err = deserialize_message(num_fields, ctx);
if (err) return;
// For platforms where size_t is shorter than uint64_t,
// perform range check
if (num_fields.value > std::numeric_limits<std::size_t>::max())
{
err = make_error_code(errc::protocol_value_error);
return;
}
// Ensure we have fields, as field_count is indicative of
// a resultset with fields
field_count_ = num_fields.value;
field_count_ = static_cast<std::size_t>(num_fields.value);
if (field_count_ == 0)
{
err = make_error_code(errc::protocol_value_error);
@@ -118,7 +127,7 @@ public:
auto& get_channel() { return channel_; }
auto& get_buffer() { return buffer_; }
std::uint64_t field_count() const noexcept { return field_count_; }
std::size_t field_count() const noexcept { return field_count_; }
};
} // detail

View File

@@ -1,6 +1,8 @@
#ifndef INCLUDE_BOOST_MYSQL_DETAIL_PROTOCOL_IMPL_SERIALIZATION_IPP_
#define INCLUDE_BOOST_MYSQL_DETAIL_PROTOCOL_IMPL_SERIALIZATION_IPP_
#include <limits>
namespace boost {
namespace mysql {
namespace detail {
@@ -254,13 +256,18 @@ boost::mysql::detail::serialization_traits<
{
return err;
}
if (!ctx.enough_size(length.value))
if (length.value > std::numeric_limits<std::size_t>::max())
{
return errc::protocol_value_error;
}
auto len = static_cast<std::size_t>(length.value);
if (!ctx.enough_size(len))
{
return errc::incomplete_message;
}
output.value = get_string(ctx.first(), length.value);
ctx.advance(length.value);
output.value = get_string(ctx.first(), len);
ctx.advance(len);
return errc::ok;
}