Merge pull request #1760 from Xav83/cppcheckFixes

Cppcheck fixes
This commit is contained in:
Niels Lohmann 2019-09-24 20:42:38 +02:00 committed by GitHub
commit e2c531a1f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 10 deletions

View file

@ -647,7 +647,7 @@ class binary_reader
const int exp = (half >> 10u) & 0x1Fu; const int exp = (half >> 10u) & 0x1Fu;
const unsigned int mant = half & 0x3FFu; const unsigned int mant = half & 0x3FFu;
assert(0 <= exp and exp <= 32); assert(0 <= exp and exp <= 32);
assert(0 <= mant and mant <= 1024); assert(mant <= 1024);
switch (exp) switch (exp)
{ {
case 0: case 0:

View file

@ -861,13 +861,12 @@ class binary_writer
*/ */
static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t& value) static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t& value)
{ {
std::size_t embedded_document_size = 0ul;
std::size_t array_index = 0ul; std::size_t array_index = 0ul;
for (const auto& el : value) const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), 0ul, [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el)
{ {
embedded_document_size += calc_bson_element_size(std::to_string(array_index++), el); return result + calc_bson_element_size(std::to_string(array_index++), el);
} });
return sizeof(std::int32_t) + embedded_document_size + 1ul; return sizeof(std::int32_t) + embedded_document_size + 1ul;
} }

View file

@ -5678,7 +5678,7 @@ class binary_reader
const int exp = (half >> 10u) & 0x1Fu; const int exp = (half >> 10u) & 0x1Fu;
const unsigned int mant = half & 0x3FFu; const unsigned int mant = half & 0x3FFu;
assert(0 <= exp and exp <= 32); assert(0 <= exp and exp <= 32);
assert(0 <= mant and mant <= 1024); assert(mant <= 1024);
switch (exp) switch (exp)
{ {
case 0: case 0:
@ -12044,13 +12044,12 @@ class binary_writer
*/ */
static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t& value) static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t& value)
{ {
std::size_t embedded_document_size = 0ul;
std::size_t array_index = 0ul; std::size_t array_index = 0ul;
for (const auto& el : value) const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), 0ul, [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el)
{ {
embedded_document_size += calc_bson_element_size(std::to_string(array_index++), el); return result + calc_bson_element_size(std::to_string(array_index++), el);
} });
return sizeof(std::int32_t) + embedded_document_size + 1ul; return sizeof(std::int32_t) + embedded_document_size + 1ul;
} }