Skip to content

Commit

Permalink
Follow up the PR#542: improve assert() calls, simplify code in json_o…
Browse files Browse the repository at this point in the history
…bject_equal().
  • Loading branch information
hawicz committed Mar 2, 2020
1 parent 737aee4 commit b3296e7
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions json_object.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit b3296e7

Please sign in to comment.