]> granicus.if.org Git - json-c/commitdiff
Add an explicit cast to double to squash a -Wimplicit-int-float-conversion warning.
authorEric Haszlakiewicz <erh+git@nimenees.com>
Mon, 12 Aug 2019 00:30:45 +0000 (00:30 +0000)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Mon, 12 Aug 2019 00:30:45 +0000 (00:30 +0000)
Though we will no longer be comparing exactly against INT64_MAX, this is ok
because any value of that magnitude stored in a double will *also* have been
rounded up, so the comparison will work appropriately.

json_object.c

index 026dab313bf5df78358b4baca7c3d41dee93d27b..192919f4606553a7e5f16cc8e8987b4c915311d2 100644 (file)
@@ -701,7 +701,9 @@ int64_t json_object_get_int64(const struct json_object *jso)
        case json_type_int:
                return jso->o.c_int64;
        case json_type_double:
-               if (jso->o.c_double >= INT64_MAX)
+               // INT64_MAX can't be exactly represented as a double
+               // so cast to tell the compiler it's ok to round up.
+               if (jso->o.c_double >= (double)INT64_MAX)
                        return INT64_MAX;
                if (jso->o.c_double <= INT64_MIN)
                        return INT64_MIN;