tests: add sanity check on insn->detail, since it can be NULL when SKIPDATA option is ON
diff --git a/tests/test.c b/tests/test.c
index 0565808..655eb7f 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -30,8 +30,8 @@
static void test()
{
-#define X86_CODE16 "\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00"
-#define X86_CODE32 "\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00"
+#define X86_CODE16 "\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00"
+#define X86_CODE32 "\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00\x00\x91\x92"
//#define X86_CODE32 "\x0f\xa7\xc0" // xstorerng
#define X86_CODE64 "\x55\x48\x8b\x05\xb8\x13\x00\x00"
//#define ARM_CODE "\x04\xe0\x2d\xe5"
@@ -187,6 +187,9 @@
if (platforms[i].opt_type)
cs_option(handle, platforms[i].opt_type, platforms[i].opt_value);
+ // turn on SKIPDATA option, but just use default option to skip 1 byte on data
+ cs_option(handle, CS_OPT_SKIPDATA, CS_OPT_ON);
+
size_t count = cs_disasm_ex(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
if (count) {
print_string_hex(platforms[i].code, platforms[i].size);
diff --git a/tests/test_arm.c b/tests/test_arm.c
index 2aefdf1..7b3a86c 100644
--- a/tests/test_arm.c
+++ b/tests/test_arm.c
@@ -32,7 +32,13 @@
static void print_insn_detail(cs_insn *ins)
{
- cs_arm *arm = &(ins->detail->arm);
+ cs_arm *arm;
+
+ // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
+ if (ins->detail == NULL)
+ return;
+
+ arm = &(ins->detail->arm);
if (arm->op_count)
printf("\top_count: %u\n", arm->op_count);
diff --git a/tests/test_arm64.c b/tests/test_arm64.c
index 8b44e17..4418e12 100644
--- a/tests/test_arm64.c
+++ b/tests/test_arm64.c
@@ -31,9 +31,14 @@
static void print_insn_detail(cs_insn *ins)
{
- cs_arm64 *arm64 = &(ins->detail->arm64);
+ cs_arm64 *arm64;
int i;
+ // detail can be NULL if SKIPDATA option is turned ON
+ if (ins->detail == NULL)
+ return;
+
+ arm64 = &(ins->detail->arm64);
if (arm64->op_count)
printf("\top_count: %u\n", arm64->op_count);
diff --git a/tests/test_detail.c b/tests/test_detail.c
index a45a739..abe0192 100644
--- a/tests/test_detail.c
+++ b/tests/test_detail.c
@@ -201,6 +201,10 @@
// print implicit registers used by this instruction
cs_detail *detail = i->detail;
+ // detail can be NULL on "data" instruction since we turned on SKIPDATA option above.
+ if (!detail)
+ continue;
+
if (detail->regs_read_count > 0) {
printf("\tImplicit registers read: ");
for (n = 0; n < detail->regs_read_count; n++) {
diff --git a/tests/test_mips.c b/tests/test_mips.c
index fb6ea96..fcbefa1 100644
--- a/tests/test_mips.c
+++ b/tests/test_mips.c
@@ -31,8 +31,13 @@
static void print_insn_detail(cs_insn *ins)
{
- cs_mips *mips = &(ins->detail->mips);
+ cs_mips *mips;
+ // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
+ if (ins->detail == NULL)
+ return;
+
+ mips = &(ins->detail->mips);
if (mips->op_count)
printf("\top_count: %u\n", mips->op_count);
diff --git a/tests/test_ppc.c b/tests/test_ppc.c
index 548e0c5..7620a11 100644
--- a/tests/test_ppc.c
+++ b/tests/test_ppc.c
@@ -30,8 +30,13 @@
static void print_insn_detail(cs_insn *ins)
{
- cs_ppc *ppc = &(ins->detail->ppc);
+ cs_ppc *ppc;
+ // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
+ if (ins->detail == NULL)
+ return;
+
+ ppc = &(ins->detail->ppc);
if (ppc->op_count)
printf("\top_count: %u\n", ppc->op_count);
diff --git a/tests/test_sparc.c b/tests/test_sparc.c
index e0b4689..8b6ca06 100644
--- a/tests/test_sparc.c
+++ b/tests/test_sparc.c
@@ -30,8 +30,13 @@
static void print_insn_detail(cs_insn *ins)
{
- cs_sparc *sparc = &(ins->detail->sparc);
+ cs_sparc *sparc;
+ // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
+ if (ins->detail == NULL)
+ return;
+
+ sparc = &(ins->detail->sparc);
if (sparc->op_count)
printf("\top_count: %u\n", sparc->op_count);
diff --git a/tests/test_systemz.c b/tests/test_systemz.c
index 13d42f7..80b9330 100644
--- a/tests/test_systemz.c
+++ b/tests/test_systemz.c
@@ -30,8 +30,13 @@
static void print_insn_detail(cs_insn *ins)
{
- cs_sysz *sysz = &(ins->detail->sysz);
+ cs_sysz *sysz;
+ // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
+ if (ins->detail == NULL)
+ return;
+
+ sysz = &(ins->detail->sysz);
if (sysz->op_count)
printf("\top_count: %u\n", sysz->op_count);
diff --git a/tests/test_x86.c b/tests/test_x86.c
index 6086c58..00a633b 100644
--- a/tests/test_x86.c
+++ b/tests/test_x86.c
@@ -34,7 +34,13 @@
static void print_insn_detail(csh ud, cs_mode mode, cs_insn *ins)
{
int i;
- cs_x86 *x86 = &(ins->detail->x86);
+ cs_x86 *x86;
+
+ // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
+ if (ins->detail == NULL)
+ return;
+
+ x86 = &(ins->detail->x86);
print_string_hex("\tPrefix:", x86->prefix, 5);