From c33618ea8b9b72b26133f4b8cc197cc0ecfb3486 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 870b76476..816a0131f 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)