Skip to content

Commit

Permalink
Merge pull request #346 from schwehr/get_int
Browse files Browse the repository at this point in the history
Clamp double to int32 when narrowing in json_object_get_int.
  • Loading branch information
hawicz committed Aug 22, 2017
2 parents 474376f + ef7b08c commit 256ebcd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions json_object.c
Expand Up @@ -635,6 +635,10 @@ int32_t json_object_get_int(const struct json_object *jso)
return INT32_MAX;
return (int32_t) cint64;
case json_type_double:
if (jso->o.c_double <= INT32_MIN)
return INT32_MIN;
if (jso->o.c_double >= INT32_MAX)
return INT32_MAX;
return (int32_t)jso->o.c_double;
case json_type_boolean:
return jso->o.c_boolean;
Expand Down

0 comments on commit 256ebcd

Please sign in to comment.