* @brief Pushes a JSON double, narrowing to lua_Integer only when finite, in the qint64 range, * and exact; the range check must precede the cast, which is UB otherwise. */
| 333 | * and exact; the range check must precede the cast, which is UB otherwise. |
| 334 | */ |
| 335 | static void pushJsonNumber(lua_State* L, double d) |
| 336 | { |
| 337 | constexpr double kInt64Min = -9223372036854775808.0; |
| 338 | constexpr double kInt64Max = 9223372036854775808.0; |
| 339 | |
| 340 | if (std::isfinite(d) && d >= kInt64Min && d < kInt64Max) { |
| 341 | const qint64 i = static_cast<qint64>(d); |
| 342 | if (static_cast<double>(i) == d) { |
| 343 | lua_pushinteger(L, static_cast<lua_Integer>(i)); |
| 344 | return; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | lua_pushnumber(L, d); |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * @brief Pushes a QJsonObject onto the Lua stack as a string-keyed table. |
no test coverage detected