2017-05-09 12:18:17 +00:00
|
|
|
diff --git a/MCInst.c b/MCInst.c
|
2018-07-15 20:12:45 +00:00
|
|
|
index 1694e5d..758c43f 100644
|
2017-05-09 12:18:17 +00:00
|
|
|
--- a/MCInst.c
|
|
|
|
+++ b/MCInst.c
|
2018-07-15 20:12:45 +00:00
|
|
|
@@ -18,20 +18,10 @@
|
2017-05-09 12:18:17 +00:00
|
|
|
void MCInst_Init(MCInst *inst)
|
|
|
|
{
|
2018-06-11 00:57:22 +00:00
|
|
|
unsigned int i;
|
|
|
|
-
|
|
|
|
+ memset (inst, 0, sizeof (MCInst));
|
|
|
|
for (i = 0; i < 48; i++) {
|
|
|
|
inst->Operands[i].Kind = kInvalid;
|
|
|
|
}
|
|
|
|
-
|
2017-10-19 16:23:37 +00:00
|
|
|
- inst->Opcode = 0;
|
2017-05-09 12:18:17 +00:00
|
|
|
- inst->OpcodePub = 0;
|
|
|
|
- inst->size = 0;
|
|
|
|
- inst->has_imm = false;
|
|
|
|
- inst->op1_size = 0;
|
|
|
|
- inst->writeback = false;
|
|
|
|
- inst->ac_idx = 0;
|
|
|
|
- inst->popcode_adjust = 0;
|
|
|
|
- inst->assembly[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCInst_clear(MCInst *inst)
|
|
|
|
diff --git a/cs.c b/cs.c
|
2018-07-15 20:12:45 +00:00
|
|
|
index d2ffecc..f12051a 100644
|
2017-05-09 12:18:17 +00:00
|
|
|
--- a/cs.c
|
|
|
|
+++ b/cs.c
|
2018-07-15 20:12:45 +00:00
|
|
|
@@ -840,7 +840,7 @@ size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64
|
2017-05-09 12:18:17 +00:00
|
|
|
size_org = size;
|
|
|
|
|
|
|
|
total_size = sizeof(cs_insn) * cache_size;
|
|
|
|
- total = cs_mem_malloc(total_size);
|
2018-01-09 17:37:50 +00:00
|
|
|
+ total = cs_mem_calloc(1, total_size);
|
2017-05-09 12:18:17 +00:00
|
|
|
if (total == NULL) {
|
|
|
|
// insufficient memory
|
|
|
|
handle->errnum = CS_ERR_MEM;
|
2018-07-15 20:12:45 +00:00
|
|
|
@@ -858,7 +858,7 @@ size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64
|
2017-05-09 12:18:17 +00:00
|
|
|
|
|
|
|
if (handle->detail) {
|
|
|
|
// allocate memory for @detail pointer
|
|
|
|
- insn_cache->detail = cs_mem_malloc(sizeof(cs_detail));
|
2018-01-09 17:37:50 +00:00
|
|
|
+ insn_cache->detail = cs_mem_calloc(1, sizeof(cs_detail));
|
2017-05-09 12:18:17 +00:00
|
|
|
} else {
|
|
|
|
insn_cache->detail = NULL;
|
|
|
|
}
|
2018-07-15 20:12:45 +00:00
|
|
|
@@ -946,6 +946,7 @@ size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64
|
2017-05-09 12:18:17 +00:00
|
|
|
if (f == cache_size) {
|
|
|
|
// full cache, so expand the cache to contain incoming insns
|
|
|
|
cache_size = cache_size * 8 / 5; // * 1.6 ~ golden ratio
|
|
|
|
+ unsigned int old_size = total_size;
|
|
|
|
total_size += (sizeof(cs_insn) * cache_size);
|
|
|
|
tmp = cs_mem_realloc(total, total_size);
|
|
|
|
if (tmp == NULL) { // insufficient memory
|
2018-07-15 20:12:45 +00:00
|
|
|
@@ -960,7 +961,7 @@ size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64
|
2017-05-09 12:18:17 +00:00
|
|
|
handle->errnum = CS_ERR_MEM;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-01-09 17:37:50 +00:00
|
|
|
-
|
2018-05-28 09:03:19 +00:00
|
|
|
+ memset ((char *)total + (sizeof(cs_insn) * old_size), 0, (total_size - old_size));
|
2017-05-09 12:18:17 +00:00
|
|
|
total = tmp;
|
|
|
|
// continue to fill in the cache after the last instruction
|
2018-01-09 17:37:50 +00:00
|
|
|
insn_cache = (cs_insn *)((char *)total + sizeof(cs_insn) * c);
|