From 041e25dd66fdf7500dc08de03e66b7539323e8eb Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Fri, 6 Dec 2013 00:37:32 +0800 Subject: [PATCH] add CS_ERR_OPTION type. cs_option() returns this error code on invalid option --- cs.c | 10 +++++++--- include/capstone.h | 12 +++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cs.c b/cs.c index 9cf1864d6..abb2af0f3 100644 --- a/cs.c +++ b/cs.c @@ -209,20 +209,24 @@ cs_err cs_option(csh ud, cs_opt_type type, size_t value) switch (handle->arch) { default: - break; + return CS_ERR_OPTION; + case CS_ARCH_X86: if (type & CS_OPT_SYNTAX) { switch(value) { default: - break; + return CS_ERR_OPTION; + case CS_OPT_SYNTAX_INTEL: handle->printer = X86_Intel_printInst; break; + case CS_OPT_SYNTAX_ATT: handle->printer = X86_ATT_printInst; break; } - } + } else + return CS_ERR_OPTION; break; } diff --git a/include/capstone.h b/include/capstone.h index c4c133a72..d635b4dad 100644 --- a/include/capstone.h +++ b/include/capstone.h @@ -104,14 +104,16 @@ typedef struct cs_insn { // These are values returned by cs_errno() typedef enum cs_err { CS_ERR_OK = 0, // No error: everything was fine - CS_ERR_MEM, // Out-Of-Memory error - CS_ERR_ARCH, // Unsupported architecture - CS_ERR_HANDLE, // Invalid handle - CS_ERR_CSH, // Invalid csh argument - CS_ERR_MODE, // Invalid/unsupported mode + CS_ERR_MEM, // Out-Of-Memory error: cs_open(), cs_disasm_dyn() + CS_ERR_ARCH, // Unsupported architecture: cs_open() + CS_ERR_HANDLE, // Invalid handle: cs_op_count(), cs_op_index() + CS_ERR_CSH, // Invalid csh argument: cs_close(), cs_errno(), cs_option() + CS_ERR_MODE, // Invalid/unsupported mode: cs_open() + CS_ERR_OPTION, // Invalid/unsupported option: cs_option() } cs_err; + /* Return API version in major and minor numbers.