Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper committed Sep 4, 2023
1 parent ffe4da8 commit 4860562
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dissect/cstruct/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def _generate_struct_info(cs: cstruct, fields: list[Field], align: bool = False)
current_offset += size


def _optimize_struct_fmt(info: Iterator[tuple[Field, int, str]]):
def _optimize_struct_fmt(info: Iterator[tuple[Field, int, str]]) -> str:
chars = []

current_count = 0
Expand Down
2 changes: 1 addition & 1 deletion dissect/cstruct/types/char.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def _read(cls, stream: BinaryIO, context: dict[str, Any] = None) -> Char:
@classmethod
def _read_array(cls, stream: BinaryIO, count: int, context: dict[str, Any] = None) -> Char:
if count == 0:
return b""
return type.__call__(cls, b"")

Check warning on line 18 in dissect/cstruct/types/char.py

View check run for this annotation

Codecov / codecov/patch

dissect/cstruct/types/char.py#L18

Added line #L18 was not covered by tests

data = stream.read(-1 if count == EOF else count)
if count != EOF and len(data) != count:
Expand Down
1 change: 1 addition & 0 deletions dissect/cstruct/types/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def _write_0(cls, stream: BinaryIO, array: list[BaseType]) -> int:

def _fix_alias_members(cls: type[Enum]):
# Emulate aenum NoAlias behaviour
# https://github.com/ethanfurman/aenum/blob/master/aenum/doc/aenum.rst
if len(cls._member_names_) == len(cls._member_map_):
return

Expand Down
4 changes: 1 addition & 3 deletions dissect/cstruct/types/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,7 @@ class Union(Structure, metaclass=UnionMetaType):
"""Base class for cstruct union type classes."""

def __eq__(self, other: Any) -> bool:
if self.__class__ is other.__class__:
return bytes(self) == bytes(other)
return False
return self.__class__ is other.__class__ and bytes(self) == bytes(other)


def _codegen(func: FunctionType) -> FunctionType:
Expand Down
6 changes: 3 additions & 3 deletions dissect/cstruct/types/wchar.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _read(cls, stream: BinaryIO, context: dict[str, Any] = None) -> Wchar:
@classmethod
def _read_array(cls, stream: BinaryIO, count: int, context: dict[str, Any] = None) -> Wchar:
if count == 0:
return ""
return type.__call__(cls, "")

if count != EOF:
count *= 2
Expand All @@ -40,8 +40,8 @@ def _read_0(cls, stream: BinaryIO, context: dict[str, Any] = None) -> Wchar:
buf = []
while True:
point = stream.read(2)
if len(point) != 2:
raise EOFError("Read 0 bytes, but expected 2")
if (bytes_read := len(point)) != 2:
raise EOFError(f"Read {bytes_read} bytes, but expected 2")

if point == b"\x00\x00":
break
Expand Down

0 comments on commit 4860562

Please sign in to comment.