summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2023-10-08 23:12:07 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2023-10-08 23:12:07 (GMT)
commitb0f5ae703f50b182e5cb28455b549804cc37fb40 (patch)
treec359d2f225d4daee059060e509e90d6628d786a4 /plugins
parent22d7a5277e2526514b8b01983f502c26aeff5747 (diff)
Allow Kaitai numbers to be seen as booleans when needed.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/kaitai/grammar.y20
1 files changed, 20 insertions, 0 deletions
diff --git a/plugins/kaitai/grammar.y b/plugins/kaitai/grammar.y
index 9e31113..2f2b820 100644
--- a/plugins/kaitai/grammar.y
+++ b/plugins/kaitai/grammar.y
@@ -1734,6 +1734,26 @@ bool resolve_kaitai_expression_as_boolean(const kaitai_scope_t *locals, const ch
if (result)
result = reduce_resolved_kaitai_expression(out);
+ if (result)
+ {
+ if (out->type == GVT_UNSIGNED_INTEGER)
+ {
+ out->status = (out->unsigned_integer != 0);
+ out->type = GVT_BOOLEAN;
+ }
+ else if (out->type == GVT_SIGNED_INTEGER)
+ {
+ out->status = (out->signed_integer != 0);
+ out->type = GVT_BOOLEAN;
+ }
+ else if (out->type == GVT_FLOAT)
+ {
+ out->status = (out->floating_number != 0);
+ out->type = GVT_BOOLEAN;
+ }
+
+ }
+
if (result && out->type != GVT_BOOLEAN)
{
EXIT_RESOLVED_VALUE(*out);