Skip to content

Commit

Permalink
Fix setting dynamic field for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper committed Jan 6, 2024
1 parent e26407a commit 768f035
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
1 change: 1 addition & 0 deletions dissect/cstruct/types/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 0 additions & 18 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from unittest.mock import Mock

from dissect.cstruct import cstruct
from dissect.cstruct.parser import TokenParser


Expand All @@ -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

0 comments on commit 768f035

Please sign in to comment.