From e364f08def1c27b42bb61cc987317d556efc3670 Mon Sep 17 00:00:00 2001 From: Mingun Date: Mon, 6 Dec 2021 00:42:54 +0500 Subject: [PATCH] Consider the `if` key in the sizeof calculations. Probably resolve #927 --- .../struct/precompile/CalculateSeqSizes.scala | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/shared/src/main/scala/io/kaitai/struct/precompile/CalculateSeqSizes.scala b/shared/src/main/scala/io/kaitai/struct/precompile/CalculateSeqSizes.scala index b6a9c998e..78f8b5f7c 100644 --- a/shared/src/main/scala/io/kaitai/struct/precompile/CalculateSeqSizes.scala +++ b/shared/src/main/scala/io/kaitai/struct/precompile/CalculateSeqSizes.scala @@ -95,7 +95,23 @@ object CalculateSeqSizes { var seqPos: Option[Int] = Some(0) curClass.seq.foreach { attr => val sizeElement = dataTypeBitsSize(attr.dataType) - val sizeContainer = sizeMultiply(sizeElement, attr.cond.repeat, attr.path) + val size = sizeMultiply(sizeElement, attr.cond.repeat, attr.path) + val sizeContainer = attr.cond.ifExpr match { + case Some(expr) => expr.evaluateBoolConst match { + case Some(true) => { + //TODO: add user visible warning + Log.seqSizes.warn(() => s"${attr.path}: condition is always `true`") + size + } + case Some(false) => { + //TODO: add user visible warning + Log.seqSizes.warn(() => s"${attr.path}: condition is always `false`") + FixedSized(0) + } + case None => DynamicSized + } + case None => size + } op(attr, seqPos, sizeElement, sizeContainer)