Skip to content

Commit

Permalink
Fix regressions in custom memory allocator support (#2251)
Browse files Browse the repository at this point in the history
Where new code started using malloc()/calloc()/free() directly instead
of going through cs_mem_*().
  • Loading branch information
oleavr authored Jan 20, 2024
1 parent 28d0b20 commit 31ea133
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
4 changes: 2 additions & 2 deletions arch/AArch64/AArch64GenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33295,11 +33295,11 @@ static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS) {
while (AsmString[I] != ' ' && AsmString[I] != '\t' &&
AsmString[I] != '$' && AsmString[I] != '\0')
++I;
char *substr = malloc(I+1);
char *substr = cs_mem_malloc(I+1);
memcpy(substr, AsmString, I);
substr[I] = '\0';
SStream_concat0(OS, substr);
free(substr);
cs_mem_free(substr);
if (AsmString[I] != '\0') {
if (AsmString[I] == ' ' || AsmString[I] == '\t') {
SStream_concat1(OS, ' ');
Expand Down
4 changes: 2 additions & 2 deletions arch/AArch64/AArch64InstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ DEFINE_printMatrix(0);
const char *RegName = getRegisterName(MCOperand_getReg(RegOp), AArch64_NoRegAltName); \
\
unsigned buf_len = strlen(RegName) + 1; \
char *Base = calloc(1, buf_len); \
char *Base = cs_mem_calloc(1, buf_len); \
memcpy(Base, RegName, buf_len); \
char *Dot = strchr(Base, '.'); \
if (!Dot) { \
Expand All @@ -1326,7 +1326,7 @@ DEFINE_printMatrix(0);
SStream_concat(O, "%s%s", Base, (IsVertical ? "v" : "h")); \
SStream_concat1(O, '.'); \
SStream_concat0(O, Suffix); \
free(Base); \
cs_mem_free(Base); \
}
DEFINE_printMatrixTileVector(0);
DEFINE_printMatrixTileVector(1);
Expand Down
7 changes: 2 additions & 5 deletions arch/ARM/ARMDisassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,11 +955,8 @@ DecodeStatus AddThumbPredicate(MCInst *MI)
assert(TiedOp >= 0 &&
"Inactive register in vpred_r is not tied to an output!");
// Copy the operand to ensure it's not invalidated when MI grows.
MCOperand *Op = malloc(sizeof(MCOperand));
memcpy(Op, MCInst_getOperand(MI, TiedOp),
sizeof(MCOperand));
MCInst_insert0(MI, VCCPos + 3, Op);
free(Op);
MCOperand Op = *MCInst_getOperand(MI, TiedOp);
MCInst_insert0(MI, VCCPos + 3, &Op);
}
} else if (VCC != ARMVCC_None) {
Check(&S, MCDisassembler_SoftFail);
Expand Down
4 changes: 2 additions & 2 deletions arch/ARM/ARMGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13298,11 +13298,11 @@ static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS)
while (AsmString[I] != ' ' && AsmString[I] != '\t' &&
AsmString[I] != '$' && AsmString[I] != '\0')
++I;
char *substr = malloc(I + 1);
char *substr = cs_mem_malloc(I + 1);
memcpy(substr, AsmString, I);
substr[I] = '\0';
SStream_concat0(OS, substr);
free(substr);
cs_mem_free(substr);
if (AsmString[I] != '\0') {
if (AsmString[I] == ' ' || AsmString[I] == '\t') {
SStream_concat1(OS, ' ');
Expand Down
4 changes: 2 additions & 2 deletions arch/PowerPC/PPCGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15689,11 +15689,11 @@ static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS) {
while (AsmString[I] != ' ' && AsmString[I] != '\t' &&
AsmString[I] != '$' && AsmString[I] != '\0')
++I;
char *substr = malloc(I+1);
char *substr = cs_mem_malloc(I+1);
memcpy(substr, AsmString, I);
substr[I] = '\0';
SStream_concat0(OS, substr);
free(substr);
cs_mem_free(substr);
if (AsmString[I] != '\0') {
if (AsmString[I] == ' ' || AsmString[I] == '\t') {
SStream_concat1(OS, ' ');
Expand Down

0 comments on commit 31ea133

Please sign in to comment.