Skip to content

StructMembers() operates incorrectly on structures with gaps #90

@GoogleCodeExporter

Description

@GoogleCodeExporter
# What steps will reproduce the problem?

1. Create a structure with gaps in it:

00000000 MyExampleStruc struc ; (sizeof=0x101)
00000000 None db ?
00000001 bar db ?
00000002     db ? ; undefined
00000003     db ? ; undefined
00000004     db ? ; undefined
00000005     db ? ; undefined
00000006 field_6 dd ?
0000000A field_A db ?
0000000B     db ? ; undefined
...
00000012     db ? ; undefined
00000013 xxx dd ?
00000017     db ? ; undefined
...
000000EF     db ? ; undefined
000000F0 Field2 dd ?
000000F4     db ? ; undefined
...
000000FD     db ? ; undefined
000000FE Field3 dw ?
00000100 xField db ?
00000101 MyExampleStruc ends

2. Iterate over the fields in the structure with StructMembers:
for (o,n,s) in StructMembers(sid): print "%s @ %s-%s" % (n,o,o+(s or 0))

# What is the expected output? 

Python>for (o,n,s) in StructMembers2(sid): print "%s @ %s-%s" % (n,o,o+(s or 0))
None @ 0-1
bar @ 1-2
field_6 @ 6-10
field_A @ 10-11
xxx @ 19-23
Field2 @ 240-244
Field3 @ 254-256
xField @ 256-257

# What do you see instead?

Python>for (o,n,s) in StructMembers(sid): print "%s @ %s-%s" % (n,o,o+(s or 0))
None @ 0-1
bar @ 1-2
None @ 2-2
None @ 3-3
None @ 4-4
None @ 5-5
field_6 @ 6-10
field_A @ 10-11

# What version of the product are you using? On what operating system?

6.4.130306

# Please provide any additional information below.

I have attached a patch which resolves the issue.

Original issue reported on code.google.com by zachrig...@gmail.com on 29 Nov 2013 at 4:31

Attachments:

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions