Fix compile warnings under CMake -Wall

This commit is contained in:
billow 2023-05-28 11:48:59 +08:00
parent 8920374073
commit 9bb4f81961
5 changed files with 20 additions and 26 deletions

View File

@ -35,7 +35,7 @@ static char *hex_string(unsigned char *str, size_t len)
if (!hex_out) { goto Exit; }
for (i = 0; i < len; ++i) {
snprintf(hex_out + (i*2), 2, "%02x", str[i]);
snprintf(hex_out + (i*2), 3, "%02x", str[i]);
}
hex_out[len*2] = 0; // trailing null
@ -46,8 +46,6 @@ Exit:
static void snprint_insn_detail(char * buf, size_t * cur, size_t * left, cs_insn *ins)
{
size_t used = 0;
#define _this_printf(...) \
{ \
size_t used = 0; \
@ -84,10 +82,10 @@ static void snprint_insn_detail(char * buf, size_t * cur, size_t * left, cs_insn
break;
case ARM_OP_MEM:
_this_printf("\t\toperands[%u].type: MEM\n", i);
if (op->mem.base != X86_REG_INVALID)
if (op->mem.base != ARM_REG_INVALID)
_this_printf("\t\t\toperands[%u].mem.base: REG = %s\n",
i, cs_reg_name(handle, op->mem.base));
if (op->mem.index != X86_REG_INVALID)
if (op->mem.index != ARM_REG_INVALID)
_this_printf("\t\t\toperands[%u].mem.index: REG = %s\n",
i, cs_reg_name(handle, op->mem.index));
if (op->mem.scale != 1)
@ -287,8 +285,6 @@ static void test_valids()
}};
struct valid_instructions * valid = NULL;
uint64_t address = 0x1000;
cs_insn *insn;
int i;
int j;
@ -323,8 +319,6 @@ static void test_valids()
char tmp_buf[2048];
size_t left = 2048;
size_t cur = 0;
size_t used = 0;
int success = 0;
char * hex_str = NULL;
struct valid_code * valid_code = NULL;

View File

@ -9,8 +9,8 @@ char *(*function)(csh *, cs_mode, cs_insn*) = NULL;
void test_single_MC(csh *handle, int mc_mode, char *line)
{
char **list_part, **list_byte;
int size_part, size_byte, size_data, size_insn;
int i, count, count_noreg;
int size_part, size_byte;
int i, count;
unsigned char *code;
cs_insn *insn;
char tmp[MAXMEM], tmp_mc[MAXMEM], origin[MAXMEM], tmp_noreg[MAXMEM];
@ -72,7 +72,7 @@ void test_single_MC(csh *handle, int mc_mode, char *line)
replace_negative(tmp, mc_mode);
if (cs_option(*handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_NOREGNAME) == CS_ERR_OK) {
count_noreg = cs_disasm(*handle, code, size_byte, offset, 0, &insn);
cs_disasm(*handle, code, size_byte, offset, 0, &insn);
strcpy(tmp_noreg, insn[0].mnemonic);
if (strlen(insn[0].op_str) > 0) {
tmp_noreg[strlen(insn[0].mnemonic)] = ' ';
@ -192,8 +192,8 @@ int set_function(int arch)
void test_single_issue(csh *handle, cs_mode mode, char *line, int detail)
{
char **list_part, **list_byte, **list_part_cs_result, **list_part_issue_result;
int size_part, size_byte, size_part_cs_result, size_part_issue_result;
char **list_part, **list_byte, **list_part_issue_result;
int size_part, size_byte, size_part_issue_result;
char *tmptmp;
int i, count, j;
unsigned char *code;
@ -246,7 +246,7 @@ void test_single_issue(csh *handle, cs_mode mode, char *line, int detail)
}
}
}
trim_str(cs_result);
add_str(&cs_result, " ;");
// list_part_cs_result = split(cs_result, " ; ", &size_part_cs_result);
@ -255,8 +255,8 @@ void test_single_issue(csh *handle, cs_mode mode, char *line, int detail)
for (i = 0; i < size_part_issue_result; ++i) {
trim_str(list_part_issue_result[i]);
memset(tmptmp, MAXMEM, 0);
memset(tmptmp, 0, MAXMEM);
tmptmp = (char *)malloc(sizeof(char));
tmptmp[0] = '\0';
add_str(&tmptmp, "%s", list_part_issue_result[i]);

View File

@ -108,7 +108,7 @@ void add_str(char **src, const char *format, ...)
void replace_hex(char *src)
{
char *tmp, *result, *found, *origin, *orig_found;
int i, valid;
int valid;
unsigned long long int value;
char *tmp_tmp;
@ -155,7 +155,7 @@ void replace_hex(char *src)
void replace_negative(char *src, int mode)
{
char *tmp, *result, *found, *origin, *orig_found;
int i, cnt, valid;
int cnt, valid;
char *value, *tmp_tmp;
unsigned short int tmp_short;
unsigned int tmp_int;

View File

@ -140,7 +140,7 @@ static int setup_MC(void **state)
char **list_params;
int size_params;
int arch, mode;
int i, index, tmp_counter;
int i, tmp_counter;
if (failed_setup) {
fprintf(stderr, "[ ERROR ] --- Invalid file to setup\n");
@ -241,8 +241,7 @@ static int setup_issue(void **state)
char **list_params;
int size_params;
int arch, mode;
int i, index, result;
char *(*function)(csh *, cs_mode, cs_insn*);
int i, result;
getDetail = 0;
failed_setup = 0;
@ -369,11 +368,10 @@ static int teardown_issue(void **state)
static void test_file(const char *filename)
{
int size, i;
char **list_str;
int i;
char *content, *tmp;
struct CMUnitTest *tests;
int issue_num, number_of_tests;
int number_of_tests;
printf("[+] TARGET: %s\n", filename);
content = readfile(filename);

View File

@ -96,7 +96,7 @@ static void print_insn_detail(csh handle, cs_insn *insn)
break;
case SH_OP_IMM:
printf("\t\toperands[%u].type: IMMEDIATE = #%d\n", i,
printf("\t\toperands[%u].type: IMMEDIATE = #%lu\n", i,
op->imm);
break;
@ -138,6 +138,8 @@ static void print_insn_detail(csh handle, cs_insn *insn)
printf("TBR base with displacement DISP %d\n",
op->mem.disp);
break;
case SH_OP_MEM_INVALID:
break;
}
break;
}