mirror of
https://github.com/nlohmann/json.git
synced 2025-07-12 09:21:42 +03:00
🚑 fix for #416
This commit is contained in:
@ -6938,11 +6938,10 @@ class basic_json
|
||||
case 0xca: // float 32
|
||||
{
|
||||
// copy bytes in reverse order into the double variable
|
||||
check_length(v.size(), sizeof(float), 1);
|
||||
float res;
|
||||
for (size_t byte = 0; byte < sizeof(float); ++byte)
|
||||
{
|
||||
reinterpret_cast<uint8_t*>(&res)[sizeof(float) - byte - 1] = v[current_idx + 1 + byte];
|
||||
reinterpret_cast<uint8_t*>(&res)[sizeof(float) - byte - 1] = v.at(current_idx + 1 + byte);
|
||||
}
|
||||
idx += sizeof(float); // skip content bytes
|
||||
return res;
|
||||
@ -6951,11 +6950,10 @@ class basic_json
|
||||
case 0xcb: // float 64
|
||||
{
|
||||
// copy bytes in reverse order into the double variable
|
||||
check_length(v.size(), sizeof(double), 1);
|
||||
double res;
|
||||
for (size_t byte = 0; byte < sizeof(double); ++byte)
|
||||
{
|
||||
reinterpret_cast<uint8_t*>(&res)[sizeof(double) - byte - 1] = v[current_idx + 1 + byte];
|
||||
reinterpret_cast<uint8_t*>(&res)[sizeof(double) - byte - 1] = v.at(current_idx + 1 + byte);
|
||||
}
|
||||
idx += sizeof(double); // skip content bytes
|
||||
return res;
|
||||
@ -7517,7 +7515,6 @@ class basic_json
|
||||
|
||||
case 0xf9: // Half-Precision Float (two-byte IEEE 754)
|
||||
{
|
||||
check_length(v.size(), 2, 1);
|
||||
idx += 2; // skip two content bytes
|
||||
|
||||
// code from RFC 7049, Appendix D, Figure 3:
|
||||
@ -7527,7 +7524,7 @@ class basic_json
|
||||
// include at least decoding support for them even without such
|
||||
// support. An example of a small decoder for half-precision
|
||||
// floating-point numbers in the C language is shown in Fig. 3.
|
||||
const int half = (v[current_idx + 1] << 8) + v[current_idx + 2];
|
||||
const int half = (v.at(current_idx + 1) << 8) + v.at(current_idx + 2);
|
||||
const int exp = (half >> 10) & 0x1f;
|
||||
const int mant = half & 0x3ff;
|
||||
double val;
|
||||
@ -7549,11 +7546,10 @@ class basic_json
|
||||
case 0xfa: // Single-Precision Float (four-byte IEEE 754)
|
||||
{
|
||||
// copy bytes in reverse order into the float variable
|
||||
check_length(v.size(), sizeof(float), 1);
|
||||
float res;
|
||||
for (size_t byte = 0; byte < sizeof(float); ++byte)
|
||||
{
|
||||
reinterpret_cast<uint8_t*>(&res)[sizeof(float) - byte - 1] = v[current_idx + 1 + byte];
|
||||
reinterpret_cast<uint8_t*>(&res)[sizeof(float) - byte - 1] = v.at(current_idx + 1 + byte);
|
||||
}
|
||||
idx += sizeof(float); // skip content bytes
|
||||
return res;
|
||||
@ -7561,12 +7557,11 @@ class basic_json
|
||||
|
||||
case 0xfb: // Double-Precision Float (eight-byte IEEE 754)
|
||||
{
|
||||
check_length(v.size(), sizeof(double), 1);
|
||||
// copy bytes in reverse order into the double variable
|
||||
double res;
|
||||
for (size_t byte = 0; byte < sizeof(double); ++byte)
|
||||
{
|
||||
reinterpret_cast<uint8_t*>(&res)[sizeof(double) - byte - 1] = v[current_idx + 1 + byte];
|
||||
reinterpret_cast<uint8_t*>(&res)[sizeof(double) - byte - 1] = v.at(current_idx + 1 + byte);
|
||||
}
|
||||
idx += sizeof(double); // skip content bytes
|
||||
return res;
|
||||
|
Reference in New Issue
Block a user