Skip to content

Commit

Permalink
fix C26451 warnnings in to_chars.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
dota17 committed Mar 23, 2020
1 parent 0feea61 commit 0a82168
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions include/nlohmann/detail/conversions/to_chars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,11 +990,11 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent,
// digits[000]
// len <= max_exp + 2

std::memset(buf + k, '0', static_cast<size_t>(n - k));
std::memset(buf + k, '0', static_cast<size_t>(n) - static_cast<size_t>(k));
// Make it look like a floating-point number (#362, #378)
buf[n + 0] = '.';
buf[n + 1] = '0';
return buf + (n + 2);
return buf + (static_cast<size_t>(n) + 2);
}

if (0 < n and n <= max_exp)
Expand All @@ -1004,21 +1004,21 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent,

assert(k > n);

std::memmove(buf + (n + 1), buf + n, static_cast<size_t>(k - n));
std::memmove(buf + (static_cast<size_t>(n) + 1), buf + n, static_cast<size_t>(k) - static_cast<size_t>(n));
buf[n] = '.';
return buf + (k + 1);
return buf + (static_cast<size_t>(k) + 1);
}

if (min_exp < n and n <= 0)
{
// 0.[000]digits
// len <= 2 + (-min_exp - 1) + max_digits10

std::memmove(buf + (2 + -n), buf, static_cast<size_t>(k));
std::memmove(buf + (2 + static_cast<size_t>(-n)), buf, static_cast<size_t>(k));
buf[0] = '0';
buf[1] = '.';
std::memset(buf + 2, '0', static_cast<size_t>(-n));
return buf + (2 + (-n) + k);
return buf + (2 + static_cast<size_t>(-n) + k);
}

if (k == 1)
Expand All @@ -1033,9 +1033,9 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent,
// d.igitsE+123
// len <= max_digits10 + 1 + 5

std::memmove(buf + 2, buf + 1, static_cast<size_t>(k - 1));
std::memmove(buf + 2, buf + 1, static_cast<size_t>(k) - 1);
buf[1] = '.';
buf += 1 + k;
buf += 1 + static_cast<size_t>(k);
}

*buf++ = 'e';
Expand Down
16 changes: 8 additions & 8 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13639,11 +13639,11 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent,
// digits[000]
// len <= max_exp + 2

std::memset(buf + k, '0', static_cast<size_t>(n - k));
std::memset(buf + k, '0', static_cast<size_t>(n) - static_cast<size_t>(k));
// Make it look like a floating-point number (#362, #378)
buf[n + 0] = '.';
buf[n + 1] = '0';
return buf + (n + 2);
return buf + (static_cast<size_t>(n) + 2);
}

if (0 < n and n <= max_exp)
Expand All @@ -13653,21 +13653,21 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent,

assert(k > n);

std::memmove(buf + (n + 1), buf + n, static_cast<size_t>(k - n));
std::memmove(buf + (static_cast<size_t>(n) + 1), buf + n, static_cast<size_t>(k) - static_cast<size_t>(n));
buf[n] = '.';
return buf + (k + 1);
return buf + (static_cast<size_t>(k) + 1);
}

if (min_exp < n and n <= 0)
{
// 0.[000]digits
// len <= 2 + (-min_exp - 1) + max_digits10

std::memmove(buf + (2 + -n), buf, static_cast<size_t>(k));
std::memmove(buf + (2 + static_cast<size_t>(-n)), buf, static_cast<size_t>(k));
buf[0] = '0';
buf[1] = '.';
std::memset(buf + 2, '0', static_cast<size_t>(-n));
return buf + (2 + (-n) + k);
return buf + (2 + static_cast<size_t>(-n) + k);
}

if (k == 1)
Expand All @@ -13682,9 +13682,9 @@ inline char* format_buffer(char* buf, int len, int decimal_exponent,
// d.igitsE+123
// len <= max_digits10 + 1 + 5

std::memmove(buf + 2, buf + 1, static_cast<size_t>(k - 1));
std::memmove(buf + 2, buf + 1, static_cast<size_t>(k) - 1);
buf[1] = '.';
buf += 1 + k;
buf += 1 + static_cast<size_t>(k);
}

*buf++ = 'e';
Expand Down

0 comments on commit 0a82168

Please sign in to comment.