diff --git a/dissect/cstruct/types/enum.py b/dissect/cstruct/types/enum.py index c67280b..1d3b2e6 100644 --- a/dissect/cstruct/types/enum.py +++ b/dissect/cstruct/types/enum.py @@ -39,6 +39,7 @@ def __call__( enum_cls.cs = cs enum_cls.type = type_ enum_cls.size = type_.size + enum_cls.dynamic = type_.dynamic enum_cls.alignment = type_.alignment _fix_alias_members(enum_cls) diff --git a/tests/test_basic.py b/tests/test_basic.py index b594f0a..b318e39 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -505,3 +505,20 @@ def test_size_and_aligment(cs: cstruct): test = cs._make_packed_type("test", "B", int, alignment=8) assert test.size == 1 assert test.alignment == 8 + + +def test_dynamic_substruct_size(cs: cstruct): + cdef = """ + struct { + int32 len; + char str[len]; + } sub; + + struct { + sub data[1]; + } test; + """ + cs.load(cdef) + + assert cs.sub.dynamic + assert cs.test.dynamic diff --git a/tests/test_parser.py b/tests/test_parser.py index 193980b..232ba26 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -1,6 +1,5 @@ from unittest.mock import Mock -from dissect.cstruct import cstruct from dissect.cstruct.parser import TokenParser @@ -24,20 +23,3 @@ def test_preserve_comment_newlines(): mock_token.match.start.return_value = data.index("#define multi_anchor") assert TokenParser._lineno(mock_token) == 9 - - -def test_dynamic_substruct_size(cs: cstruct): - cdef = """ - struct { - int32 len; - char str[len]; - } sub; - - struct { - sub data[1]; - } test; - """ - cs.load(cdef) - - assert cs.sub.dynamic - assert cs.test.dynamic