🚨 fixed a compiler warning #527
The result of snprintf is later used in situations where a long may overflow.
This commit is contained in:
parent
67a06834b0
commit
d60851168e
2 changed files with 10 additions and 12 deletions
11
src/json.hpp
11
src/json.hpp
|
@ -6929,8 +6929,8 @@ class basic_json
|
||||||
static constexpr auto d = std::numeric_limits<number_float_t>::digits10;
|
static constexpr auto d = std::numeric_limits<number_float_t>::digits10;
|
||||||
|
|
||||||
// the actual conversion
|
// the actual conversion
|
||||||
long len = snprintf(number_buffer.data(), number_buffer.size(),
|
std::ptrdiff_t len = snprintf(number_buffer.data(), number_buffer.size(),
|
||||||
"%.*g", d, x);
|
"%.*g", d, x);
|
||||||
|
|
||||||
// negative value indicates an error
|
// negative value indicates an error
|
||||||
assert(len > 0);
|
assert(len > 0);
|
||||||
|
@ -10429,10 +10429,9 @@ class basic_json
|
||||||
|
|
||||||
Proof (by contradiction): Assume a finite input. To loop forever, the
|
Proof (by contradiction): Assume a finite input. To loop forever, the
|
||||||
loop must never hit code with a `break` statement. The only code
|
loop must never hit code with a `break` statement. The only code
|
||||||
snippets without a `break` statement are the continue statements for
|
snippets without a `break` statement is the continue statement for
|
||||||
whitespace and byte-order-marks. To loop forever, the input must be an
|
whitespace. To loop forever, the input must be an infinite sequence
|
||||||
infinite sequence of whitespace or byte-order-marks. This contradicts
|
whitespace. This contradicts the assumption of finite input, q.e.d.
|
||||||
the assumption of finite input, q.e.d.
|
|
||||||
*/
|
*/
|
||||||
token_type scan()
|
token_type scan()
|
||||||
{
|
{
|
||||||
|
|
|
@ -6929,8 +6929,8 @@ class basic_json
|
||||||
static constexpr auto d = std::numeric_limits<number_float_t>::digits10;
|
static constexpr auto d = std::numeric_limits<number_float_t>::digits10;
|
||||||
|
|
||||||
// the actual conversion
|
// the actual conversion
|
||||||
long len = snprintf(number_buffer.data(), number_buffer.size(),
|
std::ptrdiff_t len = snprintf(number_buffer.data(), number_buffer.size(),
|
||||||
"%.*g", d, x);
|
"%.*g", d, x);
|
||||||
|
|
||||||
// negative value indicates an error
|
// negative value indicates an error
|
||||||
assert(len > 0);
|
assert(len > 0);
|
||||||
|
@ -10429,10 +10429,9 @@ class basic_json
|
||||||
|
|
||||||
Proof (by contradiction): Assume a finite input. To loop forever, the
|
Proof (by contradiction): Assume a finite input. To loop forever, the
|
||||||
loop must never hit code with a `break` statement. The only code
|
loop must never hit code with a `break` statement. The only code
|
||||||
snippets without a `break` statement are the continue statements for
|
snippets without a `break` statement is the continue statement for
|
||||||
whitespace and byte-order-marks. To loop forever, the input must be an
|
whitespace. To loop forever, the input must be an infinite sequence
|
||||||
infinite sequence of whitespace or byte-order-marks. This contradicts
|
whitespace. This contradicts the assumption of finite input, q.e.d.
|
||||||
the assumption of finite input, q.e.d.
|
|
||||||
*/
|
*/
|
||||||
token_type scan()
|
token_type scan()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue