-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dump_float: truncation from ptrdiff_t to long #527
Comments
index a9a5067..e7b23a5 100644
--- a/src/json.hpp.re2c
+++ b/src/json.hpp.re2c
@@ -6927,7 +6927,7 @@ class basic_json
static constexpr auto d = std::numeric_limits<number_float_t>::digits10;
// 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);
// negative value indicates an error |
According to the VS 2015 docs, the return type is |
Sorry for the lack of context. The compiler error comes from line 6946: The return type of snprintf is still |
Thanks for the clarification, that makes more sense. I just assumed that the error was on the code line that you posted, and that it was line 6946 in the version of the header that you were using. |
I don't have a system on which I can run re2c, so I hesitate to issue a PR for this - is the patch above sufficient? |
@TurpentineDistillery Good point! |
The result of snprintf is later used in situations where a long may overflow.
@ftillier Should be fixed now. Could you please validate? |
@nlohmann, validated as fixed. Thanks! |
Building with VisualStudio 2017, using /W4 and /Wx, I get the following:
1>json.hpp(6946): warning C4244: '=': conversion from 'std::_Array_iterator<_Ty,64>::difference_type' to 'long', possible loss of data
On Windows, long is always 32-bits. Declaring 'len' as std::ptrdiff_t fixes the issue.
The text was updated successfully, but these errors were encountered: