diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-09-02 21:59:45 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-09-02 21:59:45 +0200 |
commit | d3240ccf01044b37a328a202303c0e3528aacf01 (patch) | |
tree | 8a2272514d8f70c72edf661404ab1d2327991fbc | |
parent | e810a0e763d363a6a8991bd6610608c024d9e787 (diff) |
eval: treat exception values as false
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | eval.c | 37 |
1 files changed, 22 insertions, 15 deletions
@@ -61,29 +61,36 @@ ut_exception(struct ut_state *state, struct ut_opcode *op, const char *fmt, ...) bool ut_val_is_truish(struct json_object *val) { + struct ut_opcode *tag = json_object_get_userdata(val); double d; - switch (json_object_get_type(val)) { - case json_type_int: - return (json_object_get_int64(val) != 0); + switch (tag ? tag->type : 0) { + case T_EXCEPTION: + return false; - case json_type_double: - d = json_object_get_double(val); + default: + switch (json_object_get_type(val)) { + case json_type_int: + return (json_object_get_int64(val) != 0); - return (d != 0 && !isnan(d)); + case json_type_double: + d = json_object_get_double(val); - case json_type_boolean: - return (json_object_get_boolean(val) != false); + return (d != 0 && !isnan(d)); - case json_type_string: - return (json_object_get_string_len(val) > 0); + case json_type_boolean: + return (json_object_get_boolean(val) != false); - case json_type_array: - case json_type_object: - return true; + case json_type_string: + return (json_object_get_string_len(val) > 0); - default: - return false; + case json_type_array: + case json_type_object: + return true; + + default: + return false; + } } } |