summaryrefslogtreecommitdiffhomepage
path: root/libs/luci-lib-jsonc/src/jsonc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libs/luci-lib-jsonc/src/jsonc.c')
-rw-r--r--libs/luci-lib-jsonc/src/jsonc.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/libs/luci-lib-jsonc/src/jsonc.c b/libs/luci-lib-jsonc/src/jsonc.c
index 74839dd4f5..5abb738f5f 100644
--- a/libs/luci-lib-jsonc/src/jsonc.c
+++ b/libs/luci-lib-jsonc/src/jsonc.c
@@ -294,7 +294,7 @@ static bool visited(struct seen **sp, const void *ptr) {
static struct json_object * _lua_to_json_rec(lua_State *L, int index,
struct seen **seen)
{
- lua_Number nd, ni;
+ lua_Number nd;
struct json_object *obj;
const char *key;
int i, max;
@@ -364,10 +364,12 @@ static struct json_object * _lua_to_json_rec(lua_State *L, int index,
return json_object_new_boolean(lua_toboolean(L, index));
case LUA_TNUMBER:
+ if (lua_isinteger(L, index))
+ return json_object_new_int64(lua_tointeger(L, index));
+
nd = lua_tonumber(L, index);
- ni = lua_tointeger(L, index);
- if (nd == ni)
+ if (isfinite(nd) && trunc(nd) == nd)
return json_object_new_int64(nd);
return json_object_new_double(nd);