core: C99 fix for cs_disasm_ex()

This commit is contained in:
Nguyen Anh Quynh 2014-03-06 22:40:08 +08:00
parent 472a4a4121
commit 034a7487c0

7
cs.c
View File

@ -324,6 +324,7 @@ size_t cs_disasm_ex(csh ud, const uint8_t *buffer, size_t size, uint64_t offset,
cs_insn insn_cache[INSN_CACHE_SIZE]; cs_insn insn_cache[INSN_CACHE_SIZE];
void *total = NULL; void *total = NULL;
size_t total_size = 0; size_t total_size = 0;
bool r;
if (!handle) { if (!handle) {
// FIXME: how to handle this case: // FIXME: how to handle this case:
@ -342,7 +343,7 @@ size_t cs_disasm_ex(csh ud, const uint8_t *buffer, size_t size, uint64_t offset,
MCInst_Init(&mci); MCInst_Init(&mci);
mci.csh = handle; mci.csh = handle;
bool r = handle->disasm(ud, buffer, size, &mci, &insn_size, offset, handle->getinsn_info); r = handle->disasm(ud, buffer, size, &mci, &insn_size, offset, handle->getinsn_info);
if (r) { if (r) {
SStream ss; SStream ss;
SStream_Init(&ss); SStream_Init(&ss);
@ -368,8 +369,10 @@ size_t cs_disasm_ex(csh ud, const uint8_t *buffer, size_t size, uint64_t offset,
if (f == ARR_SIZE(insn_cache)) { if (f == ARR_SIZE(insn_cache)) {
// resize total to contain newly disasm insns // resize total to contain newly disasm insns
void *tmp;
total_size += (sizeof(cs_insn) * INSN_CACHE_SIZE); total_size += (sizeof(cs_insn) * INSN_CACHE_SIZE);
void *tmp = cs_mem_realloc(total, total_size); tmp = cs_mem_realloc(total, total_size);
if (tmp == NULL) { // insufficient memory if (tmp == NULL) { // insufficient memory
cs_mem_free(total); cs_mem_free(total);
handle->errnum = CS_ERR_MEM; handle->errnum = CS_ERR_MEM;