Skip to content

Commit

Permalink
reset prev_prefix at the entry of cs_disasm_ex(). this fixes a nasty …
Browse files Browse the repository at this point in the history
…segfault bug
  • Loading branch information
aquynh committed Jan 22, 2014
1 parent 9162aa1 commit 11b0519
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ size_t cs_disasm_ex(csh ud, const uint8_t *buffer, size_t size, uint64_t offset,

handle->errnum = CS_ERR_OK;

// reset previous prefix for X86
handle->prev_prefix = 0;

memset(insn_cache, 0, sizeof(insn_cache));

while (size > 0) {
Expand Down
8 changes: 8 additions & 0 deletions suite/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
)


# for debugging
def to_hex(s):
return " ".join("0x" + "{0:x}".format(ord(c)).zfill(2) for c in s) # <-- Python 3 is OK

def get_code(f, size):
code = f.read(size)
if len(code) != size: # reached end-of-file?
Expand Down Expand Up @@ -77,12 +81,16 @@ def cs(md, code):
cfile.seek(0)
for i in xrange(3):
code = get_code(cfile, 128)
#print to_hex(code)
#print
cs(md, code)

# start real benchmark
c_t = 0
for i in xrange(50000):
code = get_code(cfile, 128)
#print to_hex(code)
#print

t1 = time()
cs(md, code)
Expand Down

0 comments on commit 11b0519

Please sign in to comment.