summaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2019-11-13 09:03:38 +0100
committerJo-Philipp Wich <jo@mein.io>2019-11-13 09:11:09 +0100
commit8da8f38bf97c925f6f113d3b4793edb23e7e0dc2 (patch)
treeaa65fe13612c62b00bc35b2fbec29b9d9786ae20 /libs
parentdf38e4505ceae1634dc48c2793040f31856c758a (diff)
luci-lib-jsonc: store large JSON integer values as Lua doubles
Fixes: #3293 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'libs')
-rw-r--r--libs/luci-lib-jsonc/src/jsonc.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/libs/luci-lib-jsonc/src/jsonc.c b/libs/luci-lib-jsonc/src/jsonc.c
index 9ff8520db..2f56a4a68 100644
--- a/libs/luci-lib-jsonc/src/jsonc.c
+++ b/libs/luci-lib-jsonc/src/jsonc.c
@@ -17,6 +17,7 @@ limitations under the License.
#define _GNU_SOURCE
#include <math.h>
+#include <stdint.h>
#include <stdbool.h>
#include <json-c/json.h>
@@ -145,6 +146,7 @@ static int json_parse_chunk(lua_State *L)
static void _json_to_lua(lua_State *L, struct json_object *obj)
{
+ int64_t v;
int n;
switch (json_object_get_type(obj))
@@ -172,7 +174,12 @@ static void _json_to_lua(lua_State *L, struct json_object *obj)
break;
case json_type_int:
- lua_pushinteger(L, json_object_get_int(obj));
+ v = json_object_get_int64(obj);
+ if (sizeof(lua_Integer) > sizeof(int32_t) ||
+ (v >= INT32_MIN && v <= INT32_MAX))
+ lua_pushinteger(L, (lua_Integer)v);
+ else
+ lua_pushnumber(L, (lua_Number)v);
break;
case json_type_double: