summaryrefslogtreecommitdiff
path: root/json_object.c
diff options
context:
space:
mode:
authorEric Haszlakiewicz <erh+git@nimenees.com>2020-03-02 02:08:49 +0000
committerEric Haszlakiewicz <erh+git@nimenees.com>2020-03-02 02:08:49 +0000
commitb3296e778fc0beb9855282c84a290fb4c4e155bb (patch)
tree73ec0780468ba4c991bb7d168e376721be31cfb2 /json_object.c
parent737aee40c4eb74f39fb1bcbb94a31f93e4608c0f (diff)
downloadjson-c-b3296e778fc0beb9855282c84a290fb4c4e155bb.tar.gz
Follow up the PR#542: improve assert() calls, simplify code in json_object_equal().
Diffstat (limited to 'json_object.c')
-rw-r--r--json_object.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/json_object.c b/json_object.c
index 57d4093..399d8a4 100644
--- a/json_object.c
+++ b/json_object.c
@@ -597,7 +597,7 @@ json_bool json_object_get_boolean(const struct json_object *jso)
case json_object_int_type_uint64:
return (jso->o.c_int.cint.c_uint64 != 0);
default:
- assert(0);
+ assert(!"invalid cint_type");
}
case json_type_double:
return (jso->o.c_double != 0);
@@ -734,7 +734,7 @@ int64_t json_object_get_int64(const struct json_object *jso)
return INT64_MAX;
return (int64_t)jso->o.c_int.cint.c_uint64;
default:
- assert(0);
+ assert(!"invalid cint_type");
}
case json_type_double:
// INT64_MAX can't be exactly represented as a double
@@ -772,7 +772,7 @@ uint64_t json_object_get_uint64(const struct json_object *jso)
case json_object_int_type_uint64:
return jso->o.c_int.cint.c_uint64;
default:
- assert(0);
+ assert(!"invalid cint_type");
}
case json_type_double:
// UINT64_MAX can't be exactly represented as a double
@@ -836,7 +836,7 @@ int json_object_int_inc(struct json_object *jso, int64_t val) {
}
return 1;
default:
- assert(0);
+ assert(!"invalid cint_type");
}
}
@@ -1067,7 +1067,7 @@ double json_object_get_double(const struct json_object *jso)
case json_object_int_type_uint64:
return jso->o.c_int.cint.c_uint64;
default:
- assert(0);
+ assert(!"invalid cint_type");
}
case json_type_boolean:
return jso->o.c_boolean;
@@ -1447,23 +1447,20 @@ int json_object_equal(struct json_object* jso1, struct json_object* jso2)
return (jso1->o.c_double == jso2->o.c_double);
case json_type_int:
- if (jso1->o.c_int.cint_type == json_object_int_type_int64) {
- if (jso2->o.c_int.cint_type == json_object_int_type_int64) {
+ if (jso1->o.c_int.cint_type == json_object_int_type_int64)
+ {
+ if (jso2->o.c_int.cint_type == json_object_int_type_int64)
return (jso1->o.c_int.cint.c_int64 == jso2->o.c_int.cint.c_int64);
- } else {
- if (jso1->o.c_int.cint.c_int64 < 0)
- return 0;
- return ((uint64_t)jso1->o.c_int.cint.c_int64 == jso2->o.c_int.cint.c_uint64);
- }
- } else {
- if (jso2->o.c_int.cint_type == json_object_int_type_uint64) {
- return (jso1->o.c_int.cint.c_uint64 == jso2->o.c_int.cint.c_uint64);
- } else {
- if (jso2->o.c_int.cint.c_int64 < 0)
- return 0;
- return (jso1->o.c_int.cint.c_uint64 == (uint64_t)jso2->o.c_int.cint.c_int64);
- }
+ if (jso1->o.c_int.cint.c_int64 < 0)
+ return 0;
+ return ((uint64_t)jso1->o.c_int.cint.c_int64 == jso2->o.c_int.cint.c_uint64);
}
+ // else jso1 is a uint64
+ if (jso2->o.c_int.cint_type == json_object_int_type_uint64)
+ return (jso1->o.c_int.cint.c_uint64 == jso2->o.c_int.cint.c_uint64);
+ if (jso2->o.c_int.cint.c_int64 < 0)
+ return 0;
+ return (jso1->o.c_int.cint.c_uint64 == (uint64_t)jso2->o.c_int.cint.c_int64);
case json_type_string:
return (jso1->o.c_string.len == jso2->o.c_string.len &&
@@ -1533,7 +1530,7 @@ int json_c_shallow_copy_default(json_object *src, json_object *parent, const cha
*dst = json_object_new_uint64(src->o.c_int.cint.c_uint64);
break;
default:
- assert(0);
+ assert(!"invalid cint_type");
}
break;