Skip to content

Commit

Permalink
add new error code CS_ERR_MEMSETUP to report error when user-defined …
Browse files Browse the repository at this point in the history
…dynamic mem management is uninitialized
  • Loading branch information
aquynh committed Jan 6, 2014
1 parent 1044c3e commit c52352d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ unsigned int cs_version(int *major, int *minor)
return (CS_API_MAJOR << 8) + CS_API_MINOR;
}

bool cs_support(cs_arch arch)
bool cs_support(int arch)
{
if (arch == CS_ARCH_ALL)
return all_arch == ((1 << CS_ARCH_ARM) | (1 << CS_ARCH_ARM64) |
Expand Down Expand Up @@ -79,13 +79,20 @@ const char *cs_strerror(cs_err code)
return "Invalid option (CS_ERR_OPTION)";
case CS_ERR_DETAIL:
return "Details are unavailable (CS_ERR_DETAIL)";
case CS_ERR_MEMSETUP:
return "Dynamic memory management uninitialized (CS_ERR_MEMSETUP)";
}
}

cs_err cs_open(cs_arch arch, cs_mode mode, csh *handle)
{
cs_struct *ud;

if (!my_malloc || !my_calloc || !my_realloc || !my_free)
// Error: before cs_open(), dynamic memory management must be initialized
// with cs_option(CS_OPT_MEM)
return CS_ERR_MEMSETUP;

ud = my_calloc(1, sizeof(*ud));
if (!ud) {
// memory insufficient
Expand Down
2 changes: 1 addition & 1 deletion include/capstone.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ typedef struct cs_insn {
// Ascii text of instruction mnemonic
// This information is available even when CS_OPT_DETAIL = CS_OPT_OFF
char mnemonic[32];

// Ascii text of instruction operands
// This information is available even when CS_OPT_DETAIL = CS_OPT_OFF
char op_str[96];
Expand Down Expand Up @@ -160,6 +159,7 @@ typedef enum cs_err {
CS_ERR_MODE, // Invalid/unsupported mode: cs_open()
CS_ERR_OPTION, // Invalid/unsupported option: cs_option()
CS_ERR_DETAIL, // Information is unavailable because detail option is OFF
CS_ERR_MEMSETUP, // Dynamic memory management uninitialized (see CS_OPT_MEM)
} cs_err;

/*
Expand Down

0 comments on commit c52352d

Please sign in to comment.