mirror of
https://github.com/capstone-engine/capstone.git
synced 2025-03-04 20:39:50 +00:00
add new error code CS_ERR_MEMSETUP to report error when user-defined dynamic mem management is uninitialized
This commit is contained in:
parent
1044c3e912
commit
c52352d6d9
9
cs.c
9
cs.c
@ -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) |
|
||||
@ -79,6 +79,8 @@ 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)";
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,6 +88,11 @@ 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
|
||||
|
@ -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];
|
||||
@ -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;
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user