diff --git a/binr/r2agent/r2agent.c b/binr/r2agent/r2agent.c
index d66fe55c60..8f14f699a9 100644
--- a/binr/r2agent/r2agent.c
+++ b/binr/r2agent/r2agent.c
@@ -102,7 +102,9 @@ int main(int argc, char **argv) {
const char *result = page_index;
rs = r_socket_http_accept (s, 0, timeout);
- if (!rs) continue;
+ if (!rs) {
+ continue;
+ }
if (!strcmp (rs->method, "GET")) {
if (!strncmp (rs->path, "/proc/kill/", 11)) {
// TODO: show page here?
diff --git a/binr/rabin2/rabin2.c b/binr/rabin2/rabin2.c
index d4327d9509..a2687afc1c 100644
--- a/binr/rabin2/rabin2.c
+++ b/binr/rabin2/rabin2.c
@@ -879,7 +879,9 @@ int main(int argc, char **argv) {
*p2++ = 0;
data = malloc (strlen (p2)+1);
datalen = r_hex_str2bin (p2, data);
- if (datalen < 0) datalen = -datalen;
+ if (datalen < 0) {
+ datalen = -datalen;
+ }
} else {
data = NULL;
datalen = 0;
diff --git a/binr/radare2/radare2.c b/binr/radare2/radare2.c
index fe367cb5c4..50f92e0914 100644
--- a/binr/radare2/radare2.c
+++ b/binr/radare2/radare2.c
@@ -1427,12 +1427,16 @@ int main(int argc, char **argv, char **envp) {
r.num->value = 0;
break;
}
- if (lock) r_th_lock_enter (lock);
+ if (lock) {
+ r_th_lock_enter (lock);
+ }
/* -1 means invalid command, -2 means quit prompt loop */
if ((ret = r_core_prompt_exec (&r)) == -2) {
break;
}
- if (lock) r_th_lock_leave (lock);
+ if (lock) {
+ r_th_lock_leave (lock);
+ }
if (rabin_th && !r_th_wait_async (rabin_th)) {
// eprintf ("rabin thread end \n");
r_th_kill_free (rabin_th);
diff --git a/binr/rafind2/rafind2.c b/binr/rafind2/rafind2.c
index 1bac12ec94..535eb7da7d 100644
--- a/binr/rafind2/rafind2.c
+++ b/binr/rafind2/rafind2.c
@@ -83,7 +83,9 @@ static int hit(RSearchKeyword *kw, void *user, ut64 addr) {
static int show_help(char *argv0, int line) {
printf ("Usage: %s [-mXnzZhqv] [-a align] [-b sz] [-f/t from/to] [-[e|s|S] str] [-x hex] file|dir ..\n", argv0);
- if (line) return 0;
+ if (line) {
+ return 0;
+ }
printf (
" -a [align] only accept aligned hits\n"
" -b [size] set block size\n"
@@ -136,7 +138,9 @@ static int rafind_open_file(char *file) {
r_cons_new ();
rs = r_search_new (mode);
- if (!rs) return 1;
+ if (!rs) {
+ return 1;
+ }
buf = calloc (1, bsize);
if (!buf) {
eprintf ("Cannot allocate %"PFMT64d" bytes\n", bsize);
diff --git a/binr/ragg2/ragg2.c b/binr/ragg2/ragg2.c
index 94909becb1..c104e3dbc4 100644
--- a/binr/ragg2/ragg2.c
+++ b/binr/ragg2/ragg2.c
@@ -15,38 +15,39 @@ static int usage(int v) {
printf ("Usage: ragg2 [-FOLsrxhvz] [-a arch] [-b bits] [-k os] [-o file] [-I path]\n"
" [-i sc] [-e enc] [-B hex] [-c k=v] [-C file] [-p pad] [-q off]\n"
" [-q off] [-dDw off:hex] file|f.asm|-\n");
- if (v) printf (
- " -a [arch] select architecture (x86, mips, arm)\n"
- " -b [bits] register size (32, 64, ..)\n"
- " -B [hexpairs] append some hexpair bytes\n"
- " -c [k=v] set configuration options\n"
- " -C [file] append contents of file\n"
- " -d [off:dword] patch dword (4 bytes) at given offset\n"
- " -D [off:qword] patch qword (8 bytes) at given offset\n"
- " -e [encoder] use specific encoder. see -L\n"
- " -f [format] output format (raw, c, pe, elf, mach0, python, javascript)\n"
- " -F output native format (osx=mach0, linux=elf, ..)\n"
- " -h show this help\n"
- " -i [shellcode] include shellcode plugin, uses options. see -L\n"
- " -I [path] add include path\n"
- " -k [os] operating system's kernel (linux,bsd,osx,w32)\n"
- " -L list all plugins (shellcodes and encoders)\n"
- " -n [dword] append 32bit number (4 bytes)\n"
- " -N [dword] append 64bit number (8 bytes)\n"
- " -o [file] output file\n"
- " -O use default output file (filename without extension or a.out)\n"
- " -p [padding] add padding after compilation (padding=n10s32)\n"
- " ntas : begin nop, trap, 'a', sequence\n"
- " NTAS : same as above, but at the end\n"
- " -P [size] prepend debruijn pattern\n"
- " -q [fragment] debruijn pattern offset\n"
- " -r show raw bytes instead of hexpairs\n"
- " -s show assembler\n"
- " -v show version\n"
- " -w [off:hex] patch hexpairs at given offset\n"
- " -x execute\n"
- " -z output in C string syntax\n"
- );
+ if (v) {
+ printf (
+ " -a [arch] select architecture (x86, mips, arm)\n"
+ " -b [bits] register size (32, 64, ..)\n"
+ " -B [hexpairs] append some hexpair bytes\n"
+ " -c [k=v] set configuration options\n"
+ " -C [file] append contents of file\n"
+ " -d [off:dword] patch dword (4 bytes) at given offset\n"
+ " -D [off:qword] patch qword (8 bytes) at given offset\n"
+ " -e [encoder] use specific encoder. see -L\n"
+ " -f [format] output format (raw, c, pe, elf, mach0, python, javascript)\n"
+ " -F output native format (osx=mach0, linux=elf, ..)\n"
+ " -h show this help\n"
+ " -i [shellcode] include shellcode plugin, uses options. see -L\n"
+ " -I [path] add include path\n"
+ " -k [os] operating system's kernel (linux,bsd,osx,w32)\n"
+ " -L list all plugins (shellcodes and encoders)\n"
+ " -n [dword] append 32bit number (4 bytes)\n"
+ " -N [dword] append 64bit number (8 bytes)\n"
+ " -o [file] output file\n"
+ " -O use default output file (filename without extension or a.out)\n"
+ " -p [padding] add padding after compilation (padding=n10s32)\n"
+ " ntas : begin nop, trap, 'a', sequence\n"
+ " NTAS : same as above, but at the end\n"
+ " -P [size] prepend debruijn pattern\n"
+ " -q [fragment] debruijn pattern offset\n"
+ " -r show raw bytes instead of hexpairs\n"
+ " -s show assembler\n"
+ " -v show version\n"
+ " -w [off:hex] patch hexpairs at given offset\n"
+ " -x execute\n"
+ " -z output in C string syntax\n");
+ }
return 1;
}
diff --git a/binr/rasm2/rasm2.c b/binr/rasm2/rasm2.c
index 38670c8a21..2e6bb5782d 100644
--- a/binr/rasm2/rasm2.c
+++ b/binr/rasm2/rasm2.c
@@ -84,8 +84,9 @@ static void rasm2_list(RAsm *la, const char *arch) {
if (h->cpus && !strcmp (arch, h->name)) {
char *c = strdup (h->cpus);
int n = r_str_split (c, ',');
- for (i = 0; i < n; i++)
+ for (i = 0; i < n; i++) {
printf ("%s\n", r_str_word_get0 (c, i));
+ }
free (c);
break;
}
@@ -94,15 +95,29 @@ static void rasm2_list(RAsm *la, const char *arch) {
if (h->bits == 27) {
strcat (bits, "27");
} else {
- if (h->bits & 8) strcat (bits, "8 ");
- if (h->bits & 16) strcat (bits, "16 ");
- if (h->bits & 32) strcat (bits, "32 ");
- if (h->bits & 64) strcat (bits, "64 ");
+ if (h->bits & 8) {
+ strcat (bits, "8 ");
+ }
+ if (h->bits & 16) {
+ strcat (bits, "16 ");
+ }
+ if (h->bits & 32) {
+ strcat (bits, "32 ");
+ }
+ if (h->bits & 64) {
+ strcat (bits, "64 ");
+ }
}
feat = "__";
- if (h->assemble && h->disassemble) feat = "ad";
- if (h->assemble && !h->disassemble) feat = "a_";
- if (!h->assemble && h->disassemble) feat = "_d";
+ if (h->assemble && h->disassemble) {
+ feat = "ad";
+ }
+ if (h->assemble && !h->disassemble) {
+ feat = "a_";
+ }
+ if (!h->assemble && h->disassemble) {
+ feat = "_d";
+ }
feat2 = has_esil (anal, h->name);
if (quiet) {
printf ("%s\n", h->name);
@@ -157,12 +172,15 @@ static int showanal(RAnal *lanal, RAnalOp *op, ut64 offset, ut8 *buf, int len, b
printf ("{\"opcode\": \"0x%08" PFMT64x "\",", offset);
printf ("\"bytes\": \"%s\",", bytes);
printf ("\"type\": \"%s\",", optype);
- if (op->jump != -1LL)
+ if (op->jump != -1LL) {
printf ("{\"jump\": \"0x%08" PFMT64x ",", op->jump);
- if (op->fail != -1LL)
+ }
+ if (op->fail != -1LL) {
printf ("{\"fail\": \"0x%08" PFMT64x ",", op->fail);
- if (op->val != -1LL)
+ }
+ if (op->val != -1LL) {
printf ("{\"value\": \"0x%08" PFMT64x ",", op->val);
+ }
printf ("\"stackop\": \"%s\",", stackop);
printf ("\"esil\": \"%s\",", r_strbuf_get (&op->esil));
printf ("\"stackptr\": \"0x%08" PFMT64x "\"", op->stackptr);
@@ -171,14 +189,17 @@ static int showanal(RAnal *lanal, RAnalOp *op, ut64 offset, ut8 *buf, int len, b
printf ("offset: 0x%08" PFMT64x "\n", offset);
printf ("bytes: %s\n", bytes);
printf ("type: %s\n", optype);
- if (op->jump != -1LL)
+ if (op->jump != -1LL) {
printf ("jump: 0x%08" PFMT64x "\n", op->jump);
- if (op->fail != -1LL)
+ }
+ if (op->fail != -1LL) {
printf ("fail: 0x%08" PFMT64x "\n", op->fail);
+ }
//if (op->ref != -1LL)
// printf ("ref: 0x%08"PFMT64x"\n", op->ref);
- if (op->val != -1LL)
+ if (op->val != -1LL) {
printf ("value: 0x%08" PFMT64x "\n", op->val);
+ }
printf ("stackop: %s\n", stackop);
printf ("esil: %s\n", r_strbuf_get (&op->esil));
printf ("stackptr: %" PFMT64d "\n", op->stackptr);
@@ -332,7 +353,9 @@ static void print_buf(char *str) {
printf ("\\x%c%c", *str, str[1]);
}
printf ("\"\n");
- } else printf ("%s\n", str);
+ } else {
+ printf ("%s\n", str);
+ }
}
static bool print_label(void *user, const char *k, void *v) {
@@ -443,8 +466,9 @@ int main (int argc, char *argv[]) {
&__lib_anal_cb, &__lib_anal_dt, NULL);
path = r_sys_getenv (R_LIB_ENV);
- if (path && *path)
+ if (path && *path) {
r_lib_opendir (l, path);
+ }
if (1) {
char *homeplugindir = r_str_home (R2_HOME_PLUGINS);
@@ -544,7 +568,9 @@ int main (int argc, char *argv[]) {
break;
case 'O':
fd = open (optarg, O_TRUNC | O_RDWR | O_CREAT, 0644);
- if (fd != -1) dup2 (fd, 1);
+ if (fd != -1) {
+ dup2 (fd, 1);
+ }
break;
case 'p':
use_spp = true;
@@ -595,8 +621,9 @@ int main (int argc, char *argv[]) {
goto beach;
}
r_anal_use (anal, arch);
- if (!strcmp (arch, "bf"))
+ if (!strcmp (arch, "bf")) {
ascii = 1;
+ }
} else if (env_arch) {
if (!r_asm_use (a, env_arch)) {
eprintf ("rasm2: Unknown asm plugin '%s'\n", env_arch);
@@ -680,8 +707,9 @@ int main (int argc, char *argv[]) {
content = r_file_slurp (file, &length);
if (content) {
- if (len && len > 0 && len < length)
+ if (len && len > 0 && len < length) {
length = len;
+ }
content[length] = '\0';
if (skip && length > skip) {
if (bin) {
@@ -710,7 +738,9 @@ int main (int argc, char *argv[]) {
int length;
do {
length = read (0, buf, sizeof (buf) - 1);
- if (length < 1) break;
+ if (length < 1) {
+ break;
+ }
if (len > 0 && len < length) {
length = len;
}
@@ -726,8 +756,9 @@ int main (int argc, char *argv[]) {
}
if (!bin || !dis) {
int buflen = strlen ((const char *)buf);
- if (buf[buflen] == '\n')
+ if (buf[buflen] == '\n') {
buf[buflen - 1] = '\0';
+ }
}
if (dis) {
ret = rasm_disasm ((char *)buf, offset, length, a->bits, ascii, bin, dis - 1);
diff --git a/libr/anal/anal_ex.c b/libr/anal/anal_ex.c
index 6b89398eb4..ba1a7af1cc 100644
--- a/libr/anal/anal_ex.c
+++ b/libr/anal/anal_ex.c
@@ -331,19 +331,25 @@ R_API ut64 r_anal_ex_map_anal_ex_to_anal_bb_type (ut64 ranal2_op_type) {
R_ANAL_OP_TYPE_COND : 0;
ut64 code_op_val = ranal2_op_type & (R_ANAL_EX_CODE_OP | 0x1FF);
- if (conditional)
+ if (conditional) {
bb_type |= R_ANAL_BB_TYPE_COND;
- if (ranal2_op_type & R_ANAL_EX_LOAD_OP)
+ }
+ if (ranal2_op_type & R_ANAL_EX_LOAD_OP) {
bb_type |= R_ANAL_BB_TYPE_LD;
- if (ranal2_op_type & R_ANAL_EX_BIN_OP)
+ }
+ if (ranal2_op_type & R_ANAL_EX_BIN_OP) {
bb_type |= R_ANAL_BB_TYPE_BINOP;
- if (ranal2_op_type & R_ANAL_EX_LOAD_OP)
+ }
+ if (ranal2_op_type & R_ANAL_EX_LOAD_OP) {
bb_type |= R_ANAL_BB_TYPE_LD;
- if (ranal2_op_type & R_ANAL_EX_STORE_OP)
+ }
+ if (ranal2_op_type & R_ANAL_EX_STORE_OP) {
bb_type |= R_ANAL_BB_TYPE_ST;
+ }
/* mark bb with a comparison */
- if (ranal2_op_type & R_ANAL_EX_BINOP_CMP)
+ if (ranal2_op_type & R_ANAL_EX_BINOP_CMP) {
bb_type |= R_ANAL_BB_TYPE_CMP;
+ }
/* change in control flow here */
if (code_op_val & R_ANAL_EX_CODEOP_JMP) {
@@ -362,11 +368,13 @@ R_API ut64 r_anal_ex_map_anal_ex_to_anal_bb_type (ut64 ranal2_op_type) {
bb_type |= R_ANAL_BB_TYPE_TAIL;
}
- if ( ranal2_op_type & R_ANAL_EX_UNK_OP && code_op_val & R_ANAL_EX_CODEOP_JMP)
+ if (ranal2_op_type & R_ANAL_EX_UNK_OP && code_op_val & R_ANAL_EX_CODEOP_JMP) {
bb_type |= R_ANAL_BB_TYPE_FOOT;
+ }
- if ( conditional && code_op_val & R_ANAL_EX_CODEOP_JMP)
+ if (conditional && code_op_val & R_ANAL_EX_CODEOP_JMP) {
bb_type |= R_ANAL_BB_TYPE_BODY;
+ }
return bb_type;
}
@@ -414,9 +422,15 @@ ut64 extract_load_store_op(ut64 ranal2_op_type) {
ut64 extract_unknown_op(ut64 ranal2_op_type) {
- if ( (ranal2_op_type & R_ANAL_EX_CODEOP_JMP) == R_ANAL_EX_CODEOP_JMP ) return R_ANAL_OP_TYPE_UJMP;
- if ( (ranal2_op_type & R_ANAL_EX_CODEOP_CALL) == R_ANAL_EX_CODEOP_CALL) return R_ANAL_OP_TYPE_UCALL;
- if ( (ranal2_op_type & R_ANAL_EX_LDST_OP_PUSH) == R_ANAL_EX_LDST_OP_PUSH) return R_ANAL_OP_TYPE_UPUSH;
+ if ((ranal2_op_type & R_ANAL_EX_CODEOP_JMP) == R_ANAL_EX_CODEOP_JMP) {
+ return R_ANAL_OP_TYPE_UJMP;
+ }
+ if ((ranal2_op_type & R_ANAL_EX_CODEOP_CALL) == R_ANAL_EX_CODEOP_CALL) {
+ return R_ANAL_OP_TYPE_UCALL;
+ }
+ if ((ranal2_op_type & R_ANAL_EX_LDST_OP_PUSH) == R_ANAL_EX_LDST_OP_PUSH) {
+ return R_ANAL_OP_TYPE_UPUSH;
+ }
return R_ANAL_OP_TYPE_UNK;
}
diff --git a/libr/anal/cond.c b/libr/anal/cond.c
index 214f175920..06c9fd4083 100644
--- a/libr/anal/cond.c
+++ b/libr/anal/cond.c
@@ -29,14 +29,18 @@ R_API RAnalCond *r_anal_cond_new() {
}
R_API void r_anal_cond_fini (RAnalCond *c) {
- if (!c) return;
+ if (!c) {
+ return;
+ }
r_anal_value_free (c->arg[0]);
r_anal_value_free (c->arg[1]);
c->arg[0] = c->arg[1] = NULL;
}
R_API void r_anal_cond_free (RAnalCond *c) {
- if (!c) return;
+ if (!c) {
+ return;
+ }
r_anal_cond_fini (c);
free (c);
}
@@ -44,7 +48,9 @@ R_API void r_anal_cond_free (RAnalCond *c) {
// XXX?
R_API RAnalCond *r_anal_cond_clone(RAnalCond *cond) {
RAnalCond *c = R_NEW (RAnalCond);
- if (!c) return NULL;
+ if (!c) {
+ return NULL;
+ }
memcpy (c, cond, sizeof (RAnalCond));
return c;
}
@@ -53,10 +59,11 @@ static inline const char *condstring(RAnalCond *cond) {
const char *condstr_single[] = { "!", "", "0<", "0<=", "0>", "0>=" };
const char *condstr[] = { "==", "!=", ">=", ">", "<=", "<" };
if (cond) {
- if (cond->arg[1])
+ if (cond->arg[1]) {
return condstr[cond->type % 6];
- else
+ } else {
return condstr_single[cond->type % 6];
+ }
}
return "";
}
@@ -91,21 +98,24 @@ R_API int r_anal_cond_eval(RAnal *anal, RAnalCond *cond) {
R_API char *r_anal_cond_to_string(RAnalCond *cond) {
char *val0, *val1, *out = NULL;
const char *cnd;
- if (!cond)
+ if (!cond) {
return NULL;
+ }
cnd = condstring (cond);
val0 = r_anal_value_to_string (cond->arg[0]);
val1 = r_anal_value_to_string (cond->arg[1]);
if (val0) {
if (R_ANAL_COND_SINGLE (cond)) {
int val0len = strlen (val0) + 10;
- if ((out = malloc (val0len)))
+ if ((out = malloc (val0len))) {
snprintf (out, val0len, "%s%s", cnd, val0);
+ }
} else {
if (val1) {
int val0len = strlen (val0) + strlen (val1) + 10;
- if ((out = malloc (val0len)))
+ if ((out = malloc (val0len))) {
snprintf (out, val0len, "%s %s %s", val0, cnd, val1);
+ }
}
}
}
@@ -116,8 +126,9 @@ R_API char *r_anal_cond_to_string(RAnalCond *cond) {
R_API RAnalCond *r_anal_cond_new_from_op(RAnalOp *op) {
RAnalCond *cond;
- if (!(cond = r_anal_cond_new ()))
+ if (!(cond = r_anal_cond_new ())) {
return NULL;
+ }
//v->reg[0] = op->src[0];
//v->reg[1] = op->src[1];
cond->arg[0] = op->src[0];
diff --git a/libr/anal/cycles.c b/libr/anal/cycles.c
index 2e7e8eef97..1dbe08e3f4 100644
--- a/libr/anal/cycles.c
+++ b/libr/anal/cycles.c
@@ -16,7 +16,9 @@ R_API RAnalCycleFrame *r_anal_cycle_frame_new() {
}
R_API void r_anal_cycle_frame_free(RAnalCycleFrame *cf) {
- if (!cf) return;
+ if (!cf) {
+ return;
+ }
r_list_free (cf->hooks);
free (cf);
}
diff --git a/libr/anal/data.c b/libr/anal/data.c
index 803967a2f0..5af551ac06 100644
--- a/libr/anal/data.c
+++ b/libr/anal/data.c
@@ -5,7 +5,9 @@
#define MINLEN 1
static int is_string(const ut8 *buf, int size, int *len) {
int i;
- if (size < 1) return 0;
+ if (size < 1) {
+ return 0;
+ }
if (size > 3 && buf[0] && !buf[1] && buf[2] && !buf[3]) {
*len = 1; // XXX: TODO: Measure wide string length
return 2; // is wide
@@ -42,8 +44,12 @@ static int is_null(const ut8 *buf, int size) {
}
static int is_invalid(const ut8 *buf, int size) {
- if (size < 1) return 1;
- if (size > 8) size = 8;
+ if (size < 1) {
+ return 1;
+ }
+ if (size > 8) {
+ size = 8;
+ }
return (!memcmp (buf, "\xff\xff\xff\xff\xff\xff\xff\xff", size))? 1: 0;
}
@@ -52,10 +58,13 @@ static ut64 is_pointer(RAnal *anal, const ut8 *buf, int size) {
ut64 n;
ut8 buf2[32];
RIOBind *iob = &anal->iob;
- if (size > sizeof (buf2))
+ if (size > sizeof (buf2)) {
size = sizeof (buf2);
+ }
n = r_mem_get_num (buf, size);
- if (!n) return 1; // null pointer
+ if (!n) {
+ return 1; // null pointer
+ }
#if USE_IS_VALID_OFFSET
int r = iob->is_valid_offset (iob->io, n, 0);
return r? n: 0LL;
@@ -94,7 +103,9 @@ R_API char *r_anal_data_to_string(RAnalData *d, RConsPrintablePalette *pal) {
ut32 n32;
char *line;
- if (!d) return NULL;
+ if (!d) {
+ return NULL;
+ }
line = malloc (mallocsz);
if (!line) {
@@ -203,7 +214,9 @@ R_API char *r_anal_data_to_string(RAnalData *d, RConsPrintablePalette *pal) {
R_API RAnalData *r_anal_data_new_string(ut64 addr, const char *p, int len, int type) {
RAnalData *ad = R_NEW0 (RAnalData);
- if (!ad) return NULL;
+ if (!ad) {
+ return NULL;
+ }
ad->str = NULL;
ad->addr = addr;
ad->type = type;
@@ -330,7 +343,9 @@ R_API RAnalData *r_anal_data(RAnal *anal, ut64 addr, const ut8 *buf, int size, i
}
if (size >= word) {
n = is_number (buf, word);
- if (n) return r_anal_data_new (addr, R_ANAL_DATA_TYPE_NUMBER, n, buf, word);
+ if (n) {
+ return r_anal_data_new (addr, R_ANAL_DATA_TYPE_NUMBER, n, buf, word);
+ }
}
return r_anal_data_new (addr, R_ANAL_DATA_TYPE_UNKNOWN, dst, buf, R_MIN (word, size));
}
@@ -344,8 +359,9 @@ R_API const char *r_anal_data_kind(RAnal *a, ut64 addr, const ut8 *buf, int len)
RAnalData *data;
int word = a->bits / 8;
for (i = j = 0; i < len; j++) {
- if (str && !buf[i])
+ if (str && !buf[i]) {
str++;
+ }
data = r_anal_data (a, addr + i, buf + i, len - i, 0);
if (!data) {
i += word;
@@ -357,7 +373,9 @@ R_API const char *r_anal_data_kind(RAnal *a, ut64 addr, const ut8 *buf, int len)
i += word;
break;
case R_ANAL_DATA_TYPE_NUMBER:
- if (data->ptr > 1000) num++;
+ if (data->ptr > 1000) {
+ num++;
+ }
i += word;
break;
case R_ANAL_DATA_TYPE_UNKNOWN:
@@ -367,7 +385,9 @@ R_API const char *r_anal_data_kind(RAnal *a, ut64 addr, const ut8 *buf, int len)
case R_ANAL_DATA_TYPE_STRING:
if (data->len > 0) {
i += data->len;
- } else i += word;
+ } else {
+ i += word;
+ }
str++;
break;
default:
@@ -375,10 +395,20 @@ R_API const char *r_anal_data_kind(RAnal *a, ut64 addr, const ut8 *buf, int len)
}
r_anal_data_free (data);
}
- if (j < 1) return "unknown";
- if ((inv * 100 / j) > 60) return "invalid";
- if ((unk * 100 / j) > 60) return "code";
- if ((num * 100 / j) > 60) return "code";
- if ((str * 100 / j) > 40) return "text";
+ if (j < 1) {
+ return "unknown";
+ }
+ if ((inv * 100 / j) > 60) {
+ return "invalid";
+ }
+ if ((unk * 100 / j) > 60) {
+ return "code";
+ }
+ if ((num * 100 / j) > 60) {
+ return "code";
+ }
+ if ((str * 100 / j) > 40) {
+ return "text";
+ }
return "data";
}
diff --git a/libr/anal/diff.c b/libr/anal/diff.c
index b40060b904..eea90e2da0 100644
--- a/libr/anal/diff.c
+++ b/libr/anal/diff.c
@@ -98,8 +98,9 @@ R_API int r_anal_diff_fingerprint_fcn(RAnal *anal, RAnalFunction *fcn) {
r_list_foreach (fcn->bbs, iter, bb) {
len += bb->size;
fcn->fingerprint = realloc (fcn->fingerprint, len + 1);
- if (!fcn->fingerprint)
+ if (!fcn->fingerprint) {
return 0;
+ }
memcpy (fcn->fingerprint+len-bb->size, bb->fingerprint, bb->size);
}
return len;
diff --git a/libr/anal/esil.c b/libr/anal/esil.c
index ed6fab016c..c8c0904d68 100644
--- a/libr/anal/esil.c
+++ b/libr/anal/esil.c
@@ -30,7 +30,9 @@ static inline ut64 genmask(int bits) {
ut64 m = UT64_MAX;
if (bits < 64) {
m = (ut64)(((ut64)(2) << bits) - 1);
- if (!m) m = UT64_MAX;
+ if (!m) {
+ m = UT64_MAX;
+ }
}
return m;
}
@@ -169,12 +171,14 @@ R_API int r_anal_esil_fire_interrupt(RAnalEsil *esil, int interrupt) {
if (esil->anal) {
RAnalPlugin *ap = esil->anal->cur;
if (ap && ap->esil_intr) {
- if (ap->esil_intr (esil, interrupt))
+ if (ap->esil_intr (esil, interrupt)) {
return true;
+ }
}
}
- if (!esil->interrupts)
+ if (!esil->interrupts) {
return false;
+ }
i = sdb_itoa ((ut64)interrupt, t, 16);
if (!sdb_num_exists (esil->interrupts, i)) {
//eprintf ("0x%08"PFMT64x" Invalid interrupt/syscall 0x%08x\n", esil->address, interrupt);
@@ -409,8 +413,12 @@ R_API int r_anal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int
static int internal_esil_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, int *size) {
RRegItem *reg = r_reg_get (esil->anal->reg, regname, -1);
if (reg) {
- if (size) *size = reg->size;
- if (num) *num = r_reg_get_value (esil->anal->reg, reg);
+ if (size) {
+ *size = reg->size;
+ }
+ if (num) {
+ *num = r_reg_get_value (esil->anal->reg, reg);
+ }
return true;
}
return false;
@@ -530,8 +538,9 @@ R_API int r_anal_esil_get_parm_type(RAnalEsil *esil, const char *str) {
}
return R_ANAL_ESIL_PARM_NUM;
not_a_number:
- if (r_reg_get (esil->anal->reg, str, -1))
+ if (r_reg_get (esil->anal->reg, str, -1)) {
return R_ANAL_ESIL_PARM_REG;
+ }
return R_ANAL_ESIL_PARM_INVALID;
}
@@ -657,11 +666,15 @@ R_API int r_anal_esil_get_parm_size(RAnalEsil *esil, const char *str, ut64 *num,
switch (parm_type) {
case R_ANAL_ESIL_PARM_INTERNAL:
// *num = esil_internal_read (esil, str, num);
- if (size) *size = esil->anal->bits;
+ if (size) {
+ *size = esil->anal->bits;
+ }
return esil_internal_read (esil, str, num);
case R_ANAL_ESIL_PARM_NUM:
*num = r_num_get (NULL, str);
- if (size) *size = esil->anal->bits;
+ if (size) {
+ *size = esil->anal->bits;
+ }
return true;
case R_ANAL_ESIL_PARM_REG:
if (!r_anal_esil_reg_read (esil, str, num, size)) {
@@ -716,7 +729,9 @@ R_API int r_anal_esil_reg_read(RAnalEsil *esil, const char *regname, ut64 *num,
}
return esil_internal_read (esil, regname, num);
}
- if (!num) num = &localnum;
+ if (!num) {
+ num = &localnum;
+ }
*num = 0LL;
if (size) {
*size = esil->anal->bits;
@@ -1404,8 +1419,9 @@ static int esil_break(RAnalEsil *esil) {
static int esil_clear(RAnalEsil *esil) {
char *r;
- while ((r = r_anal_esil_pop (esil)))
+ while ((r = r_anal_esil_pop (esil))) {
free (r);
+ }
return 1;
}
@@ -2022,7 +2038,9 @@ static int esil_mem_oreq_n(RAnalEsil *esil, int bits) {
r_anal_esil_pushnum (esil, d); //push the new dst-value
r_anal_esil_push (esil, dst); //push the dst-addr
ret &= (!!esil_poke_n (esil, bits)); //write
- } else ret = 0;
+ } else {
+ ret = 0;
+ }
}
if (!ret) {
ERR ("esil_mem_oreq_n: invalid parameters");
@@ -2066,7 +2084,9 @@ static int esil_mem_xoreq_n(RAnalEsil *esil, int bits) {
r_anal_esil_pushnum (esil, d);
r_anal_esil_push (esil, dst);
ret &= (!!esil_poke_n (esil, bits));
- } else ret = 0;
+ } else {
+ ret = 0;
+ }
}
if (!ret) {
ERR ("esil_mem_xoreq_n: invalid parameters");
@@ -2110,7 +2130,9 @@ static int esil_mem_andeq_n(RAnalEsil *esil, int bits) {
r_anal_esil_pushnum (esil, d);
r_anal_esil_push (esil, dst);
ret &= (!!esil_poke_n (esil, bits));
- } else ret = 0;
+ } else {
+ ret = 0;
+ }
}
if (!ret) {
ERR ("esil_mem_andeq_n: invalid parameters");
@@ -2154,10 +2176,13 @@ static int esil_mem_addeq_n(RAnalEsil *esil, int bits) {
r_anal_esil_pushnum (esil, d);
r_anal_esil_push (esil, dst);
ret &= (!!esil_poke_n (esil, bits));
- } else ret = 0;
+ } else {
+ ret = 0;
+ }
}
- if (!ret)
+ if (!ret) {
ERR ("esil_mem_addeq_n: invalid parameters");
+ }
free (dst);
free (src0);
free (src1);
@@ -2197,10 +2222,13 @@ static int esil_mem_subeq_n(RAnalEsil *esil, int bits) {
r_anal_esil_pushnum (esil, d);
r_anal_esil_push (esil, dst);
ret &= (!!esil_poke_n (esil, bits));
- } else ret = 0;
+ } else {
+ ret = 0;
+ }
}
- if (!ret)
+ if (!ret) {
ERR ("esil_mem_subeq_n: invalid parameters");
+ }
free (dst);
free (src0);
free (src1);
@@ -2298,11 +2326,14 @@ static int esil_mem_diveq_n(RAnalEsil *esil, int bits) {
r_anal_esil_pushnum (esil, d);
r_anal_esil_push (esil, dst);
ret &= (!!esil_poke_n (esil, bits));
- } else ret = 0;
+ } else {
+ ret = 0;
+ }
}
}
- if (!ret)
+ if (!ret) {
ERR ("esil_mem_diveq_n: invalid parameters");
+ }
free (dst);
free (src0);
free (src1);
@@ -2342,10 +2373,13 @@ static int esil_mem_muleq_n(RAnalEsil *esil, int bits, ut64 bitmask) {
r_anal_esil_pushnum (esil, d);
r_anal_esil_push (esil, dst);
ret &= (!!esil_poke_n (esil, bits));
- } else ret = 0;
+ } else {
+ ret = 0;
+ }
}
- if (!ret)
+ if (!ret) {
ERR ("esil_mem_muleq_n: invalid parameters");
+ }
free (dst);
free (src0);
free (src1);
@@ -2391,10 +2425,13 @@ static int esil_mem_inceq_n(RAnalEsil *esil, int bits) {
r_anal_esil_pushnum (esil, s);
r_anal_esil_push (esil, off);
ret &= (!!esil_poke_n (esil, bits));
- } else ret = 0;
+ } else {
+ ret = 0;
+ }
}
- if (!ret)
+ if (!ret) {
ERR ("esil_mem_inceq_n: invalid parameters");
+ }
free (src);
free (off);
return ret;
@@ -2432,10 +2469,13 @@ static int esil_mem_deceq_n(RAnalEsil *esil, int bits) {
r_anal_esil_pushnum (esil, s);
r_anal_esil_push (esil, off);
ret &= (!!esil_poke_n (esil, bits));
- } else ret = 0;
+ } else {
+ ret = 0;
+ }
}
- if (!ret)
+ if (!ret) {
ERR ("esil_mem_deceq_n: invalid parameters");
+ }
free (src);
free (off);
return ret;
@@ -2528,10 +2568,13 @@ static int esil_mem_lsreq_n(RAnalEsil *esil, int bits) {
r_anal_esil_pushnum (esil, d);
r_anal_esil_push (esil, dst);
ret &= (!!esil_poke_n (esil, bits));
- } else ret = 0;
+ } else {
+ ret = 0;
+ }
}
- if (!ret)
+ if (!ret) {
ERR ("esil_mem_lsreq_n: invalid parameters");
+ }
free (dst);
free (src0);
free (src1);
@@ -2558,10 +2601,12 @@ static int esil_mem_lsreq(RAnalEsil *esil) {
static int esil_num(RAnalEsil *esil) {
char *dup_me;
ut64 dup;
- if (!esil)
+ if (!esil) {
return false;
- if (!(dup_me = r_anal_esil_pop (esil)))
+ }
+ if (!(dup_me = r_anal_esil_pop (esil))) {
return false;
+ }
if (!r_anal_esil_get_parm (esil, dup_me, &dup)) {
free (dup_me);
return false;
@@ -2807,7 +2852,9 @@ static int runword(RAnalEsil *esil, const char *word) {
r_anal_esil_parse (esil, esil->Reil->if_buf);
return 1;
}
- if (iscommand (esil, word, &op)) esil->Reil->cmd_count++;
+ if (iscommand (esil, word, &op)) {
+ esil->Reil->cmd_count++;
+ }
return 1;
}
@@ -2852,8 +2899,9 @@ static const char *gotoWord(const char *str, int n) {
const char *ostr = str;
int count = 0;
while (*str) {
- if (count == n)
+ if (count == n) {
return ostr;
+ }
str++;
if (*str == ',') {
ostr = str + 1;
@@ -3018,7 +3066,9 @@ R_API int r_anal_esil_condition(RAnalEsil *esil, const char *str) {
if (!esil) {
return false;
}
- while (*str == ' ') str++; // use proper string chop?
+ while (*str == ' ') {
+ str++; // use proper string chop?
+ }
(void) r_anal_esil_parse (esil, str);
popped = r_anal_esil_pop (esil);
if (popped) {
@@ -3171,7 +3221,9 @@ static void r_anal_esil_setup_ops(RAnalEsil *esil) {
/* register callbacks using this anal module. */
R_API int r_anal_esil_setup(RAnalEsil *esil, RAnal *anal, int romem, int stats, int nonull) {
- if (!esil) return false;
+ if (!esil) {
+ return false;
+ }
//esil->debug = 0;
esil->anal = anal;
esil->parse_goto_count = anal->esil_goto_limit;
diff --git a/libr/anal/esil2reil.c b/libr/anal/esil2reil.c
index 83128f5e55..6efa58eca3 100644
--- a/libr/anal/esil2reil.c
+++ b/libr/anal/esil2reil.c
@@ -66,7 +66,9 @@ RAnalReilArg *reil_pop_arg(RAnalEsil *esil) {
continue;
}
// Strip all spaces
- if (buf[i] == ' ') continue;
+ if (buf[i] == ' ') {
+ continue;
+ }
tmp_buf[j] = buf[i];
j++;
}
@@ -99,7 +101,9 @@ void get_next_temp_reg(RAnalEsil *esil, char *buf) {
}
void reil_make_arg(RAnalEsil *esil, RAnalReilArg *arg, char *name) {
- if (!arg) return;
+ if (!arg) {
+ return;
+ }
RAnalReilArgType type;
type = reil_get_arg_type(esil, name);
arg->size = 0;
@@ -110,7 +114,9 @@ void reil_make_arg(RAnalEsil *esil, RAnalReilArg *arg, char *name) {
// Free ins and all its arguments
void reil_free_inst(RAnalReilInst *ins) {
- if (!ins) return;
+ if (!ins) {
+ return;
+ }
if (ins->arg[0]) R_FREE(ins->arg[0]);
if (ins->arg[1]) R_FREE(ins->arg[1]);
if (ins->arg[2]) R_FREE(ins->arg[2]);
@@ -166,18 +172,22 @@ void reil_cast_size(RAnalEsil *esil, RAnalReilArg *src, RAnalReilArg *dst) {
snprintf (tmp_buf, REGBUFSZ-1, "0:%d", dst->size);
r_anal_esil_push (esil, tmp_buf);
ins = R_NEW0 (RAnalReilInst);
- if (!ins) return;
+ if (!ins) {
+ return;
+ }
ins->opcode = REIL_OR;
ins->arg[0] = src;
ins->arg[1] = reil_pop_arg (esil);
ins->arg[2] = R_NEW0(RAnalReilArg);
get_next_temp_reg (esil, tmp_buf);
reil_make_arg (esil, ins->arg[2], tmp_buf);
- if (ins->arg[2])
+ if (ins->arg[2]) {
ins->arg[2]->size = dst->size;
+ }
reil_print_inst (esil, ins);
- if (ins->arg[2])
+ if (ins->arg[2]) {
reil_push_arg (esil, ins->arg[2]);
+ }
reil_free_inst (ins);
}
@@ -189,7 +199,9 @@ static int reil_eq(RAnalEsil *esil) {
RAnalReilArg *dst, *src;
dst = reil_pop_arg (esil);
- if (!dst) return false;
+ if (!dst) {
+ return false;
+ }
src = reil_pop_arg (esil);
if (!src) {
R_FREE (dst);
@@ -205,7 +217,9 @@ static int reil_eq(RAnalEsil *esil) {
} else if (src_type == ARG_REG) {
// No direct register to register transfer.
ins = R_NEW0 (RAnalReilInst);
- if (!ins) return false;
+ if (!ins) {
+ return false;
+ }
ins->opcode = REIL_STR;
ins->arg[0] = src;
ins->arg[1] = R_NEW0 (RAnalReilArg);
@@ -307,7 +321,9 @@ static int reil_binop(RAnalEsil *esil, RAnalReilOpcode opcode) {
RAnalReilArg *op2, *op1;
op2 = reil_pop_arg(esil);
- if (!op2) return false;
+ if (!op2) {
+ return false;
+ }
op1 = reil_pop_arg(esil);
if (!op1) {
R_FREE (op2);
@@ -336,11 +352,13 @@ static int reil_binop(RAnalEsil *esil, RAnalReilOpcode opcode) {
reil_make_arg(esil, ins->arg[2], tmp_buf);
// Choose the larger of the two sizes as the size of dst
dst_size = ins->arg[0]->size;
- if (dst_size < ins->arg[1]->size)
+ if (dst_size < ins->arg[1]->size) {
dst_size = ins->arg[1]->size;
+ }
// REIL_LT has a dst_size of 1.
- if (opcode == REIL_LT)
+ if (opcode == REIL_LT) {
dst_size = 1;
+ }
ins->arg[2]->size = dst_size;
reil_print_inst(esil, ins);
reil_push_arg(esil, ins->arg[2]);
@@ -352,7 +370,9 @@ static int reil_binop(RAnalEsil *esil, RAnalReilOpcode opcode) {
static int reil_bineqop(RAnalEsil *esil, RAnalReilOpcode opcode) {
int ret = 1;
RAnalReilArg *op = reil_pop_arg(esil);
- if (!op) return false;
+ if (!op) {
+ return false;
+ }
reil_push_arg(esil, op);
ret &= reil_binop(esil, opcode);
@@ -388,7 +408,9 @@ static int reil_cmp(RAnalEsil *esil) {
RAnalReilArg *op2, *op1;
op2 = reil_pop_arg (esil);
- if (!op2) return false;
+ if (!op2) {
+ return false;
+ }
op1 = reil_pop_arg (esil);
if (!op1) {
R_FREE (op2);
@@ -432,7 +454,9 @@ static int reil_smaller_equal(RAnalEsil *esil) {
RAnalReilArg *op2, *op1;
op2 = reil_pop_arg(esil);
- if (!op2) return false;
+ if (!op2) {
+ return false;
+ }
op1 = reil_pop_arg(esil);
if (!op1) {
R_FREE (op2);
@@ -474,7 +498,9 @@ static int reil_larger_equal(RAnalEsil *esil) {
RAnalReilArg *op2, *op1;
op2 = reil_pop_arg(esil);
- if (!op2) return false;
+ if (!op2) {
+ return false;
+ }
op1 = reil_pop_arg(esil);
if (!op1) {
R_FREE (op2);
@@ -516,7 +542,9 @@ static int reil_deceq(RAnalEsil *esil) {
static int reil_inc(RAnalEsil *esil) {
RAnalReilArg *op = reil_pop_arg(esil);
- if (!op) return false;
+ if (!op) {
+ return false;
+ }
r_anal_esil_pushnum(esil, 1);
reil_push_arg(esil, op);
@@ -565,8 +593,9 @@ static int reil_neg(RAnalEsil *esil) {
}
get_next_temp_reg (esil, tmp_buf);
reil_make_arg(esil, ins->arg[2], tmp_buf);
- if (ins->arg[0]->size < ins->arg[1]->size)
+ if (ins->arg[0]->size < ins->arg[1]->size) {
ins->arg[1]->size = ins->arg[0]->size;
+ }
ins->arg[2]->size = 1;
reil_print_inst (esil, ins);
@@ -577,7 +606,9 @@ static int reil_neg(RAnalEsil *esil) {
static int reil_negeq(RAnalEsil *esil) {
RAnalReilArg *op = reil_pop_arg(esil);
- if (!op) return false;
+ if (!op) {
+ return false;
+ }
reil_push_arg (esil, op);
reil_neg (esil);
reil_push_arg (esil, op);
@@ -590,7 +621,9 @@ static int reil_not(RAnalEsil *esil) {
char tmp_buf[REGBUFSZ];
RAnalReilInst *ins;
RAnalReilArg *op = reil_pop_arg (esil);
- if (!op) return false;
+ if (!op) {
+ return false;
+ }
ins = R_NEW0 (RAnalReilInst);
if (!ins) {
@@ -624,7 +657,9 @@ static int reil_if(RAnalEsil *esil) {
RAnalReilArg *op2, *op1;
op2 = reil_pop_arg (esil);
- if (!op2) return false;
+ if (!op2) {
+ return false;
+ }
op1 = reil_pop_arg (esil);
if (!op1) {
R_FREE (op2);
@@ -657,7 +692,9 @@ static int reil_peek(RAnalEsil *esil) {
RAnalReilInst *ins;
char tmp_buf[REGBUFSZ];
RAnalReilArg *op1 = reil_pop_arg(esil);
- if (!op1) return false;
+ if (!op1) {
+ return false;
+ }
ins = R_NEW0 (RAnalReilInst);
if (!ins) {
@@ -690,7 +727,9 @@ static int reil_peek(RAnalEsil *esil) {
static int reil_peekn(RAnalEsil *esil, ut8 n) {
RAnalReilArg *op2;
RAnalReilArg *op1 = reil_pop_arg (esil);
- if (!op1) return false;
+ if (!op1) {
+ return false;
+ }
reil_push_arg (esil, op1);
reil_peek (esil);
@@ -702,7 +741,9 @@ static int reil_peekn(RAnalEsil *esil, ut8 n) {
R_FREE (op1);
op1 = reil_pop_arg (esil);
- if (!op1) return false;
+ if (!op1) {
+ return false;
+ }
op2 = R_NEW0 (RAnalReilArg);
if (!op2) {
@@ -731,7 +772,9 @@ static int reil_poken(RAnalEsil *esil, ut8 n) {
RAnalReilArg *op2, *op1;
op2 = reil_pop_arg (esil);
- if (!op2) return false;
+ if (!op2) {
+ return false;
+ }
op1 = reil_pop_arg (esil);
if (!op1) {
R_FREE (op2);
@@ -784,7 +827,9 @@ static int reil_poken(RAnalEsil *esil, ut8 n) {
}
ins = R_NEW0 (RAnalReilInst);
- if (!ins) return false;
+ if (!ins) {
+ return false;
+ }
ins->opcode = REIL_STM;
ins->arg[2] = reil_pop_arg (esil);
ins->arg[0] = reil_pop_arg (esil);
@@ -814,7 +859,9 @@ static int reil_mem_bineq_n(RAnalEsil *esil, RAnalReilOpcode opcode, ut8 size) {
RAnalReilArg *op2, *op1;
op2 = reil_pop_arg (esil);
- if (!op2) return false;
+ if (!op2) {
+ return false;
+ }
op1 = reil_pop_arg (esil);
if (!op1) {
R_FREE (op2);
@@ -872,7 +919,9 @@ static int reil_mem_muleq8(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL
static int reil_mem_inceq_n(RAnalEsil *esil, ut8 size) {
int ret = 1;
RAnalReilArg *op1 = reil_pop_arg(esil);
- if (!op1) return false;
+ if (!op1) {
+ return false;
+ }
r_anal_esil_pushnum(esil, 1);
reil_push_arg(esil, op1);
@@ -893,7 +942,9 @@ static int reil_mem_inceq8(RAnalEsil *esil) { return reil_mem_inceq_n(esil, 8);
static int reil_mem_deceq_n(RAnalEsil *esil, ut8 size) {
int ret = 1;
RAnalReilArg *op1 = reil_pop_arg(esil);
- if (!op1) return false;
+ if (!op1) {
+ return false;
+ }
r_anal_esil_pushnum(esil, 1);
reil_push_arg(esil, op1);
@@ -976,7 +1027,9 @@ void reil_generate_partity_flag(RAnalEsil *esil) {
r_anal_esil_pushnum(esil, 0xff);
reil_and(esil);
op = reil_pop_arg(esil);
- if (!op) return;
+ if (!op) {
+ return;
+ }
r_anal_esil_pushnum(esil, 7);
reil_push_arg(esil, op);
@@ -1029,7 +1082,9 @@ void reil_generate_signature(RAnalEsil *esil) {
reil_and(esil);
op = reil_pop_arg(esil);
- if (!op) return;
+ if (!op) {
+ return;
+ }
r_anal_esil_pushnum(esil, esil->Reil->lastsz - 1);
reil_push_arg(esil, op);
@@ -1039,8 +1094,9 @@ void reil_generate_signature(RAnalEsil *esil) {
}
void reil_generate_overflow_flag(RAnalEsil *esil) {
- if (esil->Reil->lastsz < 2)
- r_anal_esil_pushnum(esil, 0);
+ if (esil->Reil->lastsz < 2) {
+ r_anal_esil_pushnum (esil, 0);
+ }
reil_generate_borrow_flag(esil, esil->Reil->lastsz);
reil_generate_carry_flag(esil, esil->Reil->lastsz - 2);
diff --git a/libr/anal/esil_stats.c b/libr/anal/esil_stats.c
index 00e1662aa8..3b8bb34c95 100644
--- a/libr/anal/esil_stats.c
+++ b/libr/anal/esil_stats.c
@@ -48,9 +48,11 @@ R_API void r_anal_esil_mem_ro(RAnalEsil *esil, int mem_readonly) {
R_API void r_anal_esil_stats(RAnalEsil *esil, int enable) {
if (enable) {
- if (esil->stats)
+ if (esil->stats) {
sdb_reset (esil->stats);
- else esil->stats = sdb_new0();
+ } else {
+ esil->stats = sdb_new0 ();
+ }
// reset sdb->stats
esil->cb.hook_reg_read = hook_reg_read;
esil->cb.hook_mem_read = hook_mem_read;
diff --git a/libr/anal/labels.c b/libr/anal/labels.c
index 8c70695ff7..2e2e5e18f5 100644
--- a/libr/anal/labels.c
+++ b/libr/anal/labels.c
@@ -40,8 +40,9 @@ R_API int r_anal_fcn_label_set (RAnal *anal, RAnalFunction *fcn, const char *nam
}
R_API int r_anal_fcn_label_del (RAnal *anal, RAnalFunction *fcn, const char *name, ut64 addr) {
- if (!anal || !fcn || !name)
+ if (!anal || !fcn || !name) {
return false;
+ }
sdb_array_remove (DB, LABELS, ADDRLABEL (addr, name), 0);
sdb_unset (DB, LABEL (name), 0);
sdb_unset (DB, ADDR (addr), 0);
@@ -61,8 +62,9 @@ R_API int r_anal_fcn_labels(RAnal *anal, RAnalFunction *fcn, int rad) {
char *name;
} loc;
token = strchr (cur, '/');
- if (!token)
+ if (!token) {
break;
+ }
*token = ',';
sdb_fmt_tobin (cur, "qz", &loc);
switch (rad) {
diff --git a/libr/anal/meta.c b/libr/anal/meta.c
index be732ff0c8..defa731f27 100644
--- a/libr/anal/meta.c
+++ b/libr/anal/meta.c
@@ -226,7 +226,9 @@ R_API int r_meta_del(RAnal *a, int type, ut64 addr, ut64 size) {
"meta.%c.0x%"PFMT64x,
type, sdb_atoi (s));
sdb_unset (DB, key, 0);
- if (!next) break;
+ if (!next) {
+ break;
+ }
}
free (dtr);
}
@@ -298,7 +300,9 @@ R_API void r_meta_item_free(void *_item) {
R_API RAnalMetaItem *r_meta_item_new(int type) {
RAnalMetaItem *mi = R_NEW0 (RAnalMetaItem);
- if (mi) mi->type = type;
+ if (mi) {
+ mi->type = type;
+ }
return mi;
}
@@ -558,7 +562,9 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, int rad, bool show_full) {
{
const char *type = r_meta_type_to_string (d->type);
char *s = sdb_encode ((const ut8*)pstr, -1);
- if (!s) s = strdup (pstr);
+ if (!s) {
+ s = strdup (pstr);
+ }
if (rad) {
if (!strcmp (type, "CCu")) {
a->cb_printf ("%s base64:%s @ 0x%08"PFMT64x"\n",
@@ -668,8 +674,9 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, int rad, bool show_full) {
}
break;
}
- if (str)
+ if (str) {
free (str);
+ }
}
}
@@ -764,8 +771,9 @@ static int meta_unset_cb(void *user, const char *k, const char *v) {
RAnalMetaUserItem *ui = user;
RAnal *a = ui->anal;
RAnalMetaItem it = {0};
- if (!strstr(k, ".0x"))
+ if (!strstr (k, ".0x")) {
return 1;
+ }
meta_deserialize (&it, k, v);
if (it.space != -1) {
it.space = -1;
@@ -789,8 +797,9 @@ static int meta_count_cb(void *user, const char *k, const char *v) {
RAnalMetaUserItem *ui = user;
myMetaUser *mu = ui->user;
RAnalMetaItem it = {0};
- if (!strstr(k, ".0x"))
+ if (!strstr (k, ".0x")) {
return 1;
+ }
meta_deserialize (&it, k, v);
if (mu) {
if (it.space == mu->ctx) {
diff --git a/libr/anal/op.c b/libr/anal/op.c
index c9500f322c..b8b94f738d 100644
--- a/libr/anal/op.c
+++ b/libr/anal/op.c
@@ -238,8 +238,10 @@ R_API int r_anal_op_execute(RAnal *anal, RAnalOp *op) {
if (div == 0) {
eprintf ("r_anal_op_execute: division by zero\n");
eprintf ("TODO: throw RAnalException\n");
- } else r_anal_value_set_ut64 (anal, op->dst,
- r_anal_value_to_ut64 (anal, op->src[0])/div);
+ } else {
+ r_anal_value_set_ut64 (anal, op->dst,
+ r_anal_value_to_ut64 (anal, op->src[0]) / div);
+ }
}
break;
case R_ANAL_OP_TYPE_MUL:
@@ -392,9 +394,15 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) {
char *r0 = r_anal_value_to_string (op->dst);
char *a0 = r_anal_value_to_string (op->src[0]);
char *a1 = r_anal_value_to_string (op->src[1]);
- if (!r0) r0 = strdup ("?");
- if (!a0) a0 = strdup ("?");
- if (!a1) a1 = strdup ("?");
+ if (!r0) {
+ r0 = strdup ("?");
+ }
+ if (!a0) {
+ a0 = strdup ("?");
+ }
+ if (!a1) {
+ a1 = strdup ("?");
+ }
switch (op->type) {
case R_ANAL_OP_TYPE_MOV:
@@ -443,12 +451,18 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) {
f = r_anal_get_fcn_in (anal, op->jump, R_ANAL_FCN_TYPE_NULL);
if ((bb = r_anal_bb_from_offset (anal, op->addr))) {
cstr = r_anal_cond_to_string (bb->cond);
- if (f) snprintf (ret, sizeof (ret), "if (%s) %s()", cstr, f->name);
- else snprintf (ret, sizeof (ret), "if (%s) 0x%"PFMT64x"()", cstr, op->jump);
+ if (f) {
+ snprintf (ret, sizeof (ret), "if (%s) %s()", cstr, f->name);
+ } else {
+ snprintf (ret, sizeof (ret), "if (%s) 0x%" PFMT64x "()", cstr, op->jump);
+ }
free (cstr);
} else {
- if (f) snprintf (ret, sizeof (ret), "if (unk) %s()", f->name);
- else snprintf (ret, sizeof (ret), "if (unk) 0x%"PFMT64x"()", op->jump);
+ if (f) {
+ snprintf (ret, sizeof (ret), "if (unk) %s()", f->name);
+ } else {
+ snprintf (ret, sizeof (ret), "if (unk) 0x%" PFMT64x "()", op->jump);
+ }
}
break;
case R_ANAL_OP_TYPE_ADD:
@@ -475,22 +489,30 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) {
case R_ANAL_OP_TYPE_DIV:
if (!a1 || !strcmp (a0, a1)) {
snprintf (ret, sizeof (ret), "%s /= %s", r0, a0);
- } else snprintf (ret, sizeof (ret), "%s = %s / %s", r0, a0, a1);
+ } else {
+ snprintf (ret, sizeof (ret), "%s = %s / %s", r0, a0, a1);
+ }
break;
case R_ANAL_OP_TYPE_AND:
if (!a1 || !strcmp (a0, a1)) {
snprintf (ret, sizeof (ret), "%s &= %s", r0, a0);
- } else snprintf (ret, sizeof (ret), "%s = %s & %s", r0, a0, a1);
+ } else {
+ snprintf (ret, sizeof (ret), "%s = %s & %s", r0, a0, a1);
+ }
break;
case R_ANAL_OP_TYPE_OR:
if (!a1 || !strcmp (a0, a1)) {
snprintf (ret, sizeof (ret), "%s |= %s", r0, a0);
- } else snprintf (ret, sizeof (ret), "%s = %s | %s", r0, a0, a1);
+ } else {
+ snprintf (ret, sizeof (ret), "%s = %s | %s", r0, a0, a1);
+ }
break;
case R_ANAL_OP_TYPE_XOR:
if (!a1 || !strcmp (a0, a1)) {
snprintf (ret, sizeof (ret), "%s ^= %s", r0, a0);
- } else snprintf (ret, sizeof (ret), "%s = %s ^ %s", r0, a0, a1);
+ } else {
+ snprintf (ret, sizeof (ret), "%s = %s ^ %s", r0, a0, a1);
+ }
break;
case R_ANAL_OP_TYPE_LEA:
snprintf (ret, sizeof (ret), "%s -> %s", r0, a0);
@@ -587,15 +609,33 @@ R_API const char *r_anal_op_family_to_string(int n) {
R_API int r_anal_op_family_from_string(const char *f) {
// TODO: use array of strings or so ..
- if (!strcmp (f, "cpu")) return R_ANAL_OP_FAMILY_CPU;
- if (!strcmp (f, "fpu")) return R_ANAL_OP_FAMILY_FPU;
- if (!strcmp (f, "mmx")) return R_ANAL_OP_FAMILY_MMX;
- if (!strcmp (f, "sse")) return R_ANAL_OP_FAMILY_SSE;
- if (!strcmp (f, "priv")) return R_ANAL_OP_FAMILY_PRIV;
- if (!strcmp (f, "virt")) return R_ANAL_OP_FAMILY_VIRT;
- if (!strcmp (f, "crpt")) return R_ANAL_OP_FAMILY_CRYPTO;
- if (!strcmp (f, "io")) return R_ANAL_OP_FAMILY_IO;
- if (!strcmp (f, "thrd")) return R_ANAL_OP_FAMILY_THREAD;
+ if (!strcmp (f, "cpu")) {
+ return R_ANAL_OP_FAMILY_CPU;
+ }
+ if (!strcmp (f, "fpu")) {
+ return R_ANAL_OP_FAMILY_FPU;
+ }
+ if (!strcmp (f, "mmx")) {
+ return R_ANAL_OP_FAMILY_MMX;
+ }
+ if (!strcmp (f, "sse")) {
+ return R_ANAL_OP_FAMILY_SSE;
+ }
+ if (!strcmp (f, "priv")) {
+ return R_ANAL_OP_FAMILY_PRIV;
+ }
+ if (!strcmp (f, "virt")) {
+ return R_ANAL_OP_FAMILY_VIRT;
+ }
+ if (!strcmp (f, "crpt")) {
+ return R_ANAL_OP_FAMILY_CRYPTO;
+ }
+ if (!strcmp (f, "io")) {
+ return R_ANAL_OP_FAMILY_IO;
+ }
+ if (!strcmp (f, "thrd")) {
+ return R_ANAL_OP_FAMILY_THREAD;
+ }
return R_ANAL_OP_FAMILY_UNKNOWN;
}
diff --git a/libr/anal/p/anal_6502.c b/libr/anal/p/anal_6502.c
index 0cb7fb0048..fb7a3d2381 100644
--- a/libr/anal/p/anal_6502.c
+++ b/libr/anal/p/anal_6502.c
@@ -28,10 +28,18 @@ enum {
static void _6502_anal_update_flags(RAnalOp *op, int flags) {
/* FIXME: $b9 instead of $b8 to prevent the bug triggered by: A = 0 - 0xff - 1 */
- if (flags & _6502_FLAGS_B) r_strbuf_append (&op->esil, ",$b9,C,=");
- if (flags & _6502_FLAGS_C) r_strbuf_append (&op->esil, ",$c7,C,=");
- if (flags & _6502_FLAGS_Z) r_strbuf_append (&op->esil, ",$z,Z,=");
- if (flags & _6502_FLAGS_N) r_strbuf_append (&op->esil, ",$s,N,=");
+ if (flags & _6502_FLAGS_B) {
+ r_strbuf_append (&op->esil, ",$b9,C,=");
+ }
+ if (flags & _6502_FLAGS_C) {
+ r_strbuf_append (&op->esil, ",$c7,C,=");
+ }
+ if (flags & _6502_FLAGS_Z) {
+ r_strbuf_append (&op->esil, ",$z,Z,=");
+ }
+ if (flags & _6502_FLAGS_N) {
+ r_strbuf_append (&op->esil, ",$s,N,=");
+ }
}
/* ORA, AND, EOR, ADC, STA, LDA, CMP and SBC share this pattern */
@@ -235,7 +243,9 @@ static void _6502_anal_esil_mov(RAnalOp *op, ut8 data0) {
r_strbuf_setf (&op->esil, "%s,%s,=",src,dst);
// don't update NZ on txs
- if (data0 != 0x9a) _6502_anal_update_flags (op, _6502_FLAGS_NZ);
+ if (data0 != 0x9a) {
+ _6502_anal_update_flags (op, _6502_FLAGS_NZ);
+ }
}
static void _6502_anal_esil_push(RAnalOp *op, ut8 data0) {
@@ -253,7 +263,9 @@ static void _6502_anal_esil_pop(RAnalOp *op, ut8 data0) {
// stack is on page one: sp + 0x100
r_strbuf_setf (&op->esil, "sp,++=,sp,0x100,+,[1],%s,=", reg);
- if (data0==0x68) _6502_anal_update_flags (op, _6502_FLAGS_NZ);
+ if (data0 == 0x68) {
+ _6502_anal_update_flags (op, _6502_FLAGS_NZ);
+ }
}
static void _6502_anal_esil_flags(RAnalOp *op, ut8 data0) {
@@ -463,9 +475,11 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
// FIXME: support BCD mode
op->type = R_ANAL_OP_TYPE_ADD;
_6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize);
- if (data[0] == 0x69) // immediate mode
+ if (data[0] == 0x69) { // immediate mode
r_strbuf_setf (&op->esil, "%s,a,+=,C,NUM,$c7,C,=,a,+=,$c7,C,|=", addrbuf);
- else r_strbuf_setf (&op->esil, "%s,[1],a,+=,C,NUM,$c7,C,=,a,+=,$c7,C,|=", addrbuf);
+ } else {
+ r_strbuf_setf (&op->esil, "%s,[1],a,+=,C,NUM,$c7,C,=,a,+=,$c7,C,|=", addrbuf);
+ }
_6502_anal_update_flags (op, _6502_FLAGS_NZ);
// fix Z
r_strbuf_append (&op->esil, ",a,a,=,$z,Z,=");
@@ -483,9 +497,11 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
// FIXME: support BCD mode
op->type = R_ANAL_OP_TYPE_SUB;
_6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize);
- if (data[0] == 0xe9) // immediate mode
+ if (data[0] == 0xe9) { // immediate mode
r_strbuf_setf (&op->esil, "C,!,%s,+,a,-=", addrbuf);
- else r_strbuf_setf (&op->esil, "C,!,%s,[1],+,a,-=", addrbuf);
+ } else {
+ r_strbuf_setf (&op->esil, "C,!,%s,[1],+,a,-=", addrbuf);
+ }
_6502_anal_update_flags (op, _6502_FLAGS_BNZ);
// fix Z and revert C
r_strbuf_append (&op->esil, ",a,a,=,$z,Z,=,C,!=");
@@ -501,9 +517,11 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
case 0x11: // ora ($ff),y
op->type = R_ANAL_OP_TYPE_OR;
_6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize);
- if (data[0] == 0x09) // immediate mode
+ if (data[0] == 0x09) { // immediate mode
r_strbuf_setf (&op->esil, "%s,a,|=", addrbuf);
- else r_strbuf_setf (&op->esil, "%s,[1],a,|=", addrbuf);
+ } else {
+ r_strbuf_setf (&op->esil, "%s,[1],a,|=", addrbuf);
+ }
_6502_anal_update_flags (op, _6502_FLAGS_NZ);
break;
// AND
@@ -517,9 +535,11 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
case 0x31: // and ($ff),y
op->type = R_ANAL_OP_TYPE_AND;
_6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize);
- if (data[0] == 0x29) // immediate mode
+ if (data[0] == 0x29) { // immediate mode
r_strbuf_setf (&op->esil, "%s,a,&=", addrbuf);
- else r_strbuf_setf (&op->esil, "%s,[1],a,&=", addrbuf);
+ } else {
+ r_strbuf_setf (&op->esil, "%s,[1],a,&=", addrbuf);
+ }
_6502_anal_update_flags (op, _6502_FLAGS_NZ);
break;
// EOR
@@ -533,9 +553,11 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
case 0x51: // eor ($ff),y
op->type = R_ANAL_OP_TYPE_XOR;
_6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize);
- if (data[0] == 0x49) // immediate mode
+ if (data[0] == 0x49) { // immediate mode
r_strbuf_setf (&op->esil, "%s,a,^=", addrbuf);
- else r_strbuf_setf (&op->esil, "%s,[1],a,^=", addrbuf);
+ } else {
+ r_strbuf_setf (&op->esil, "%s,[1],a,^=", addrbuf);
+ }
_6502_anal_update_flags (op, _6502_FLAGS_NZ);
break;
// ASL
@@ -645,9 +667,11 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
case 0xd1: // cmp ($ff),y
op->type = R_ANAL_OP_TYPE_CMP;
_6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize);
- if (data[0] == 0xc9) // immediate mode
+ if (data[0] == 0xc9) { // immediate mode
r_strbuf_setf (&op->esil, "%s,a,==", addrbuf);
- else r_strbuf_setf (&op->esil, "%s,[1],a,==", addrbuf);
+ } else {
+ r_strbuf_setf (&op->esil, "%s,[1],a,==", addrbuf);
+ }
_6502_anal_update_flags (op, _6502_FLAGS_BNZ);
// invert C, since C=1 when A-M >= 0
r_strbuf_append (&op->esil, ",C,!,C,=");
@@ -658,9 +682,11 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
case 0xec: // cpx $ffff
op->type = R_ANAL_OP_TYPE_CMP;
_6502_anal_esil_get_addr_pattern3 (op, data, len, addrbuf, buffsize, 0);
- if (data[0] == 0xe0) // immediate mode
+ if (data[0] == 0xe0) { // immediate mode
r_strbuf_setf (&op->esil, "%s,x,==", addrbuf);
- else r_strbuf_setf (&op->esil, "%s,[1],x,==", addrbuf);
+ } else {
+ r_strbuf_setf (&op->esil, "%s,[1],x,==", addrbuf);
+ }
_6502_anal_update_flags (op, _6502_FLAGS_BNZ);
// invert C, since C=1 when A-M >= 0
r_strbuf_append (&op->esil, ",C,!,C,=");
@@ -671,9 +697,11 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
case 0xcc: // cpy $ffff
op->type = R_ANAL_OP_TYPE_CMP;
_6502_anal_esil_get_addr_pattern3 (op, data, len, addrbuf, buffsize, 0);
- if (data[0] == 0xc0) // immediate mode
+ if (data[0] == 0xc0) { // immediate mode
r_strbuf_setf (&op->esil, "%s,y,==", addrbuf);
- else r_strbuf_setf (&op->esil, "%s,[1],y,==", addrbuf);
+ } else {
+ r_strbuf_setf (&op->esil, "%s,[1],y,==", addrbuf);
+ }
_6502_anal_update_flags (op, _6502_FLAGS_BNZ);
// invert C, since C=1 when A-M >= 0
r_strbuf_append (&op->esil, ",C,!,C,=");
@@ -770,9 +798,11 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
case 0xb1: // lda ($ff),y
op->type = R_ANAL_OP_TYPE_LOAD;
_6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize);
- if (data[0] == 0xa9) // immediate mode
+ if (data[0] == 0xa9) { // immediate mode
r_strbuf_setf (&op->esil, "%s,a,=", addrbuf);
- else r_strbuf_setf (&op->esil, "%s,[1],a,=", addrbuf);
+ } else {
+ r_strbuf_setf (&op->esil, "%s,[1],a,=", addrbuf);
+ }
_6502_anal_update_flags (op, _6502_FLAGS_NZ);
break;
// LDX
@@ -798,9 +828,11 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
case 0xbc: // ldy $ffff,x
op->type = R_ANAL_OP_TYPE_LOAD;
_6502_anal_esil_get_addr_pattern3 (op, data, len, addrbuf, buffsize, 'x');
- if (data[0] == 0xa0) // immediate mode
+ if (data[0] == 0xa0) { // immediate mode
r_strbuf_setf (&op->esil, "%s,y,=", addrbuf);
- else r_strbuf_setf (&op->esil, "%s,[1],y,=", addrbuf);
+ } else {
+ r_strbuf_setf (&op->esil, "%s,[1],y,=", addrbuf);
+ }
_6502_anal_update_flags (op, _6502_FLAGS_NZ);
break;
// STA
diff --git a/libr/anal/p/anal_arc.c b/libr/anal/p/anal_arc.c
index 45c569c55c..cde37ef1a6 100644
--- a/libr/anal/p/anal_arc.c
+++ b/libr/anal/p/anal_arc.c
@@ -1017,8 +1017,9 @@ static int arc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len)
const ut8 *b = (ut8 *)data;
memset (op, '\0', sizeof (RAnalOp));
- if (anal->bits == 16)
+ if (anal->bits == 16) {
return arcompact_op (anal, op, addr, data, len);
+ }
/* ARCtangent A4 */
op->size = 4;
diff --git a/libr/anal/p/anal_avr.c b/libr/anal/p/anal_avr.c
index 3312e19b20..3540fe8b32 100644
--- a/libr/anal/p/anal_avr.c
+++ b/libr/anal/p/anal_avr.c
@@ -199,8 +199,9 @@ static CPU_CONST *const_by_name(CPU_MODEL *cpu, int type, char *c) {
}
}
}
- if (cpu->inherit_cpu_p)
+ if (cpu->inherit_cpu_p) {
return const_by_name (cpu->inherit_cpu_p, type, c);
+ }
eprintf ("ERROR: CONSTANT key[%s] NOT FOUND.\n", c);
return NULL;
}
@@ -226,8 +227,9 @@ static CPU_CONST *const_by_value(CPU_MODEL *cpu, int type, ut32 v) {
}
}
}
- if (cpu->inherit_cpu_p)
+ if (cpu->inherit_cpu_p) {
return const_by_value (cpu->inherit_cpu_p, type, v);
+ }
return NULL;
}
@@ -365,10 +367,11 @@ static void __generic_sub_update_flags(RAnalOp *op, char t_d, ut64 v_d, char t_r
"|,vf,=,",
d, rk, d, rk);
ESIL_A ("0,RPICK,0x80,&,!,!,nf,=,"); // N
- if (carry)
+ if (carry) {
ESIL_A ("0,RPICK,!,zf,&,zf,=,"); // Z
- else
- ESIL_A ("0,RPICK,!,zf,=,"); // Z
+ } else {
+ ESIL_A ("0,RPICK,!,zf,=,"); // Z
+ }
ESIL_A ("%s,0x80,&,!," "%s,0x80,&,!,!," "&," // C
"%s,0x80,&,!,!," "0,RPICK,0x80,&,!,!," "&,"
"%s,0x80,&,!," "0,RPICK,0x80,&,!,!," "&,"
@@ -2131,12 +2134,15 @@ RAMPX, RAMPY, RAMPZ, RAMPD and EIND:
}
static int archinfo(RAnal *anal, int q) {
- if (q == R_ANAL_ARCHINFO_ALIGN)
+ if (q == R_ANAL_ARCHINFO_ALIGN) {
return 2;
- if (q == R_ANAL_ARCHINFO_MAX_OP_SIZE)
+ }
+ if (q == R_ANAL_ARCHINFO_MAX_OP_SIZE) {
return 4;
- if (q == R_ANAL_ARCHINFO_MIN_OP_SIZE)
+ }
+ if (q == R_ANAL_ARCHINFO_MIN_OP_SIZE) {
return 2;
+ }
return 2; // XXX
}
diff --git a/libr/anal/p/anal_bf.c b/libr/anal/p/anal_bf.c
index 80847c0426..62e48eb0cb 100644
--- a/libr/anal/p/anal_bf.c
+++ b/libr/anal/p/anal_bf.c
@@ -9,8 +9,9 @@
static int countChar (const ut8 *buf, int len, char ch) {
int i;
for (i = 0; i < len; i++) {
- if (buf[i] != ch)
+ if (buf[i] != ch) {
break;
+ }
}
return i;
}
@@ -45,8 +46,9 @@ static int bf_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
int lev = 0, i = 1;
len--;
while (i < len && *p) {
- if (*p == '[')
+ if (*p == '[') {
lev++;
+ }
if (*p == ']') {
lev--;
if (lev==-1) {
diff --git a/libr/anal/p/anal_ebc.c b/libr/anal/p/anal_ebc.c
index 0fde261474..a64019c7f3 100644
--- a/libr/anal/p/anal_ebc.c
+++ b/libr/anal/p/anal_ebc.c
@@ -24,8 +24,9 @@ static void ebc_anal_jmp8(RAnalOp *op, ut64 addr, const ut8 *buf) {
static void ebc_anal_jmp(RAnalOp *op, ut64 addr, const ut8 *buf) {
op->fail = addr + 6;
op->jump = (ut64)*(int32_t*)(buf + 2);
- if (TEST_BIT(buf[1], 4))
+ if (TEST_BIT (buf[1], 4)) {
op->jump += addr + 6;
+ }
if (buf[1] & 0x7) {
op->type = R_ANAL_OP_TYPE_UJMP;
} else {
@@ -61,8 +62,9 @@ static int ebc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len)
ebc_command_t cmd;
ut8 opcode = buf[0] & EBC_OPCODE_MASK;
- if (!op)
+ if (!op) {
return 2;
+ }
memset(op, 0, sizeof (RAnalOp));
op->addr = addr;
@@ -71,8 +73,9 @@ static int ebc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len)
ret = op->size = ebc_decode_command(buf, &cmd);
- if (ret < 0)
+ if (ret < 0) {
return ret;
+ }
switch (opcode) {
case EBC_JMP8:
diff --git a/libr/anal/p/anal_gb.c b/libr/anal/p/anal_gb.c
index f162dbc2fc..37a2a4bb90 100644
--- a/libr/anal/p/anal_gb.c
+++ b/libr/anal/p/anal_gb.c
@@ -28,9 +28,11 @@ static ut8 gb_op_calljump(RAnal *a, RAnalOp *op, const ut8 *data, ut64 addr)
r_meta_set_string (a, R_META_TYPE_COMMENT, addr, "--> unpredictable");
return false;
}
- if (!GB_IS_VBANK_DST (data[1], data[2]))
+ if (!GB_IS_VBANK_DST (data[1], data[2])) {
op->jump = GB_SOFTCAST(data[1], data[2]);
- else op->jump = GB_IB_DST (data[1], data[2], addr);
+ } else {
+ op->jump = GB_IB_DST (data[1], data[2], addr);
+ }
return true;
}
@@ -66,9 +68,11 @@ static inline void gb_anal_esil_ccall (RAnalOp *op, const ut8 data)
default:
cond = 'C';
}
- if (op->cond == R_ANAL_COND_EQ)
+ if (op->cond == R_ANAL_COND_EQ) {
r_strbuf_setf (&op->esil, "%c,?{,2,sp,-=,pc,sp,=[2],%"PFMT64d",pc,=,}", cond, (op->jump & 0xffff));
- else r_strbuf_setf (&op->esil, "%c,!,?{,2,sp,-=,pc,sp,=[2],%"PFMT64d",pc,=,}", cond, (op->jump & 0xffff));
+ } else {
+ r_strbuf_setf (&op->esil, "%c,!,?{,2,sp,-=,pc,sp,=[2],%" PFMT64d ",pc,=,}", cond, (op->jump & 0xffff));
+ }
}
static inline void gb_anal_esil_ret (RAnalOp *op)
@@ -79,12 +83,16 @@ static inline void gb_anal_esil_ret (RAnalOp *op)
static inline void gb_anal_esil_cret (RAnalOp *op, const ut8 data)
{
char cond;
- if ((data & 0xd0) == 0xd0)
+ if ((data & 0xd0) == 0xd0) {
cond = 'C';
- else cond = 'Z';
- if (op->cond == R_ANAL_COND_EQ)
+ } else {
+ cond = 'Z';
+ }
+ if (op->cond == R_ANAL_COND_EQ) {
r_strbuf_setf (&op->esil, "%c,?{,sp,[2],pc,=,2,sp,+=,}", cond);
- else r_strbuf_setf (&op->esil, "%c,!,?{,sp,[2],pc,=,2,sp,+=,}", cond);
+ } else {
+ r_strbuf_setf (&op->esil, "%c,!,?{,sp,[2],pc,=,2,sp,+=,}", cond);
+ }
}
static inline void gb_anal_esil_cjmp (RAnalOp *op, const ut8 data)
@@ -100,9 +108,11 @@ static inline void gb_anal_esil_cjmp (RAnalOp *op, const ut8 data)
default:
cond = 'C';
}
- if (op->cond == R_ANAL_COND_EQ)
+ if (op->cond == R_ANAL_COND_EQ) {
r_strbuf_setf (&op->esil, "%c,?{,0x%"PFMT64x",pc,=,}", cond, (op->jump & 0xffff));
- else r_strbuf_setf (&op->esil, "%c,!,?{,0x%"PFMT64x",pc,=,}", cond, (op->jump & 0xffff));
+ } else {
+ r_strbuf_setf (&op->esil, "%c,!,?{,0x%" PFMT64x ",pc,=,}", cond, (op->jump & 0xffff));
+ }
}
static inline void gb_anal_esil_jmp (RAnalOp *op)
@@ -126,20 +136,26 @@ static inline void gb_anal_id (RAnal *anal, RAnalOp *op, const ut8 data) {
if (data == 0x34 || data == 0x35) {
op->dst->memref = 1;
op->dst->reg = r_reg_get (anal->reg, "hl", R_REG_TYPE_GPR);
- if (op->type == R_ANAL_OP_TYPE_ADD)
+ if (op->type == R_ANAL_OP_TYPE_ADD) {
r_strbuf_set (&op->esil, "1,hl,[1],+,hl,=[1],$c3,H,=,$z,Z,=,0,N,=");
- else r_strbuf_set (&op->esil, "1,hl,[1],-,hl,=[1],$b4,H,=,$z,Z,=,1,N,=");
+ } else {
+ r_strbuf_set (&op->esil, "1,hl,[1],-,hl,=[1],$b4,H,=,$z,Z,=,1,N,=");
+ }
} else {
if (!(data & (1<<2))) {
op->dst->reg = r_reg_get (anal->reg, regs_16[data>>4], R_REG_TYPE_GPR);
- if (op->type == R_ANAL_OP_TYPE_ADD)
+ if (op->type == R_ANAL_OP_TYPE_ADD) {
r_strbuf_setf (&op->esil, "1,%s,+=", regs_16[data>>4]);
- else r_strbuf_setf (&op->esil, "1,%s,-=", regs_16[data>>4]);
+ } else {
+ r_strbuf_setf (&op->esil, "1,%s,-=", regs_16[data >> 4]);
+ }
} else {
op->dst->reg = r_reg_get (anal->reg, regs_8[data>>3], R_REG_TYPE_GPR);
- if (op->type == R_ANAL_OP_TYPE_ADD)
+ if (op->type == R_ANAL_OP_TYPE_ADD) {
r_strbuf_setf (&op->esil, "1,%s,+=,$c3,H,=,$z,Z,=,0,N,=", regs_8[data>>3]);
- else r_strbuf_setf (&op->esil, "1,%s,-=,$b4,H,=,$z,Z,=,1,N,=", regs_8[data>>3]);
+ } else {
+ r_strbuf_setf (&op->esil, "1,%s,-=,$b4,H,=,$z,Z,=,1,N,=", regs_8[data >> 3]);
+ }
}
}
}
@@ -157,9 +173,11 @@ static inline void gb_anal_add_sp (RReg *reg, RAnalOp *op, const ut8 data) {
op->src[0] = r_anal_value_new ();
op->dst->reg = r_reg_get (reg, "sp", R_REG_TYPE_GPR);
op->src[0]->imm = (st8)data;
- if (data < 128)
+ if (data < 128) {
r_strbuf_setf (&op->esil, "0x%02x,sp,+=", data);
- else r_strbuf_setf (&op->esil, "0x%02x,sp,-=", 0 - (st8)data);
+ } else {
+ r_strbuf_setf (&op->esil, "0x%02x,sp,-=", 0 - (st8)data);
+ }
r_strbuf_append (&op->esil, ",0,Z,=,0,N,=");
}
@@ -194,9 +212,11 @@ static inline void gb_anal_mov_hl_sp (RReg *reg, RAnalOp *op, const ut8 data) {
op->dst->reg = r_reg_get (reg, regs_16[2], R_REG_TYPE_GPR);
op->src[0]->reg = r_reg_get (reg, regs_16[3], R_REG_TYPE_GPR);
op->src[1]->imm = (st8)data;
- if (data < 128)
+ if (data < 128) {
r_strbuf_setf (&op->esil, "0x%02x,sp,+,hl,=", data);
- else r_strbuf_setf (&op->esil, "0x%02x,sp,-,hl,=", 0 - (st8)data);
+ } else {
+ r_strbuf_setf (&op->esil, "0x%02x,sp,-,hl,=", 0 - (st8)data);
+ }
r_strbuf_append (&op->esil, ",0,Z,=,0,N,=");
}
@@ -215,8 +235,9 @@ static inline void gb_anal_mov_ime (RReg *reg, RAnalOp *op, const ut8 data) {
op->src[0]->absolute = true;
op->src[0]->imm = (data != 0xf3);
r_strbuf_setf (&op->esil, "%d,ime,=", (int)op->src[0]->imm);
- if (data == 0xd9)
+ if (data == 0xd9) {
r_strbuf_append (&op->esil, ",");
+ }
}
static inline void gb_anal_mov_scf (RReg *reg, RAnalOp *op) {
@@ -247,8 +268,11 @@ static inline void gb_anal_cond (RReg *reg, RAnalOp *op, const ut8 data) {
op->dst = r_anal_value_new ();
op->src[0] = r_anal_value_new ();
op->src[0]->imm = 1;
- if (data & 0x8) op->cond = R_ANAL_COND_EQ;
- else op->cond = R_ANAL_COND_NE;
+ if (data & 0x8) {
+ op->cond = R_ANAL_COND_EQ;
+ } else {
+ op->cond = R_ANAL_COND_NE;
+ }
switch (data) {
case 0x20:
case 0x28:
@@ -284,9 +308,11 @@ static inline void gb_anal_and_res (RAnal *anal, RAnalOp *op, const ut8 data) {
op->src[0]->imm = ((~(0x1 << ((data >> 3) & 7))) & 0xff);
op->dst->memref = ((data & 7) == 6);
op->dst->reg = r_reg_get (anal->reg, regs_x[data & 7], R_REG_TYPE_GPR);
- if (op->dst->memref)
+ if (op->dst->memref) {
r_strbuf_setf (&op->esil, "0x%02x,%s,[1],&,%s,=[1]", op->src[0]->imm, regs_x[data & 7], regs_x[data & 7]);
- else r_strbuf_setf (&op->esil, "0x%02x,%s,&=", op->src[0]->imm, regs_x[data & 7]);
+ } else {
+ r_strbuf_setf (&op->esil, "0x%02x,%s,&=", op->src[0]->imm, regs_x[data & 7]);
+ }
}
static inline void gb_anal_and_bit (RReg *reg, RAnalOp *op, const ut8 data) {
@@ -295,9 +321,11 @@ static inline void gb_anal_and_bit (RReg *reg, RAnalOp *op, const ut8 data) {
op->src[0]->imm = 1<<((data>>3) & 7);
op->dst->memref = ((data & 7) == 6);
op->dst->reg = r_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR);
- if (op->dst->memref)
+ if (op->dst->memref) {
r_strbuf_setf (&op->esil, "%i,%s,[1],&,0,==,$z,Z,=,0,N,=,1,H,=", op->src[0]->imm, regs_x[data & 7]);
- else r_strbuf_setf (&op->esil, "%i,%s,&,0,==,$z,Z,=,0,N,=,1,H,=", op->src[0]->imm, regs_x[data & 7]);
+ } else {
+ r_strbuf_setf (&op->esil, "%i,%s,&,0,==,$z,Z,=,0,N,=,1,H,=", op->src[0]->imm, regs_x[data & 7]);
+ }
}
static inline void gb_anal_or_set (RAnal *anal, RAnalOp *op, const ut8 data) {
@@ -306,9 +334,11 @@ static inline void gb_anal_or_set (RAnal *anal, RAnalOp *op, const ut8 data) {
op->src[0]->imm = (data>>3) & 7;
op->dst->memref = ((data & 7) == 6);
op->dst->reg = r_reg_get (anal->reg, regs_x[data & 7], R_REG_TYPE_GPR);
- if (op->dst->memref)
+ if (op->dst->memref) {
r_strbuf_setf (&op->esil, "0x%02x,%s,[1],|,%s,=[1]", op->src[0]->imm, regs_x[data & 7], regs_x[data & 7], op->src[0]->imm);
- else r_strbuf_setf (&op->esil, "0x%02x,%s,|=", op->src[0]->imm, regs_x[data & 7]);
+ } else {
+ r_strbuf_setf (&op->esil, "0x%02x,%s,|=", op->src[0]->imm, regs_x[data & 7]);
+ }
}
static void gb_anal_xoaasc (RReg *reg, RAnalOp *op, const ut8 *data) {
@@ -319,20 +349,26 @@ static void gb_anal_xoaasc (RReg *reg, RAnalOp *op, const ut8 *data) {
op->src[0]->memref = ((data[0] & 7) == 6);
switch (op->type) {
case R_ANAL_OP_TYPE_XOR:
- if (op->src[0]->memref)
+ if (op->src[0]->memref) {
r_strbuf_setf (&op->esil, "%s,[1],a,^=,$z,Z,=,0,N,=,0,H,=,0,C,=", regs_x[data[0] & 7]);
- else r_strbuf_setf (&op->esil, "%s,a,^=,$z,Z,=,0,N,=,0,H,=,0,C,=", regs_x[data[0] & 7]);
- break;
+ } else {
+ r_strbuf_setf (&op->esil, "%s,a,^=,$z,Z,=,0,N,=,0,H,=,0,C,=", regs_x[data[0] & 7]);
+ }
+ break;
case R_ANAL_OP_TYPE_OR:
- if (op->src[0]->memref)
+ if (op->src[0]->memref) {
r_strbuf_setf (&op->esil, "%s,[1],a,|=,$z,Z,=,0,N,=,0,H,=,0,C,=", regs_x[data[0] &7]);
- else r_strbuf_setf (&op->esil, "%s,a,|=,$z,Z,=,0,N,=,0,H,=,0,C,=", regs_x[data[0] & 7]);
- break;
+ } else {
+ r_strbuf_setf (&op->esil, "%s,a,|=,$z,Z,=,0,N,=,0,H,=,0,C,=", regs_x[data[0] & 7]);
+ }
+ break;
case R_ANAL_OP_TYPE_AND:
- if (op->src[0]->memref)
+ if (op->src[0]->memref) {
r_strbuf_setf (&op->esil, "%s,[1],a,&=,$z,Z,=,0,N,=,1,H,=,0,C,=", regs_x[data[0] & 7]);
- else r_strbuf_setf (&op->esil, "%s,a,&=,$z,Z,=,0,N,=,1,H,=,0,C,=", regs_x[data[0] & 7]);
- break;
+ } else {
+ r_strbuf_setf (&op->esil, "%s,a,&=,$z,Z,=,0,N,=,1,H,=,0,C,=", regs_x[data[0] & 7]);
+ }
+ break;
case R_ANAL_OP_TYPE_ADD:
if (op->src[0]->memref) {
if (data[0] > 0x87) {
@@ -372,10 +408,12 @@ static void gb_anal_xoaasc (RReg *reg, RAnalOp *op, const ut8 *data) {
}
break;
case R_ANAL_OP_TYPE_CMP:
- if (op->src[0]->memref)
+ if (op->src[0]->memref) {
r_strbuf_setf (&op->esil, "%s,[1],a,==,$z,Z,=,$b4,H,=,$b8,C,=,1,N,=", regs_x[data[0] & 7]);
- else r_strbuf_setf (&op->esil, "%s,a,==,$z,Z,=,$b4,H,=,$b8,C,=,1,N,=", regs_x[data[0] & 7]);
- break;
+ } else {
+ r_strbuf_setf (&op->esil, "%s,a,==,$z,Z,=,$b4,H,=,$b8,C,=,1,N,=", regs_x[data[0] & 7]);
+ }
+ break;
}
}
@@ -402,16 +440,20 @@ static void gb_anal_xoaasc_imm (RReg *reg, RAnalOp *op, const ut8 *data) //xor ,
op->src[1] = r_anal_value_new ();
op->src[1]->reg = r_reg_get (reg, "C", R_REG_TYPE_GPR);
r_strbuf_append (&op->esil, "a,+=,C,NUM,$c7,C,=,$c3,H,=,a,+=,$c7,C,|=,$c3,H,|=,a,a,=,$z,Z,=,0,N,=");
- } else r_strbuf_append (&op->esil, "a,+=,$c3,H,=,$c7,C,=,0,N,=,a,a,=,$z,Z,=");
- break;
+ } else {
+ r_strbuf_append (&op->esil, "a,+=,$c3,H,=,$c7,C,=,0,N,=,a,a,=,$z,Z,=");
+ }
+ break;
case R_ANAL_OP_TYPE_SUB:
r_strbuf_setf (&op->esil, "0x%02x,", data[1]);
if (data[0] == 0xde) { //sbc
op->src[1] = r_anal_value_new ();
op->src[1]->reg = r_reg_get (reg, "C", R_REG_TYPE_GPR);
r_strbuf_append (&op->esil, "a,-=,C,NUM,$b8,C,=,$b4,H,=,a,-=,$b8,C,|=,$b4,H,|=,a,a,=,$z,Z,=,1,N,=");
- } else r_strbuf_append (&op->esil, "a,-=,$b4,H,=,$b8,C,=,1,N,=,a,a,=,$z,Z,=");
- break;
+ } else {
+ r_strbuf_append (&op->esil, "a,-=,$b4,H,=,$b8,C,=,1,N,=,a,a,=,$z,Z,=");
+ }
+ break;
case R_ANAL_OP_TYPE_CMP:
r_strbuf_setf (&op->esil, "%d,a,==,$z,Z,=,$b4,H,=,$b8,C,=,1,N,=", data[1]);
break;
@@ -481,10 +523,12 @@ static inline void gb_anal_store_hl (RReg *reg, RAnalOp *op, const ut8 *data) {
op->src[0]->reg = r_reg_get (reg, regs_8[data[0] & 0x07], R_REG_TYPE_GPR);
r_strbuf_setf (&op->esil, "%s,hl,=[1]", regs_8[data[0] & 0x07]);
}
- if (data[0] == 0x32)
+ if (data[0] == 0x32) {
r_strbuf_set (&op->esil, "a,hl,=[1],1,hl,-=");
- if (data[0] == 0x22)
+ }
+ if (data[0] == 0x22) {
r_strbuf_set (&op->esil, "a,hl,=[1],1,hl,+=");
+ }
}
static void gb_anal_store (RReg *reg, RAnalOp *op, const ut8 *data)
@@ -528,7 +572,9 @@ static inline void gb_anal_cb_swap (RReg *reg, RAnalOp* op, const ut8 data)
if ((data & 7) == 6) {
op->dst->memref = 1;
r_strbuf_setf (&op->esil, "4,%s,[1],>>,4,%s,[1],<<,|,%s,=[1],$z,Z,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]);
- } else r_strbuf_setf (&op->esil, "4,%s,>>,4,%s,<<,|,%s,=,$z,Z,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]);
+ } else {
+ r_strbuf_setf (&op->esil, "4,%s,>>,4,%s,<<,|,%s,=,$z,Z,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]);
+ }
}
static inline void gb_anal_cb_rlc (RReg *reg, RAnalOp *op, const ut8 data)
@@ -540,7 +586,9 @@ static inline void gb_anal_cb_rlc (RReg *reg, RAnalOp *op, const ut8 data)
if ((data & 7) == 6) {
op->dst->memref = 1;
r_strbuf_setf (&op->esil, "7,%s,[1],>>,1,&,C,=,1,%s,[1],<<,C,|,%s,=[1],$z,Z,=,0,H,=,0,N,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]);
- } else r_strbuf_setf (&op->esil, "1,%s,<<=,$c7,C,=,C,%s,|=,$z,Z,=,0,H,=,0,N,=", regs_x[data & 7], regs_x[data & 7]);
+ } else {
+ r_strbuf_setf (&op->esil, "1,%s,<<=,$c7,C,=,C,%s,|=,$z,Z,=,0,H,=,0,N,=", regs_x[data & 7], regs_x[data & 7]);
+ }
}
static inline void gb_anal_cb_rl (RReg *reg, RAnalOp *op, const ut8 data)
@@ -552,7 +600,9 @@ static inline void gb_anal_cb_rl (RReg *reg, RAnalOp *op, const ut8 data)
if ((data & 7) == 6) {
op->dst->memref = 1;
r_strbuf_setf (&op->esil, "1,%s,<<,C,|,%s,=[1],$c7,C,=,$z,Z,=,0,H,=,0,N,=", regs_x[data & 7], regs_x[data & 7]);
- } else r_strbuf_setf (&op->esil, "1,%s,<<,C,|,%s,=,$c7,C,=,$z,Z,=,0,H,=,0,N,=", regs_x[data & 7], regs_x[data & 7]);
+ } else {
+ r_strbuf_setf (&op->esil, "1,%s,<<,C,|,%s,=,$c7,C,=,$z,Z,=,0,H,=,0,N,=", regs_x[data & 7], regs_x[data & 7]);
+ }
}
static inline void gb_anal_cb_rrc (RReg *reg, RAnalOp *op, const ut8 data)
@@ -564,7 +614,9 @@ static inline void gb_anal_cb_rrc (RReg *reg, RAnalOp *op, const ut8 data)
if ((data &7) == 6) {
op->dst->memref = 1;
r_strbuf_setf (&op->esil, "1,%s,[1],&,C,=,1,%s,[1],>>,7,C,<<,|,%s,=[1],$z,Z,=,0,H,=,0,N,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]);
- } else r_strbuf_setf (&op->esil, "1,%s,&,C,=,1,%s,>>,7,C,<<,|,%s,=,$z,Z,=,0,H,=,0,N,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]);
+ } else {
+ r_strbuf_setf (&op->esil, "1,%s,&,C,=,1,%s,>>,7,C,<<,|,%s,=,$z,Z,=,0,H,=,0,N,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]);
+ }
}
static inline void gb_anal_cb_rr (RReg *reg, RAnalOp *op, const ut8 data)
@@ -576,7 +628,9 @@ static inline void gb_anal_cb_rr (RReg *reg, RAnalOp *op, const ut8 data)
if ((data & 7) == 6) {
op->dst->memref = 1;
r_strbuf_setf (&op->esil, "1,%s,[1],&,H,=,1,%s,[1],>>,7,C,<<,|,%s,=[1],H,C,=,0,H,=,0,N,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]);
- } else r_strbuf_setf (&op->esil, "1,%s,&,H,=,1,%s,>>,7,C,<<,|,%s,=,H,C,=,0,H,=,0,N,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); //HACK
+ } else {
+ r_strbuf_setf (&op->esil, "1,%s,&,H,=,1,%s,>>,7,C,<<,|,%s,=,H,C,=,0,H,=,0,N,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); //HACK
+ }
}
static inline void gb_anal_cb_sla (RReg *reg, RAnalOp *op, const ut8 data) //sra+sla+srl in one function, like xoaasc
@@ -586,9 +640,11 @@ static inline void gb_anal_cb_sla (RReg *reg, RAnalOp *op, const ut8 data)
op->src[0]->imm = 1;
op->dst->reg = r_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR);
op->dst->memref = ((data & 7) == 6);
- if (op->dst->memref)
+ if (op->dst->memref) {
r_strbuf_setf (&op->esil, "1,%s,[1],<<,%s,=[1],$c7,C,=,%s,[1],%s,=[1],$z,Z,=,0,H,=,0,N,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]);
- else r_strbuf_setf (&op->esil, "1,%s,<<=,$c7,C,=,%s,%s,=,$z,Z,=,0,H,=0,N,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); // %s,%s,= is a HACK for $z
+ } else {
+ r_strbuf_setf (&op->esil, "1,%s,<<=,$c7,C,=,%s,%s,=,$z,Z,=,0,H,=0,N,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); // %s,%s,= is a HACK for $z
+ }
}
static inline void gb_anal_cb_sra (RReg *reg, RAnalOp *op, const ut8 data) {
@@ -597,9 +653,11 @@ static inline void gb_anal_cb_sra (RReg *reg, RAnalOp *op, const ut8 data) {
op->src[0]->imm = 1;
op->dst->reg = r_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR);
op->dst->memref = ((data & 7) == 6);
- if (op->dst->memref)
+ if (op->dst->memref) {
r_strbuf_setf (&op->esil, "1,%s,[1],&,C,=,0x80,%s,[1],&,1,%s,[1],>>,|,%s,=[1],$z,Z,=,0,N,=,0,H,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); //spaguesil
- else r_strbuf_setf (&op->esil, "1,%s,&,C,=,0x80,%s,&,1,%s,>>,|,%s,=,$z,Z,=,0,N,=,0,H,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]);
+ } else {
+ r_strbuf_setf (&op->esil, "1,%s,&,C,=,0x80,%s,&,1,%s,>>,|,%s,=,$z,Z,=,0,N,=,0,H,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]);
+ }
}
static inline void gb_anal_cb_srl (RReg *reg, RAnalOp *op, const ut8 data) {
@@ -608,16 +666,19 @@ static inline void gb_anal_cb_srl (RReg *reg, RAnalOp *op, const ut8 data) {
op->src[0]->imm = 1;
op->dst->reg = r_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR);
op->dst->memref = ((data & 7) == 6);
- if (op->dst->memref)
+ if (op->dst->memref) {
r_strbuf_setf (&op->esil, "1,%s,[1],&,C,=,1,%s,[1],>>,%s,=[1],$z,Z,=,0,N,=,0,H,=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]);
- else r_strbuf_setf (&op->esil, "1,%s,&,C,=,1,%s,>>=,$z,Z,=,0,N,=,0,H,=", regs_x[data & 7], regs_x[data & 7]);
+ } else {
+ r_strbuf_setf (&op->esil, "1,%s,&,C,=,1,%s,>>=,$z,Z,=,0,N,=,0,H,=", regs_x[data & 7], regs_x[data & 7]);
+ }
}
static int gb_custom_daa (RAnalEsil *esil) {
ut8 a, H, C, Z;
ut64 n;
- if (!esil || !esil->anal || !esil->anal->reg)
+ if (!esil || !esil->anal || !esil->anal->reg) {
return false;
+ }
r_anal_esil_reg_read (esil, "H", &n, NULL);
H = (ut8)n;
r_anal_esil_reg_read (esil, "C", &n, NULL);
@@ -627,18 +688,22 @@ static int gb_custom_daa (RAnalEsil *esil) {
a = (ut8)n;
r_anal_esil_reg_read (esil, "N", &n, NULL);
if (n) {
- if (C)
+ if (C) {
a = (a - 0x60) & 0xff;
- else r_anal_esil_reg_write (esil, "C", 0LL);
- if (H)
+ } else {
+ r_anal_esil_reg_write (esil, "C", 0LL);
+ }
+ if (H) {
a = (a - 0x06) & 0xff;
+ }
} else {
if (C || (a > 0x99)) {
a = (a + 0x60) & 0xff;
r_anal_esil_reg_write (esil, "C", 1LL);
}
- if (H || ((a & 0x0f) > 0x09))
- a += 0x06;;
+ if (H || ((a & 0x0f) > 0x09)) {
+ a += 0x06;
+ };
}
esil->cur = a;
Z = (a == 0);
@@ -650,8 +715,9 @@ static int gb_custom_daa (RAnalEsil *esil) {
static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len){
int ilen = gbOpLength (gb_op[data[0]].type);
- if (ilen > len)
- ilen=0;
+ if (ilen > len) {
+ ilen = 0;
+ }
memset (op, '\0', sizeof (RAnalOp));
op->addr = addr;
op->type = R_ANAL_OP_TYPE_UNK;
@@ -1152,13 +1218,16 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
op->type = R_ANAL_OP_TYPE_CJMP;
op->eob = true; //halt migth wait for interrupts
op->fail = addr + ilen;
- if(len > 1)
+ if (len > 1) {
op->jump = addr + gbOpLength (gb_op[data[1]].type) + ilen;
+ }
break;
case 0xcd:
- if ( gb_op_calljump (anal, op, data, addr))
+ if (gb_op_calljump (anal, op, data, addr)) {
op->type = R_ANAL_OP_TYPE_CALL;
- else op->type = R_ANAL_OP_TYPE_UCALL;
+ } else {
+ op->type = R_ANAL_OP_TYPE_UCALL;
+ }
op->fail = addr + ilen;
op->eob = true;
gb_anal_esil_call (op);
@@ -1169,9 +1238,11 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
case 0xd4:
case 0xdc:
gb_anal_cond (anal->reg, op, data[0]);
- if( gb_op_calljump (anal, op, data, addr))
+ if (gb_op_calljump (anal, op, data, addr)) {
op->type = R_ANAL_OP_TYPE_CCALL;
- else op->type = R_ANAL_OP_TYPE_UCCALL;
+ } else {
+ op->type = R_ANAL_OP_TYPE_UCCALL;
+ }
op->fail = addr + ilen;
op->eob = true;
gb_anal_esil_ccall (op, data[0]);
@@ -1267,58 +1338,74 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
switch (data[1]>>3)
{
case 0:
- if ((data[1]&7) == 6)
+ if ((data[1] & 7) == 6) {
op->cycles = 16;
- else op->cycles = 8;
+ } else {
+ op->cycles = 8;
+ }
op->type = R_ANAL_OP_TYPE_ROL;
gb_anal_cb_rlc (anal->reg, op, data[1]);
break;
case 1:
- if ((data[1] & 7) == 6)
+ if ((data[1] & 7) == 6) {
op->cycles = 16;
- else op->cycles = 8;
+ } else {
+ op->cycles = 8;
+ }
op->type = R_ANAL_OP_TYPE_ROR;
gb_anal_cb_rrc (anal->reg, op, data[1]);
break;
case 2:
- if ((data[1]&7) == 6)
+ if ((data[1] & 7) == 6) {
op->cycles = 16;
- else op->cycles = 8;
+ } else {
+ op->cycles = 8;
+ }
op->type = R_ANAL_OP_TYPE_ROL;
gb_anal_cb_rl (anal->reg, op, data[1]);
break;
case 3:
- if ((data[1]&7) == 6)
+ if ((data[1] & 7) == 6) {
op->cycles = 16;
- else op->cycles = 8;
+ } else {
+ op->cycles = 8;
+ }
op->type = R_ANAL_OP_TYPE_ROR;
gb_anal_cb_rr (anal->reg, op, data[1]);
break;
case 4:
- if ((data [1] & 7) == 6)
+ if ((data[1] & 7) == 6) {
op->cycles = 16;
- else op->cycles = 8;
+ } else {
+ op->cycles = 8;
+ }
op->type = R_ANAL_OP_TYPE_SAL;
gb_anal_cb_sla (anal->reg, op, data[1]);
break;
case 6:
- if ((data[1] & 7) == 6)
+ if ((data[1] & 7) == 6) {
op->cycles = 16;
- else op->cycles = 8;
+ } else {
+ op->cycles = 8;
+ }
op->type = R_ANAL_OP_TYPE_ROL;
gb_anal_cb_swap (anal->reg, op, data[1]);
break;
case 5:
- if ((data [1] & 7) == 6)
+ if ((data[1] & 7) == 6) {
op->cycles = 16;
- else op->cycles = 8;
+ } else {
+ op->cycles = 8;
+ }
op->type = R_ANAL_OP_TYPE_SAR;
gb_anal_cb_sra (anal->reg, op, data[1]);
break;
case 7:
- if ((data [1] & 7) == 6)
+ if ((data[1] & 7) == 6) {
op->cycles = 16;
- else op->cycles = 8;
+ } else {
+ op->cycles = 8;
+ }
op->type = R_ANAL_OP_TYPE_SHR;
gb_anal_cb_srl (anal->reg, op, data[1]);
break;
@@ -1330,9 +1417,11 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
case 13:
case 14:
case 15:
- if ((data[1]&7) == 6)
+ if ((data[1] & 7) == 6) {
op->cycles = 12;
- else op->cycles = 8;
+ } else {
+ op->cycles = 8;
+ }
op->type = R_ANAL_OP_TYPE_ACMP;
gb_anal_and_bit (anal->reg, op, data[1]);
break; //bit
@@ -1344,9 +1433,11 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
case 21:
case 22:
case 23:
- if ((data[1]&7) == 6)
+ if ((data[1] & 7) == 6) {
op->cycles = 16;
- else op->cycles = 8;
+ } else {
+ op->cycles = 8;
+ }
gb_anal_and_res (anal, op, data[1]);
op->type = R_ANAL_OP_TYPE_AND;
break; //res
@@ -1358,9 +1449,11 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
case 29:
case 30:
case 31:
- if ((data[1]&7) == 6)
+ if ((data[1] & 7) == 6) {
op->cycles = 16;
- else op->cycles = 8;
+ } else {
+ op->cycles = 8;
+ }
gb_anal_or_set (anal, op, data[1]);
op->type = R_ANAL_OP_TYPE_OR;
break; //set
diff --git a/libr/anal/p/anal_h8300.c b/libr/anal/p/anal_h8300.c
index 34a7e26f52..e034401855 100644
--- a/libr/anal/p/anal_h8300.c
+++ b/libr/anal/p/anal_h8300.c
@@ -86,8 +86,9 @@ static void h8300_anal_jsr(RAnalOp *op, ut64 addr, const ut8 *buf) {
static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) {
int ret = -1;
ut8 opcode = buf[0];
- if (!op)
+ if (!op) {
return 2;
+ }
r_strbuf_init (&op->esil);
r_strbuf_set (&op->esil, "");
switch (opcode >> 4) {
@@ -450,10 +451,11 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) {
rsB(), rsB(), rdB(1));
return 0;
case H8300_BST_BIST: /*TODO*/
- if(! (buf[1] & 0x80) ) //BST
+ if (!(buf[1] & 0x80)) { //BST
r_strbuf_appendf(&op->esil,"%d,C,<<,r%u%c,|=",rs(),rdB(1));
- else //BIST
- r_strbuf_appendf(&op->esil,"%d,C,!,<<,r%u%c,|=",rs(),rdB(1));
+ } else { //BIST
+ r_strbuf_appendf (&op->esil, "%d,C,!,<<,r%u%c,|=", rs (), rdB (1));
+ }
return 0;
case H8300_MOV_R82IND16: /*TODO*/ return 0;
case H8300_MOV_IND162R16: /*TODO*/ return 0;
@@ -482,42 +484,46 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) {
rs(), rs(), rdB(1));
return 0;
case H8300_BOR_BIOR: /*TODO*/
- if(! (buf[1] & 0x80) ) //BOR
+ if (!(buf[1] & 0x80)) { //BOR
//C|=(rd&(1<>imm
r_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,C,|=",
rs(), rs(), rdB(1));
- else //BIOR
+ } else { //BIOR
//C|=!(rd&(1<>imm
- r_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,|=",
- rs(), rs(), rdB(1));
+ r_strbuf_appendf (&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,|=",
+ rs (), rs (), rdB (1));
+ }
return 0;
case H8300_BXOR_BIXOR: /*TODO*/
- if(! (buf[1] & 0x80) ) //BXOR
+ if (!(buf[1] & 0x80)) { //BXOR
//C^=(rd&(1<>imm
r_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,C,^=",
rs(), rs(), rdB(1));
- else //BIXOR
- r_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,^=",
- rs(), rs(), rdB(1));
+ } else { //BIXOR
+ r_strbuf_appendf (&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,^=",
+ rs (), rs (), rdB (1));
+ }
return 0;
case H8300_BAND_BIAND:
/*TODO check functionality*/
//C&=(rd&(1<>imm
- if(! (buf[1] & 0x80) ) //BAND
+ if (!(buf[1] & 0x80)) { //BAND
r_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,C,&=",
rs(), rs(), rdB(1));
- else //BIAND
- r_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,&=",
- rs(), rs(), rdB(1));
+ } else { //BIAND
+ r_strbuf_appendf (&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,&=",
+ rs (), rs (), rdB (1));
+ }
return 0;
case H8300_BILD_IMM2R8:
/*TODO*/
- if(! (buf[1] & 0x80) ) //BLD
+ if (!(buf[1] & 0x80)) { //BLD
r_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,C,=",
rs(), rs(), rdB(1));
- else //BILD
- r_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,=",
- rs(), rs(), rdB(1));
+ } else { //BILD
+ r_strbuf_appendf (&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,=",
+ rs (), rs (), rdB (1));
+ }
return 0;
case H8300_MOV_IMM162R16: /*TODO*/ return 0;
case H8300_EEPMOV: /*TODO*/ return 0;
@@ -539,8 +545,9 @@ static int h8300_op(RAnal *anal, RAnalOp *op, ut64 addr,
ut8 opcode = buf[0];
struct h8300_cmd cmd;
- if (!op)
+ if (!op) {
return 2;
+ }
memset(op, 0, sizeof (RAnalOp));
@@ -549,8 +556,9 @@ static int h8300_op(RAnal *anal, RAnalOp *op, ut64 addr,
op->ptr = op->val = -1;
ret = op->size = h8300_decode_command(buf, &cmd);
- if (ret < 0)
+ if (ret < 0) {
return ret;
+ }
switch (opcode >> 4) {
case H8300_MOV_4BIT_2:
case H8300_MOV_4BIT_3:
diff --git a/libr/anal/p/anal_i4004.c b/libr/anal/p/anal_i4004.c
index f876bbf8f4..7e4392b165 100644
--- a/libr/anal/p/anal_i4004.c
+++ b/libr/anal/p/anal_i4004.c
@@ -91,8 +91,9 @@ static const char *i4004_f[16] = {
static int i4004_get_ins_len (ut8 hex) {
ut8 high = (hex & 0xf0)>>4;
int ret = i4004_ins_len[high];
- if (ret == 3)
+ if (ret == 3) {
ret = (hex & 1) ? 1 : 2;
+ }
return ret;
}
@@ -100,13 +101,17 @@ static int i4004_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len
char basm[128];
const size_t basz = sizeof (basm)-1;
int rlen = i4004_get_ins_len (*buf);
- if (!op) return 2;
+ if (!op) {
+ return 2;
+ }
r_strbuf_init (&op->esil);
ut8 high = (*buf & 0xf0)>>4;
ut8 low = (*buf & 0xf);
basm[0] = 0;
- if (rlen > len) return op->size = 0;
+ if (rlen > len) {
+ return op->size = 0;
+ }
switch (high) {
case 0:
if (low) {
@@ -121,9 +126,11 @@ static int i4004_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len
op->fail = addr + rlen;
break;
case 2:
- if (rlen == 1)
+ if (rlen == 1) {
snprintf (basm, basz, "scr r%d", (low & 0xe));
- else snprintf (basm, basz, "fim r%d, 0x%02x", (low & 0xe), buf[1]);
+ } else {
+ snprintf (basm, basz, "fim r%d, 0x%02x", (low & 0xe), buf[1]);
+ }
break;
case 3:
op->type = R_ANAL_OP_TYPE_MOV;
diff --git a/libr/anal/p/anal_java.c b/libr/anal/p/anal_java.c
index 6dcdb4860a..9b6065ca03 100644
--- a/libr/anal/p/anal_java.c
+++ b/libr/anal/p/anal_java.c
@@ -147,8 +147,9 @@ static int java_recursive_descent(RAnal *anal, RAnalState *state, ut64 addr) {
RAnalBlock *bb;
RAnalBlock *current_head;
- if (!anal || !state || !state->current_bb || state->current_bb_head)
+ if (!anal || !state || !state->current_bb || state->current_bb_head) {
return 0;
+ }
bb = state->current_bb;
current_head = state->current_bb_head;
@@ -171,7 +172,9 @@ static int java_recursive_descent(RAnal *anal, RAnalState *state, ut64 addr) {
// if (bb->type2 & R_ANAL_EX_OBJ_OP) handle_bb_obj_op (anal, state);
// if (bb->type2 & R_ANAL_EX_STACK_OP) handle_bb_stack_op (anal, state);
// if (bb->type2 & R_ANAL_EX_BIN_OP) handle_bb_bin_op (anal, state);
- if (bb->type2 & R_ANAL_EX_CODE_OP) handle_bb_cf_recursive_descent (anal, state);
+ if (bb->type2 & R_ANAL_EX_CODE_OP) {
+ handle_bb_cf_recursive_descent (anal, state);
+ }
// if (bb->type2 & R_ANAL_EX_DATA_OP) handle_bb_data_op (anal, state);
return 0;
}
@@ -196,7 +199,9 @@ static int java_linear_sweep(RAnal *anal, RAnalState *state, ut64 addr) {
// if (bb->type2 & R_ANAL_EX_OBJ_OP) handle_bb_obj_op (anal, state);
// if (bb->type2 & R_ANAL_EX_STACK_OP) handle_bb_stack_op (anal, state);
// if (bb->type2 & R_ANAL_EX_BIN_OP) handle_bb_bin_op (anal, state);
- if (bb->type2 & R_ANAL_EX_CODE_OP) handle_bb_cf_linear_sweep (anal, state);
+ if (bb->type2 & R_ANAL_EX_CODE_OP) {
+ handle_bb_cf_linear_sweep (anal, state);
+ }
// if (bb->type2 & R_ANAL_EX_DATA_OP) handle_bb_data_op (anal, state);
return 0;
}
@@ -234,14 +239,17 @@ static int handle_bb_cf_recursive_descent (RAnal *anal, RAnalState *state) {
// visited some other time
if (!r_anal_state_search_bb (state, bb->jump)) {
jmp_list = r_anal_ex_perform_analysis ( anal, state, bb->jump );
- if (jmp_list)
- bb->jumpbb = (RAnalBlock *) r_list_get_n (jmp_list, 0);
- if (bb->jumpbb)
+ if (jmp_list) {
+ bb->jumpbb = (RAnalBlock *)r_list_get_n (jmp_list, 0);
+ }
+ if (bb->jumpbb) {
bb->jump = bb->jumpbb->addr;
+ }
} else {
bb->jumpbb = r_anal_state_search_bb (state, bb->jump);
- if (bb->jumpbb)
+ if (bb->jumpbb) {
bb->jump = bb->jumpbb->addr;
+ }
}
if (state->done == 1) {
@@ -259,8 +267,9 @@ static int handle_bb_cf_recursive_descent (RAnal *anal, RAnalState *state) {
// visited some other time
if (!r_anal_state_search_bb (state, bb->jump)) {
jmp_list = r_anal_ex_perform_analysis ( anal, state, bb->jump );
- if (jmp_list)
- bb->jumpbb = (RAnalBlock *) r_list_get_n (jmp_list, 0);
+ if (jmp_list) {
+ bb->jumpbb = (RAnalBlock *)r_list_get_n (jmp_list, 0);
+ }
if (bb->jumpbb) {
bb->jump = bb->jumpbb->addr;
}
@@ -277,8 +286,9 @@ static int handle_bb_cf_recursive_descent (RAnal *anal, RAnalState *state) {
if (!r_anal_state_search_bb (state, bb->fail)) {
jmp_list = r_anal_ex_perform_analysis ( anal, state, bb->fail );
- if (jmp_list)
- bb->failbb = (RAnalBlock *) r_list_get_n (jmp_list, 0);
+ if (jmp_list) {
+ bb->failbb = (RAnalBlock *)r_list_get_n (jmp_list, 0);
+ }
if (bb->failbb) {
bb->fail = bb->failbb->addr;
}
@@ -297,7 +307,9 @@ static int handle_bb_cf_recursive_descent (RAnal *anal, RAnalState *state) {
}
result = R_ANAL_RET_END;
- if (encountered_stop) state->done = 1;
+ if (encountered_stop) {
+ state->done = 1;
+ }
}
break;
@@ -313,8 +325,9 @@ static int handle_bb_cf_recursive_descent (RAnal *anal, RAnalState *state) {
if (caseop) {
if (r_anal_state_addr_is_valid (state, caseop->jump) ) {
jmp_list = r_anal_ex_perform_analysis ( anal, state, caseop->jump );
- if (jmp_list)
- caseop->jumpbb = (RAnalBlock *) r_list_get_n (jmp_list, 0);
+ if (jmp_list) {
+ caseop->jumpbb = (RAnalBlock *)r_list_get_n (jmp_list, 0);
+ }
if (state->done == 1) {
IFDBG eprintf (" Looks like this jmp (bb @ 0x%04"PFMT64x") found a return.\n", addr);
state->done = 0;
@@ -324,7 +337,9 @@ static int handle_bb_cf_recursive_descent (RAnal *anal, RAnalState *state) {
}
}
r_list_free (jmp_list);
- if (encountered_stop) state->done = 1;
+ if (encountered_stop) {
+ state->done = 1;
+ }
}
result = R_ANAL_RET_END;
@@ -587,7 +602,9 @@ static int java_analyze_fns_from_buffer( RAnal *anal, ut64 start, ut64 end, int
//analyze_all = 1;
buf_len = anal->iob.desc_size (anal->iob.io->desc);
- if (buf_len == UT64_MAX) buf_len = 1024;
+ if (buf_len == UT64_MAX) {
+ buf_len = 1024;
+ }
end = start + buf_len;
}
@@ -614,7 +631,9 @@ static int java_analyze_fns_from_buffer( RAnal *anal, ut64 start, ut64 end, int
r_anal_fcn_tree_insert (&anal->fcn_tree, fcn);
r_list_append (anal->fcns, fcn);
offset += r_anal_fcn_size (fcn);
- if (!analyze_all) break;
+ if (!analyze_all) {
+ break;
+ }
}
free (buffer);
return result;
@@ -867,7 +886,9 @@ static void java_update_anal_types (RAnal *anal, RBinJavaObj *bin_obj) {
if (the_list) {
r_list_foreach (the_list, iter, str) {
IFDBG eprintf ("Adding type: %s to known types.\n", str);
- if (str) sdb_set (D, str, "type", 0);
+ if (str) {
+ sdb_set (D, str, "type", 0);
+ }
}
}
r_list_free (the_list);
diff --git a/libr/anal/p/anal_m68k_cs.c b/libr/anal/p/anal_m68k_cs.c
index fb0e8debd0..3199361947 100644
--- a/libr/anal/p/anal_m68k_cs.c
+++ b/libr/anal/p/anal_m68k_cs.c
@@ -145,22 +145,30 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
// XXX no arch->cpu ?!?! CS_MODE_MICRO, N64
op->delay = 0;
// replace this with the asm.features?
- if (a->cpu && strstr (a->cpu, "68000"))
+ if (a->cpu && strstr (a->cpu, "68000")) {
mode |= CS_MODE_M68K_000;
- if (a->cpu && strstr (a->cpu, "68010"))
+ }
+ if (a->cpu && strstr (a->cpu, "68010")) {
mode |= CS_MODE_M68K_010;
- if (a->cpu && strstr (a->cpu, "68020"))
+ }
+ if (a->cpu && strstr (a->cpu, "68020")) {
mode |= CS_MODE_M68K_020;
- if (a->cpu && strstr (a->cpu, "68030"))
+ }
+ if (a->cpu && strstr (a->cpu, "68030")) {
mode |= CS_MODE_M68K_030;
- if (a->cpu && strstr (a->cpu, "68040"))
+ }
+ if (a->cpu && strstr (a->cpu, "68040")) {
mode |= CS_MODE_M68K_040;
- if (a->cpu && strstr (a->cpu, "68060"))
+ }
+ if (a->cpu && strstr (a->cpu, "68060")) {
mode |= CS_MODE_M68K_060;
+ }
op->size = 4;
if (handle == 0) {
ret = cs_open (CS_ARCH_M68K, mode, &handle);
- if (ret != CS_ERR_OK) goto fin;
+ if (ret != CS_ERR_OK) {
+ goto fin;
+ }
cs_option (handle, CS_OPT_DETAIL, CS_OPT_ON);
}
n = cs_disasm (handle, (ut8*)buf, len, addr, 1, &insn);
diff --git a/libr/anal/p/anal_mips_cs.c b/libr/anal/p/anal_mips_cs.c
index 7ef3b54af7..66ef3d6301 100644
--- a/libr/anal/p/anal_mips_cs.c
+++ b/libr/anal/p/anal_mips_cs.c
@@ -190,209 +190,208 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len
}
}
- if (insn)
- switch (insn->id) {
- case MIPS_INS_NOP:
- r_strbuf_setf (&op->esil, ",");
- break;
- case MIPS_INS_BREAK:
- r_strbuf_setf (&op->esil, "%d,%d,TRAP", IMM (0), IMM (0));
- break;
- case MIPS_INS_SD:
- r_strbuf_appendf (&op->esil, "%s,%s,=[8]",
- ARG (0), ARG (1));
- break;
- case MIPS_INS_SW:
- case MIPS_INS_SWL:
- case MIPS_INS_SWR:
- r_strbuf_appendf (&op->esil, "%s,%s,=[4]",
- ARG (0), ARG (1));
- break;
- case MIPS_INS_SH:
- r_strbuf_appendf (&op->esil, "%s,%s,=[2]",
- ARG (0), ARG (1));
- break;
- case MIPS_INS_SWC1:
- case MIPS_INS_SWC2:
- r_strbuf_setf (&op->esil, "%s,$", ARG (1));
- break;
- case MIPS_INS_SB:
- r_strbuf_appendf (&op->esil, "%s,%s,=[1]",
- ARG (0), ARG (1));
- break;
- case MIPS_INS_CMP:
- case MIPS_INS_CMPU:
- case MIPS_INS_CMPGU:
- case MIPS_INS_CMPGDU:
- case MIPS_INS_CMPI:
- r_strbuf_appendf (&op->esil, "%s,%s,==", ARG (1), ARG (0));
- break;
- case MIPS_INS_SHRAV:
- case MIPS_INS_SHRAV_R:
- case MIPS_INS_SHRA:
- case MIPS_INS_SHRA_R:
- case MIPS_INS_SRA:
- r_strbuf_appendf (&op->esil, "%s,%s,>>,31,%s,>>,?{,32,%s,-,%s,1,<<,1,-,<<,}{,0,},|,%s,=,",
- ARG (2), ARG (1), ARG (1), ARG (2), ARG (2), ARG (0));
- break;
- case MIPS_INS_SHRL:
- // suffix 'S' forces conditional flag to be updated
- case MIPS_INS_SRLV:
- case MIPS_INS_SRL:
- r_strbuf_appendf (&op->esil, "%s,%s,>>,%s,=", ARG (2), ARG (1), ARG (0));
- break;
- case MIPS_INS_SLLV:
- case MIPS_INS_SLL:
- r_strbuf_appendf (&op->esil, "%s,%s,<<,%s,=", ARG (2), ARG (1), ARG (0));
- break;
- case MIPS_INS_BAL:
- case MIPS_INS_JAL:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_D ("%s"), ARG (0));
- break;
- case MIPS_INS_JALR:
- case MIPS_INS_JALRS:
- if (OPCOUNT () < 2) {
+ if (insn) {
+ switch (insn->id) {
+ case MIPS_INS_NOP:
+ r_strbuf_setf (&op->esil, ",");
+ break;
+ case MIPS_INS_BREAK:
+ r_strbuf_setf (&op->esil, "%d,%d,TRAP", IMM (0), IMM (0));
+ break;
+ case MIPS_INS_SD:
+ r_strbuf_appendf (&op->esil, "%s,%s,=[8]",
+ ARG (0), ARG (1));
+ break;
+ case MIPS_INS_SW:
+ case MIPS_INS_SWL:
+ case MIPS_INS_SWR:
+ r_strbuf_appendf (&op->esil, "%s,%s,=[4]",
+ ARG (0), ARG (1));
+ break;
+ case MIPS_INS_SH:
+ r_strbuf_appendf (&op->esil, "%s,%s,=[2]",
+ ARG (0), ARG (1));
+ break;
+ case MIPS_INS_SWC1:
+ case MIPS_INS_SWC2:
+ r_strbuf_setf (&op->esil, "%s,$", ARG (1));
+ break;
+ case MIPS_INS_SB:
+ r_strbuf_appendf (&op->esil, "%s,%s,=[1]",
+ ARG (0), ARG (1));
+ break;
+ case MIPS_INS_CMP:
+ case MIPS_INS_CMPU:
+ case MIPS_INS_CMPGU:
+ case MIPS_INS_CMPGDU:
+ case MIPS_INS_CMPI:
+ r_strbuf_appendf (&op->esil, "%s,%s,==", ARG (1), ARG (0));
+ break;
+ case MIPS_INS_SHRAV:
+ case MIPS_INS_SHRAV_R:
+ case MIPS_INS_SHRA:
+ case MIPS_INS_SHRA_R:
+ case MIPS_INS_SRA:
+ r_strbuf_appendf (&op->esil, "%s,%s,>>,31,%s,>>,?{,32,%s,-,%s,1,<<,1,-,<<,}{,0,},|,%s,=,",
+ ARG (2), ARG (1), ARG (1), ARG (2), ARG (2), ARG (0));
+ break;
+ case MIPS_INS_SHRL:
+ // suffix 'S' forces conditional flag to be updated
+ case MIPS_INS_SRLV:
+ case MIPS_INS_SRL:
+ r_strbuf_appendf (&op->esil, "%s,%s,>>,%s,=", ARG (2), ARG (1), ARG (0));
+ break;
+ case MIPS_INS_SLLV:
+ case MIPS_INS_SLL:
+ r_strbuf_appendf (&op->esil, "%s,%s,<<,%s,=", ARG (2), ARG (1), ARG (0));
+ break;
+ case MIPS_INS_BAL:
+ case MIPS_INS_JAL:
r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_D ("%s"), ARG (0));
- } else {
- PROTECT_ZERO () {
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_DR ("%s","%s"), ARG (0), ARG (1));
+ break;
+ case MIPS_INS_JALR:
+ case MIPS_INS_JALRS:
+ if (OPCOUNT () < 2) {
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_D ("%s"), ARG (0));
+ } else {
+ PROTECT_ZERO () {
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_DR ("%s", "%s"), ARG (0), ARG (1));
+ }
}
- }
- break;
- case MIPS_INS_JALRC: // no delay
- if (OPCOUNT () < 2) {
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_ND ("%s"), ARG (0));
- } else {
- PROTECT_ZERO () {
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_NDR ("%s","%s"), ARG (0), ARG (1));
+ break;
+ case MIPS_INS_JALRC: // no delay
+ if (OPCOUNT () < 2) {
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_ND ("%s"), ARG (0));
+ } else {
+ PROTECT_ZERO () {
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_NDR ("%s", "%s"), ARG (0), ARG (1));
+ }
}
- }
- break;
- case MIPS_INS_JRADDIUSP:
- // increment stackpointer in X and jump to %ra
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%d,sp,+=,"ES_J ("ra"), ARG (0));
- break;
- case MIPS_INS_JR:
- case MIPS_INS_JRC:
- case MIPS_INS_J:
- case MIPS_INS_B: // ???
- // jump to address with conditional
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_J ("%s"), ARG (0));
- break;
- case MIPS_INS_BNE: // bne $s, $t, offset
- case MIPS_INS_BNEL:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,%s,==,$z,!,?{,"ES_J ("%s")",}",
- ARG (0), ARG (1), ARG (2));
- break;
- case MIPS_INS_BEQ:
- case MIPS_INS_BEQL:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,%s,==,$z,?{,"ES_J ("%s")",}",
- ARG (0), ARG (1), ARG (2));
- break;
- case MIPS_INS_BZ:
- case MIPS_INS_BEQZ:
- case MIPS_INS_BEQZC:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,0,==,$z,?{,"ES_J ("%s")",}",
- ARG (0), ARG (1));
- break;
- case MIPS_INS_BNEZ:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,0,==,$z,!,?{,"ES_J ("%s")",}",
- ARG (0), ARG (1));
- break;
- case MIPS_INS_BEQZALC:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,0,==,$z,?{,"ES_CALL_ND ("%s")",}",
- ARG (0), ARG (1));
- break;
- case MIPS_INS_BLEZ:
- case MIPS_INS_BLEZC:
- case MIPS_INS_BLEZL:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,%s,==,$z,?{,"ES_J ("%s")",BREAK,},",
- ARG (0), ARG (1));
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "1,"ES_IS_NEGATIVE ("%s")",==,$z,?{,"ES_J ("%s")",}",
- ARG (0), ARG (1));
- break;
- case MIPS_INS_BGEZ:
- case MIPS_INS_BGEZC:
- case MIPS_INS_BGEZL:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,"ES_IS_NEGATIVE ("%s")",==,$z,?{,"ES_J ("%s")",}",
- ARG (0), ARG (1));
- break;
- case MIPS_INS_BGEZAL:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,"ES_IS_NEGATIVE ("%s")",==,$z,?{,"ES_CALL_D ("%s")",}",
- ARG (0), ARG (1));
- break;
- case MIPS_INS_BGEZALC:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,"ES_IS_NEGATIVE ("%s")",==,$z,?{,"ES_CALL_ND ("%s")",}",
- ARG (0), ARG (1));
- break;
- case MIPS_INS_BGTZALC:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,%s,==,$z,?{,BREAK,},", ARG(0));
- r_strbuf_appendf (&op->esil, "0,"ES_IS_NEGATIVE ("%s")",==,$z,?{,"ES_CALL_ND ("%s")",}",
- ARG (0), ARG (1));
- break;
- case MIPS_INS_BLTZAL:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "1,"ES_IS_NEGATIVE ("%s")",==,$z,?{,"ES_CALL_D ("%s")",}", ARG(0), ARG(1));
- break;
- case MIPS_INS_BLTZ:
- case MIPS_INS_BLTZC:
- case MIPS_INS_BLTZL:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "1,"ES_IS_NEGATIVE ("%s")",==,$z,?{,"ES_J ("%s")",}",
- ARG (0), ARG (1));
- break;
- case MIPS_INS_BGTZ:
- case MIPS_INS_BGTZC:
- case MIPS_INS_BGTZL:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,%s,==,$z,?{,BREAK,},", ARG (0));
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,"ES_IS_NEGATIVE ("%s")",==,$z,?{,"ES_J("%s")",}",
- ARG (0), ARG (1));
- break;
- case MIPS_INS_BTEQZ:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,t,==,$z,?{,"ES_J ("%s")",}", ARG (0));
- break;
- case MIPS_INS_BTNEZ:
- r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,t,==,$z,!,?{,"ES_J ("%s")",}", ARG (0));
- break;
- case MIPS_INS_MOV:
- case MIPS_INS_MOVE:
- PROTECT_ZERO () {
- r_strbuf_appendf (&op->esil, "%s,%s,=", ARG (1), REG (0));
- }
- break;
- case MIPS_INS_MOVZ:
- case MIPS_INS_MOVF:
- PROTECT_ZERO () {
- r_strbuf_appendf (&op->esil, "0,%s,==,$z,?{,%s,%s,=,}",
- ARG (2), ARG (1), REG (0));
- }
- break;
- case MIPS_INS_MOVT:
- PROTECT_ZERO () {
- r_strbuf_appendf (&op->esil, "1,%s,==,$z,?{,%s,%s,=,}",
- ARG (2), ARG (1), REG (0));
- }
- break;
- case MIPS_INS_FSUB:
- case MIPS_INS_SUB:
- case MIPS_INS_SUBU:
- case MIPS_INS_DSUB:
- case MIPS_INS_DSUBU:
- PROTECT_ZERO () {
- r_strbuf_appendf(&op->esil, "%s,%s,-,%s,=",
- ARG (2), ARG (1), ARG (0));
- }
- break;
- case MIPS_INS_NEG:
- case MIPS_INS_NEGU:
- r_strbuf_appendf (&op->esil, "%s,0,-,%s,=,",
- ARG (1), ARG (0));
- break;
+ break;
+ case MIPS_INS_JRADDIUSP:
+ // increment stackpointer in X and jump to %ra
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%d,sp,+=," ES_J ("ra"), ARG (0));
+ break;
+ case MIPS_INS_JR:
+ case MIPS_INS_JRC:
+ case MIPS_INS_J:
+ case MIPS_INS_B: // ???
+ // jump to address with conditional
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_J ("%s"), ARG (0));
+ break;
+ case MIPS_INS_BNE: // bne $s, $t, offset
+ case MIPS_INS_BNEL:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,%s,==,$z,!,?{," ES_J ("%s") ",}",
+ ARG (0), ARG (1), ARG (2));
+ break;
+ case MIPS_INS_BEQ:
+ case MIPS_INS_BEQL:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,%s,==,$z,?{," ES_J ("%s") ",}",
+ ARG (0), ARG (1), ARG (2));
+ break;
+ case MIPS_INS_BZ:
+ case MIPS_INS_BEQZ:
+ case MIPS_INS_BEQZC:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,0,==,$z,?{," ES_J ("%s") ",}",
+ ARG (0), ARG (1));
+ break;
+ case MIPS_INS_BNEZ:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,0,==,$z,!,?{," ES_J ("%s") ",}",
+ ARG (0), ARG (1));
+ break;
+ case MIPS_INS_BEQZALC:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,0,==,$z,?{," ES_CALL_ND ("%s") ",}",
+ ARG (0), ARG (1));
+ break;
+ case MIPS_INS_BLEZ:
+ case MIPS_INS_BLEZC:
+ case MIPS_INS_BLEZL:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,%s,==,$z,?{," ES_J ("%s") ",BREAK,},",
+ ARG (0), ARG (1));
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "1," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_J ("%s") ",}",
+ ARG (0), ARG (1));
+ break;
+ case MIPS_INS_BGEZ:
+ case MIPS_INS_BGEZC:
+ case MIPS_INS_BGEZL:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_J ("%s") ",}",
+ ARG (0), ARG (1));
+ break;
+ case MIPS_INS_BGEZAL:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_CALL_D ("%s") ",}",
+ ARG (0), ARG (1));
+ break;
+ case MIPS_INS_BGEZALC:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_CALL_ND ("%s") ",}",
+ ARG (0), ARG (1));
+ break;
+ case MIPS_INS_BGTZALC:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,%s,==,$z,?{,BREAK,},", ARG (0));
+ r_strbuf_appendf (&op->esil, "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_CALL_ND ("%s") ",}",
+ ARG (0), ARG (1));
+ break;
+ case MIPS_INS_BLTZAL:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "1," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_CALL_D ("%s") ",}", ARG (0), ARG (1));
+ break;
+ case MIPS_INS_BLTZ:
+ case MIPS_INS_BLTZC:
+ case MIPS_INS_BLTZL:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "1," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_J ("%s") ",}",
+ ARG (0), ARG (1));
+ break;
+ case MIPS_INS_BGTZ:
+ case MIPS_INS_BGTZC:
+ case MIPS_INS_BGTZL:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,%s,==,$z,?{,BREAK,},", ARG (0));
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_J ("%s") ",}",
+ ARG (0), ARG (1));
+ break;
+ case MIPS_INS_BTEQZ:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,t,==,$z,?{," ES_J ("%s") ",}", ARG (0));
+ break;
+ case MIPS_INS_BTNEZ:
+ r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,t,==,$z,!,?{," ES_J ("%s") ",}", ARG (0));
+ break;
+ case MIPS_INS_MOV:
+ case MIPS_INS_MOVE:
+ PROTECT_ZERO () {
+ r_strbuf_appendf (&op->esil, "%s,%s,=", ARG (1), REG (0));
+ }
+ break;
+ case MIPS_INS_MOVZ:
+ case MIPS_INS_MOVF:
+ PROTECT_ZERO () {
+ r_strbuf_appendf (&op->esil, "0,%s,==,$z,?{,%s,%s,=,}",
+ ARG (2), ARG (1), REG (0));
+ }
+ break;
+ case MIPS_INS_MOVT:
+ PROTECT_ZERO () {
+ r_strbuf_appendf (&op->esil, "1,%s,==,$z,?{,%s,%s,=,}",
+ ARG (2), ARG (1), REG (0));
+ }
+ break;
+ case MIPS_INS_FSUB:
+ case MIPS_INS_SUB:
+ case MIPS_INS_SUBU:
+ case MIPS_INS_DSUB:
+ case MIPS_INS_DSUBU:
+ PROTECT_ZERO () {
+ r_strbuf_appendf (&op->esil, "%s,%s,-,%s,=",
+ ARG (2), ARG (1), ARG (0));
+ }
+ break;
+ case MIPS_INS_NEG:
+ case MIPS_INS_NEGU:
+ r_strbuf_appendf (&op->esil, "%s,0,-,%s,=,",
+ ARG (1), ARG (0));
+ break;
- /** signed -- sets overflow flag */
- case MIPS_INS_ADD:
- {
- PROTECT_ZERO () {
- r_strbuf_appendf(&op->esil, "%s,%s,+,%s,=",
- ARG (1), ARG (2), ARG (0));
+ /** signed -- sets overflow flag */
+ case MIPS_INS_ADD: {
+ PROTECT_ZERO () {
+ r_strbuf_appendf (&op->esil, "%s,%s,+,%s,=",
+ ARG (1), ARG (2), ARG (0));
#if 0
r_strbuf_appendf (&op->esil,
"0,32,%s,%s,+,>>,>,?{,1,TRAP,}{,%s,%s,+,%s,=,}",
@@ -584,6 +583,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len
default:
return -1;
}
+ }
return 0;
}
@@ -701,17 +701,21 @@ static int analop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len)
// XXX no arch->cpu ?!?! CS_MODE_MICRO, N64
op->delay = 0;
op->type = R_ANAL_OP_TYPE_ILL;
- if (len<4)
+ if (len < 4) {
return -1;
+ }
op->size = 4;
if (hndl == 0) {
ret = cs_open (CS_ARCH_MIPS, mode, &hndl);
- if (ret != CS_ERR_OK) goto fin;
+ if (ret != CS_ERR_OK) {
+ goto fin;
+ }
cs_option (hndl, CS_OPT_DETAIL, CS_OPT_ON);
}
n = cs_disasm (hndl, (ut8*)buf, len, addr, 1, &insn);
- if (n<1 || insn->size<1)
+ if (n < 1 || insn->size < 1) {
goto beach;
+ }
op->type = R_ANAL_OP_TYPE_NULL;
op->delay = 0;
op->jump = UT64_MAX;
@@ -997,8 +1001,9 @@ static int analop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len)
beach:
set_opdir (op);
if (anal->decode) {
- if (analop_esil (anal, op, addr, buf, len, &hndl, insn) != 0)
+ if (analop_esil (anal, op, addr, buf, len, &hndl, insn) != 0) {
r_strbuf_fini (&op->esil);
+ }
}
if (anal->fillval) {
op_fillval (anal, op, &hndl, insn);
diff --git a/libr/anal/p/anal_mips_gnu.c b/libr/anal/p/anal_mips_gnu.c
index 957536b0b7..8b6a9697e4 100644
--- a/libr/anal/p/anal_mips_gnu.c
+++ b/libr/anal/p/anal_mips_gnu.c
@@ -15,7 +15,9 @@ static const char* mips_reg_decode(unsigned reg_num) {
"s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
"t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra"
};
- if (reg_num < 32) return REGISTERS[reg_num];
+ if (reg_num < 32) {
+ return REGISTERS[reg_num];
+ }
return NULL;
}
@@ -24,8 +26,9 @@ static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len) {
// WIP char buf[10]; int reg; int family;
int optype, oplen = (anal->bits==16)?2:4;
- if (!op)
+ if (!op) {
return oplen;
+ }
memset (op, 0, sizeof (RAnalOp));
op->type = R_ANAL_OP_TYPE_UNK;
@@ -242,8 +245,9 @@ static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len) {
int rs = ((b[0]&3)<<3)+(b[1]>>5);
int rt = b[1]&31;
int imm = (b[2]<<8)+b[3];
- if (((optype >> 2) ^ 0x3) && (imm & 0x8000))
+ if (((optype >> 2) ^ 0x3) && (imm & 0x8000)) {
imm = 0 - (0x10000 - imm);
+ }
switch (optype) {
case 1: // if (rt) { /* bgez */ } else { /* bltz */ }
case 4: // beq
diff --git a/libr/anal/p/anal_nios2.c b/libr/anal/p/anal_nios2.c
index 4279500a91..4eacf48278 100644
--- a/libr/anal/p/anal_nios2.c
+++ b/libr/anal/p/anal_nios2.c
@@ -7,8 +7,9 @@
#include
static int nios2_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len) {
- if (!op)
+ if (!op) {
return 1;
+ }
/* Ayeeee! What's inside op? Do we have an initialized RAnalOp? Are we going to have a leak here? :-( */
memset (op, 0, sizeof (RAnalOp)); /* We need to refactorize this. Something like r_anal_op_init would be more appropiate */
r_strbuf_init (&op->esil);
@@ -36,54 +37,54 @@ static int nios2_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len)
// blt, r19, r5, 0x8023480
op->type = R_ANAL_OP_TYPE_LOAD;
// TODO: address
- } else
- switch (b[0]) {
- case 0x3a:
- if (b[1]>=0xa0 && b[1]<=0xaf && b[3]==0x3d) {
- op->type = R_ANAL_OP_TYPE_TRAP;
- } else
- if ((b[1]>=0xe0&&b[1]<=0xe7) && b[2]==0x3e && !b[3]) {
- // nextpc ra
- op->type = R_ANAL_OP_TYPE_RET;
+ } else {
+ switch (b[0]) {
+ case 0x3a:
+ if (b[1] >= 0xa0 && b[1] <= 0xaf && b[3] == 0x3d) {
+ op->type = R_ANAL_OP_TYPE_TRAP;
+ } else if ((b[1] >= 0xe0 && b[1] <= 0xe7) && b[2] == 0x3e && !b[3]) {
+ // nextpc ra
+ op->type = R_ANAL_OP_TYPE_RET;
+ }
+ break;
+ case 0x01:
+ // jmpi
+ op->type = R_ANAL_OP_TYPE_JMP;
+ break;
+ case 0x00:
+ case 0x20:
+ case 0x40:
+ case 0x80:
+ case 0xc0:
+ //
+ op->type = R_ANAL_OP_TYPE_CALL;
+ break;
+ case 0x26:
+ // beq
+ break;
+ case 0x07:
+ case 0x47:
+ case 0x87:
+ case 0xc7:
+ // ldb
+ op->type = R_ANAL_OP_TYPE_LOAD;
+ break;
+ case 0x0d:
+ case 0x2d:
+ case 0x4d:
+ case 0x8d:
+ case 0xcd:
+ // sth && sthio
+ op->type = R_ANAL_OP_TYPE_LOAD;
+ break;
+ case 0x06:
+ case 0x46:
+ case 0x86:
+ case 0xc6:
+ // br
+ op->type = R_ANAL_OP_TYPE_CALL;
+ break;
}
- break;
- case 0x01:
- // jmpi
- op->type = R_ANAL_OP_TYPE_JMP;
- break;
- case 0x00:
- case 0x20:
- case 0x40:
- case 0x80:
- case 0xc0:
- //
- op->type = R_ANAL_OP_TYPE_CALL;
- break;
- case 0x26:
- // beq
- break;
- case 0x07:
- case 0x47:
- case 0x87:
- case 0xc7:
- // ldb
- op->type = R_ANAL_OP_TYPE_LOAD;
- break;
- case 0x0d:
- case 0x2d:
- case 0x4d:
- case 0x8d:
- case 0xcd:
- // sth && sthio
- op->type = R_ANAL_OP_TYPE_LOAD;
- break;
- case 0x06:
- case 0x46:
- case 0x86:
- case 0xc6:
- // br
- op->type = R_ANAL_OP_TYPE_CALL;
- break;
}
return op->size;
}
diff --git a/libr/anal/p/anal_pic.c b/libr/anal/p/anal_pic.c
index ff9c8058f0..0f1c13e475 100644
--- a/libr/anal/p/anal_pic.c
+++ b/libr/anal/p/anal_pic.c
@@ -738,10 +738,12 @@ static int anal_pic_pic18_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf
ut16 b = *(ut16 *)buf;
switch (b >> 9) {
case 0x76: //call
- if (len < 4)
+ if (len < 4) {
goto beach;
- if (*(ut32 *)buf >> 28 != 0xf)
+ }
+ if (*(ut32 *)buf >> 28 != 0xf) {
goto beach;
+ }
op->size = 4;
op->type = R_ANAL_OP_TYPE_CALL;
return op->size;
@@ -764,10 +766,12 @@ static int anal_pic_pic18_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf
r_strbuf_setf (&op->esil, ",");
return op->size;
case 0xc: //movff
- if (len < 4)
+ if (len < 4) {
goto beach;
- if (*(ut32 *)buf >> 28 != 0xf)
+ }
+ if (*(ut32 *)buf >> 28 != 0xf) {
goto beach;
+ }
op->size = 4;
op->type = R_ANAL_OP_TYPE_MOV;
return op->size;
@@ -808,10 +812,12 @@ static int anal_pic_pic18_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf
pic18_cond_branch (op, addr, buf, "c");
return op->size;
case 0xef: //goto
- if (len < 4)
+ if (len < 4) {
goto beach;
- if (*(ut32 *)buf >> 28 != 0xf)
+ }
+ if (*(ut32 *)buf >> 28 != 0xf) {
goto beach;
+ }
op->size = 4;
op->cycles = 2;
ut32 dword_instr = *(ut32 *)buf;
@@ -865,10 +871,12 @@ static int anal_pic_pic18_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf
switch (b >> 6) { //LFSR
case 0x3b8: //lfsr
- if (len < 4)
+ if (len < 4) {
goto beach;
- if (*(ut32 *)buf >> 28 != 0xf)
+ }
+ if (*(ut32 *)buf >> 28 != 0xf) {
goto beach;
+ }
op->size = 4;
op->type = R_ANAL_OP_TYPE_LOAD;
return op->size;
diff --git a/libr/anal/p/anal_ppc_cs.c b/libr/anal/p/anal_ppc_cs.c
index ae357fb332..79738969af 100644
--- a/libr/anal/p/anal_ppc_cs.c
+++ b/libr/anal/p/anal_ppc_cs.c
@@ -43,8 +43,12 @@ static const char* cmask64(const char *mb_c, const char *me_c) {
static char cmask[32];
ut64 mb = 0;
ut64 me = 0;
- if (mb_c) mb = strtol (mb_c, NULL, 16);
- if (me_c) me = strtol (me_c, NULL, 16);
+ if (mb_c) {
+ mb = strtol (mb_c, NULL, 16);
+ }
+ if (me_c) {
+ me = strtol (me_c, NULL, 16);
+ }
snprintf (cmask, sizeof (cmask), "0x%"PFMT64x"", mask64 (mb, me));
return cmask;
}
@@ -53,8 +57,12 @@ static const char* cmask32(const char *mb_c, const char *me_c) {
static char cmask[32];
ut32 mb = 0;
ut32 me = 0;
- if (mb_c) mb = strtol (mb_c, NULL, 16);
- if (me_c) me = strtol (me_c, NULL, 16);
+ if (mb_c) {
+ mb = strtol (mb_c, NULL, 16);
+ }
+ if (me_c) {
+ me = strtol (me_c, NULL, 16);
+ }
snprintf (cmask, sizeof (cmask), "0x%"PFMT32x"", mask32 (mb, me));
return cmask;
}
@@ -595,8 +603,11 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
case PPC_INS_CMPWI:
op->type = R_ANAL_OP_TYPE_CMP;
op->sign = true;
- if (ARG (2)[0] == '\0') esilprintf (op, "%s,%s,-,0xff,&,cr0,=", ARG (1), ARG (0));
- else esilprintf (op, "%s,%s,-,0xff,&,%s,=", ARG (2), ARG (1), ARG (0));
+ if (ARG (2)[0] == '\0') {
+ esilprintf (op, "%s,%s,-,0xff,&,cr0,=", ARG (1), ARG (0));
+ } else {
+ esilprintf (op, "%s,%s,-,0xff,&,%s,=", ARG (2), ARG (1), ARG (0));
+ }
break;
case PPC_INS_MFLR:
op->type = R_ANAL_OP_TYPE_MOV;
@@ -630,13 +641,19 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
case PPC_INS_EXTSB:
op->sign = true;
op->type = R_ANAL_OP_TYPE_MOV;
- if (a->bits == 64) esilprintf (op, "%s,0x80,&,?{,0xFFFFFFFFFFFFFF00,%s,|,%s,=,}", ARG (1), ARG (1), ARG (0));
- else esilprintf (op, "%s,0x80,&,?{,0xFFFFFF00,%s,|,%s,=,}", ARG (1), ARG (1), ARG (0));
+ if (a->bits == 64) {
+ esilprintf (op, "%s,0x80,&,?{,0xFFFFFFFFFFFFFF00,%s,|,%s,=,}", ARG (1), ARG (1), ARG (0));
+ } else {
+ esilprintf (op, "%s,0x80,&,?{,0xFFFFFF00,%s,|,%s,=,}", ARG (1), ARG (1), ARG (0));
+ }
break;
case PPC_INS_EXTSH:
op->sign = true;
- if (a->bits == 64) esilprintf (op, "%s,0x8000,&,?{,0xFFFFFFFFFFFF0000,%s,|,%s,=,}", ARG (1), ARG (1), ARG (0));
- else esilprintf (op, "%s,0x8000,&,?{,0xFFFF0000,%s,|,%s,=,}", ARG (1), ARG (1), ARG (0));
+ if (a->bits == 64) {
+ esilprintf (op, "%s,0x8000,&,?{,0xFFFFFFFFFFFF0000,%s,|,%s,=,}", ARG (1), ARG (1), ARG (0));
+ } else {
+ esilprintf (op, "%s,0x8000,&,?{,0xFFFF0000,%s,|,%s,=,}", ARG (1), ARG (1), ARG (0));
+ }
break;
case PPC_INS_EXTSW:
op->sign = true;
diff --git a/libr/anal/p/anal_ppc_gnu.c b/libr/anal/p/anal_ppc_gnu.c
index 52c2caac7d..0771c84012 100644
--- a/libr/anal/p/anal_ppc_gnu.c
+++ b/libr/anal/p/anal_ppc_gnu.c
@@ -34,7 +34,9 @@ static int ppc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len
// bctr
} else {
op->jump = (aa)?(baddr):(addr+baddr);
- if (lk) op->fail = addr+4;
+ if (lk) {
+ op->fail = addr + 4;
+ }
}
op->eob = 1;
break;
diff --git a/libr/anal/p/anal_riscv.c b/libr/anal/p/anal_riscv.c
index c138eb1662..370e912323 100644
--- a/libr/anal/p/anal_riscv.c
+++ b/libr/anal/p/anal_riscv.c
@@ -17,7 +17,9 @@ static bool _is_any(const char *str, ...) {
va_start (va, str);
while (true) {
cur = va_arg (va, char *);
- if (!cur) break;
+ if (!cur) {
+ break;
+ }
if (!strcmp (str, cur)) {
va_end (va);
return true;
@@ -72,13 +74,18 @@ static int riscv_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
op->type = R_ANAL_OP_TYPE_ILL;
return -1;
}
- if (!o || !o->name) return op->size;
+ if (!o || !o->name) {
+ return op->size;
+ }
for (; o < &riscv_opcodes[NUMOPCODES]; o++) {
// XXX ASAN segfault if ( !(o->match_func)(o, word) ) continue;
- if ( no_alias && (o->pinfo & INSN_ALIAS) ) continue;
- if ( isdigit ((int)(o->subset[0])) && atoi (o->subset) != xlen) continue;
- else {
+ if (no_alias && (o->pinfo & INSN_ALIAS)) {
+ continue;
+ }
+ if (isdigit ((int)(o->subset[0])) && atoi (o->subset) != xlen) {
+ continue;
+ } else {
break;
}
}
diff --git a/libr/anal/p/anal_snes.c b/libr/anal/p/anal_snes.c
index 9d62141947..4efda6768b 100644
--- a/libr/anal/p/anal_snes.c
+++ b/libr/anal/p/anal_snes.c
@@ -13,8 +13,9 @@ static struct snes_asm_flags* snesflags = NULL;
static int snes_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) {
memset (op, '\0', sizeof (RAnalOp));
op->size = snes_op_get_size(snesflags->M, snesflags->X, &snes_op[data[0]]);
- if (op->size > len)
+ if (op->size > len) {
return op->size = 0;
+ }
op->nopcode = 1;
op->addr = addr;
op->type = R_ANAL_OP_TYPE_UNK;
@@ -219,19 +220,29 @@ static int snes_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int l
op->type = R_ANAL_OP_TYPE_RET;
break;
case 0xc2: // rep
- if ( ((st8)data[1]) & 0x10 ) snesflags->X = 0;
- if ( ((st8)data[1]) & 0x20 ) snesflags->M = 0;
+ if (((st8)data[1]) & 0x10) {
+ snesflags->X = 0;
+ }
+ if (((st8)data[1]) & 0x20) {
+ snesflags->M = 0;
+ }
break;
case 0xe2: // sep
- if ( ((st8)data[1]) & 0x10 ) snesflags->X = 1;
- if ( ((st8)data[1]) & 0x20 ) snesflags->M = 1;
+ if (((st8)data[1]) & 0x10) {
+ snesflags->X = 1;
+ }
+ if (((st8)data[1]) & 0x20) {
+ snesflags->M = 1;
+ }
break;
}
return op->size;
}
static int snes_anal_init (void* user) {
- if (!snesflags) snesflags = malloc(sizeof( struct snes_asm_flags ));
+ if (!snesflags) {
+ snesflags = malloc (sizeof (struct snes_asm_flags));
+ }
memset(snesflags,0,sizeof (struct snes_asm_flags));
return 0;
}
diff --git a/libr/anal/p/anal_sparc_cs.c b/libr/anal/p/anal_sparc_cs.c
index 558e9581ac..aa635c614c 100644
--- a/libr/anal/p/anal_sparc_cs.c
+++ b/libr/anal/p/anal_sparc_cs.c
@@ -105,8 +105,9 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
}
mode = CS_MODE_LITTLE_ENDIAN;
- if (!strcmp (a->cpu, "v9"))
+ if (!strcmp (a->cpu, "v9")) {
mode |= CS_MODE_V9;
+ }
if (mode != omode) {
cs_close (&handle);
handle = 0;
@@ -211,17 +212,21 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
switch (INSOP(0).type) {
case SPARC_OP_REG:
op->type = R_ANAL_OP_TYPE_CJMP;
- if (INSCC != SPARC_CC_ICC_N) // never
- op->jump = INSOP(1).imm;
- if (INSCC != SPARC_CC_ICC_A) // always
- op->fail = addr+4;
+ if (INSCC != SPARC_CC_ICC_N) { // never
+ op->jump = INSOP (1).imm;
+ }
+ if (INSCC != SPARC_CC_ICC_A) { // always
+ op->fail = addr + 4;
+ }
break;
case SPARC_OP_IMM:
op->type = R_ANAL_OP_TYPE_CJMP;
- if (INSCC != SPARC_CC_ICC_N) // never
- op->jump = INSOP(0).imm;
- if (INSCC != SPARC_CC_ICC_A) // always
- op->fail = addr+4;
+ if (INSCC != SPARC_CC_ICC_N) { // never
+ op->jump = INSOP (0).imm;
+ }
+ if (INSCC != SPARC_CC_ICC_A) { // always
+ op->fail = addr + 4;
+ }
break;
default:
// MEM?
diff --git a/libr/anal/p/anal_sparc_gnu.c b/libr/anal/p/anal_sparc_gnu.c
index 529d64c7a7..fc9fd1c96b 100644
--- a/libr/anal/p/anal_sparc_gnu.c
+++ b/libr/anal/p/anal_sparc_gnu.c
@@ -304,8 +304,9 @@ static void anal_call(RAnalOp *op, const ut32 insn, const ut64 addr) {
static void anal_jmpl(RAnal const * const anal, RAnalOp *op, const ut32 insn, const ut64 addr) {
st64 disp = 0;
- if (X_LDST_I(insn))
- disp = get_immed_sgnext(insn, 12);
+ if (X_LDST_I (insn)) {
+ disp = get_immed_sgnext (insn, 12);
+ }
if (X_RD(insn) == GPR_O7) {
op->type = R_ANAL_OP_TYPE_UCALL;
diff --git a/libr/anal/p/anal_tms320.c b/libr/anal/p/anal_tms320.c
index 195cea1997..aaa15321b7 100644
--- a/libr/anal/p/anal_tms320.c
+++ b/libr/anal/p/anal_tms320.c
@@ -38,20 +38,23 @@ int tms320_c55x_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len)
if (match(str, "B ")) {
op->type = R_ANAL_OP_TYPE_JMP;
- if (match(str, "B AC"))
+ if (match (str, "B AC")) {
op->type = R_ANAL_OP_TYPE_UJMP;
+ }
} else if (match(str, "BCC ") || match(str, "BCCU ")) {
op->type = R_ANAL_OP_TYPE_CJMP;
} else if (match(str, "CALL ")) {
op->type = R_ANAL_OP_TYPE_CALL;
- if (match(str, "CALL AC"))
+ if (match (str, "CALL AC")) {
op->type = R_ANAL_OP_TYPE_UCALL;
+ }
} else if (match(str, "CALLCC ")) {
op->type = R_ANAL_OP_TYPE_CCALL;
} else if (match(str, "RET")) {
op->type = R_ANAL_OP_TYPE_RET;
- if (match(str, "RETCC"))
+ if (match (str, "RETCC")) {
op->type = R_ANAL_OP_TYPE_CRET;
+ }
} else if (match(str, "MOV ")) {
op->type = R_ANAL_OP_TYPE_MOV;
} else if (match(str, "PSHBOTH ")) {
diff --git a/libr/anal/p/anal_tms320_c55x_plus.c b/libr/anal/p/anal_tms320_c55x_plus.c
index db8732f502..6178d87086 100644
--- a/libr/anal/p/anal_tms320_c55x_plus.c
+++ b/libr/anal/p/anal_tms320_c55x_plus.c
@@ -12,12 +12,14 @@ int tms320_c55x_plus_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int
ut16 *ins = (ut16*)buf;
ut32 ins_len;
- if (!buf || len <= 0)
+ if (!buf || len <= 0) {
return 0;
+ }
ins_len = get_ins_len(buf[0]);
- if (ins_len == 0)
+ if (ins_len == 0) {
return 0;
+ }
memset (op, 0, sizeof (RAnalOp));
op->type = R_ANAL_OP_TYPE_UNK;
diff --git a/libr/anal/p/anal_v810.c b/libr/anal/p/anal_v810.c
index 32dfe44171..358c04da4e 100644
--- a/libr/anal/p/anal_v810.c
+++ b/libr/anal/p/anal_v810.c
@@ -17,17 +17,33 @@ enum {
};
static void update_flags(RAnalOp *op, int flags) {
- if (flags & V810_FLAG_CY) r_strbuf_append(&op->esil, ",$c31,cy,=");
- if (flags & V810_FLAG_OV) r_strbuf_append(&op->esil, ",$o,ov,=");
- if (flags & V810_FLAG_S) r_strbuf_append(&op->esil, ",$s,s,=");
- if (flags & V810_FLAG_Z) r_strbuf_append(&op->esil, ",$z,z,=");
+ if (flags & V810_FLAG_CY) {
+ r_strbuf_append (&op->esil, ",$c31,cy,=");
+ }
+ if (flags & V810_FLAG_OV) {
+ r_strbuf_append (&op->esil, ",$o,ov,=");
+ }
+ if (flags & V810_FLAG_S) {
+ r_strbuf_append (&op->esil, ",$s,s,=");
+ }
+ if (flags & V810_FLAG_Z) {
+ r_strbuf_append (&op->esil, ",$z,z,=");
+ }
}
static void clear_flags(RAnalOp *op, int flags) {
- if (flags & V810_FLAG_CY) r_strbuf_append(&op->esil, ",0,cy,=");
- if (flags & V810_FLAG_OV) r_strbuf_append(&op->esil, ",0,ov,=");
- if (flags & V810_FLAG_S) r_strbuf_append(&op->esil, ",0,s,=");
- if (flags & V810_FLAG_Z) r_strbuf_append(&op->esil, ",0,z,=");
+ if (flags & V810_FLAG_CY) {
+ r_strbuf_append (&op->esil, ",0,cy,=");
+ }
+ if (flags & V810_FLAG_OV) {
+ r_strbuf_append (&op->esil, ",0,ov,=");
+ }
+ if (flags & V810_FLAG_S) {
+ r_strbuf_append (&op->esil, ",0,s,=");
+ }
+ if (flags & V810_FLAG_Z) {
+ r_strbuf_append (&op->esil, ",0,z,=");
+ }
}
static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
@@ -58,8 +74,9 @@ static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len)
op->ptr = op->val = -1;
opcode = OPCODE(word1);
- if (opcode>>3 == 0x4)
+ if (opcode >> 3 == 0x4) {
opcode &= 0x20;
+ }
switch (opcode) {
case V810_MOV:
@@ -104,10 +121,11 @@ static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len)
update_flags (op, V810_FLAG_OV | V810_FLAG_S | V810_FLAG_Z);
break;
case V810_JMP:
- if (REG1(word1) == 31)
+ if (REG1 (word1) == 31) {
op->type = R_ANAL_OP_TYPE_RET;
- else
+ } else {
op->type = R_ANAL_OP_TYPE_UJMP;
+ }
r_strbuf_appendf (&op->esil, "r%u,pc,=",
REG1(word1));
break;
diff --git a/libr/anal/p/anal_v850.c b/libr/anal/p/anal_v850.c
index b21aaed661..0b9625b4b2 100644
--- a/libr/anal/p/anal_v850.c
+++ b/libr/anal/p/anal_v850.c
@@ -12,17 +12,33 @@
#include
static void update_flags(RAnalOp *op, int flags) {
- if (flags & V850_FLAG_CY) r_strbuf_append (&op->esil, ",$c31,cy,=");
- if (flags & V850_FLAG_OV) r_strbuf_append (&op->esil, ",$o,ov,=");
- if (flags & V850_FLAG_S) r_strbuf_append (&op->esil, ",$s,s,=");
- if (flags & V850_FLAG_Z) r_strbuf_append (&op->esil, ",$z,z,=");
+ if (flags & V850_FLAG_CY) {
+ r_strbuf_append (&op->esil, ",$c31,cy,=");
+ }
+ if (flags & V850_FLAG_OV) {
+ r_strbuf_append (&op->esil, ",$o,ov,=");
+ }
+ if (flags & V850_FLAG_S) {
+ r_strbuf_append (&op->esil, ",$s,s,=");
+ }
+ if (flags & V850_FLAG_Z) {
+ r_strbuf_append (&op->esil, ",$z,z,=");
+ }
}
static void clear_flags(RAnalOp *op, int flags) {
- if (flags & V850_FLAG_CY) r_strbuf_append (&op->esil, ",0,cy,=");
- if (flags & V850_FLAG_OV) r_strbuf_append (&op->esil, ",0,ov,=");
- if (flags & V850_FLAG_S) r_strbuf_append (&op->esil, ",0,s,=");
- if (flags & V850_FLAG_Z) r_strbuf_append (&op->esil, ",0,z,=");
+ if (flags & V850_FLAG_CY) {
+ r_strbuf_append (&op->esil, ",0,cy,=");
+ }
+ if (flags & V850_FLAG_OV) {
+ r_strbuf_append (&op->esil, ",0,ov,=");
+ }
+ if (flags & V850_FLAG_S) {
+ r_strbuf_append (&op->esil, ",0,s,=");
+ }
+ if (flags & V850_FLAG_Z) {
+ r_strbuf_append (&op->esil, ",0,z,=");
+ }
}
static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
diff --git a/libr/anal/p/anal_vax.c b/libr/anal/p/anal_vax.c
index 89250562fd..701c32c003 100644
--- a/libr/anal/p/anal_vax.c
+++ b/libr/anal/p/anal_vax.c
@@ -13,7 +13,9 @@
static int vax_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
op->size = 1;
- if (len<1) return -1;
+ if (len < 1) {
+ return -1;
+ }
op->type = R_ANAL_OP_TYPE_UNK;
switch (buf[0]) {
case 0xd0:
diff --git a/libr/anal/p/anal_x86_cs.c b/libr/anal/p/anal_x86_cs.c
index ef55cc6d95..84c88ad886 100644
--- a/libr/anal/p/anal_x86_cs.c
+++ b/libr/anal/p/anal_x86_cs.c
@@ -2071,8 +2071,9 @@ static void anop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh
}
break;
case X86_OP_IMM:
- if (INSOP(1).imm > 10)
- op->ptr = INSOP(1).imm;
+ if (INSOP (1).imm > 10) {
+ op->ptr = INSOP (1).imm;
+ }
break;
default:
break;
@@ -2746,8 +2747,9 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
//#if X86_GRP_PRIVILEGE>0
if (insn) {
#if HAVE_CSGRP_PRIVILEGE
- if (cs_insn_group (handle, insn, X86_GRP_PRIVILEGE))
+ if (cs_insn_group (handle, insn, X86_GRP_PRIVILEGE)) {
op->family = R_ANAL_OP_FAMILY_PRIV;
+ }
#endif
#if !USE_ITER_API
cs_free (insn, n);
diff --git a/libr/anal/p/anal_xap.c b/libr/anal/p/anal_xap.c
index 06ac564304..558f2ec9fa 100644
--- a/libr/anal/p/anal_xap.c
+++ b/libr/anal/p/anal_xap.c
@@ -129,8 +129,9 @@ static int xap_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len
// BSR
op->type = R_ANAL_OP_TYPE_CALL;
op->jump = label_off (&d);
- if (op->jump&1)
- op->jump+=3;
+ if (op->jump & 1) {
+ op->jump += 3;
+ }
op->fail = addr+2;
op->eob = true;
break;
@@ -150,16 +151,18 @@ static int xap_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len
case 0: // BRA
op->type = R_ANAL_OP_TYPE_JMP;
op->jump = label_off (&d)+4;
- if (op->jump&1)
- op->jump+=3;
+ if (op->jump & 1) {
+ op->jump += 3;
+ }
op->eob = true;
break;
case 1:
// BLT
op->type = R_ANAL_OP_TYPE_CJMP;
op->jump = label_off (&d);
- if (op->jump&1)
- op->jump+=3;
+ if (op->jump & 1) {
+ op->jump += 3;
+ }
op->fail = addr + 2;
op->eob = true;
break;
@@ -167,8 +170,9 @@ static int xap_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len
// BPL
op->type = R_ANAL_OP_TYPE_CJMP;
op->jump = label_off (&d);
- if (op->jump&1)
- op->jump+=3;
+ if (op->jump & 1) {
+ op->jump += 3;
+ }
op->fail = addr + 2;
op->eob = true;
break;
@@ -176,8 +180,9 @@ static int xap_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len
// BMI
op->type = R_ANAL_OP_TYPE_CJMP;
op->jump = label_off (&d);
- if (op->jump&1)
- op->jump+=3;
+ if (op->jump & 1) {
+ op->jump += 3;
+ }
op->fail = addr + 2;
op->eob = true;
break;
@@ -191,8 +196,9 @@ static int xap_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len
case 3: // BCS
op->type = R_ANAL_OP_TYPE_CJMP;
op->jump = label_off (&d);
- if (op->jump&1)
- op->jump+=3;
+ if (op->jump & 1) {
+ op->jump += 3;
+ }
op->fail = addr+2;
break;
}
diff --git a/libr/anal/p/anal_xcore_cs.c b/libr/anal/p/anal_xcore_cs.c
index 778f1c17e1..c3794f3722 100644
--- a/libr/anal/p/anal_xcore_cs.c
+++ b/libr/anal/p/anal_xcore_cs.c
@@ -56,8 +56,9 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
cs_insn *insn;
int mode, n, ret;
mode = CS_MODE_BIG_ENDIAN;
- if (!strcmp (a->cpu, "v9"))
+ if (!strcmp (a->cpu, "v9")) {
mode |= CS_MODE_V9;
+ }
if (mode != omode) {
if (handle) {
cs_close (&handle);
diff --git a/libr/anal/p/anal_xtensa.c b/libr/anal/p/anal_xtensa.c
index ab4896e89c..fd258edebd 100644
--- a/libr/anal/p/anal_xtensa.c
+++ b/libr/anal/p/anal_xtensa.c
@@ -282,10 +282,11 @@ static void xtensa_imp_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf)
op->type = R_ANAL_OP_TYPE_NULL;
break;
case 0xe:
- if (((buf[0] >> 4) & 0xf) <= 1)
+ if (((buf[0] >> 4) & 0xf) <= 1) {
op->type = R_ANAL_OP_TYPE_RET;
- else
+ } else {
xtensa_unk_op (anal, op, addr, buf);
+ }
break;
default:
xtensa_unk_op (anal, op, addr, buf);
@@ -495,10 +496,11 @@ static void xtensa_lsci_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf)
ut8 r = buf[1] >> 4;
op->family = R_ANAL_OP_FAMILY_FPU;
if ((r & 3) == 0) {
- if (r & 4)
+ if (r & 4) {
xtensa_store_op (anal, op, addr, buf);
- else
+ } else {
xtensa_load_op (anal, op, addr, buf);
+ }
} else {
xtensa_unk_op (anal, op, addr, buf);
}
@@ -1904,14 +1906,16 @@ static void analop_esil (xtensa_isa isa, xtensa_opcode opcode, xtensa_format for
}
static int xtensa_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf_original, int len_original) {
- if (!op)
+ if (!op) {
return 1;
+ }
memset (op, 0, sizeof (RAnalOp));
r_strbuf_init (&op->esil);
op->size = xtensa_length (buf_original);
- if (op->size > len_original)
+ if (op->size > len_original) {
return 1;
+ }
xtensa_op0_fns[(buf_original[0] & 0xf)] (anal, op, addr, buf_original);
diff --git a/libr/anal/reflines.c b/libr/anal/reflines.c
index d1d1f97c21..0c17dab779 100644
--- a/libr/anal/reflines.c
+++ b/libr/anal/reflines.c
@@ -193,7 +193,9 @@ R_API RList *r_anal_reflines_get(RAnal *anal, ut64 addr, const ut8 *buf, ut64 le
if (min < 0) {
min = 0;
}
- while (free_levels[++min] == 1);
+ while (free_levels[++min] == 1) {
+ ;
+ }
} else {
free_levels[el->r->level - 1] = 0;
if (min > el->r->level - 1) {
@@ -321,8 +323,9 @@ R_API int r_anal_reflines_middle(RAnal *a, RList* /**/ list, ut64
RAnalRefline *ref;
RListIter *iter;
r_list_foreach (list, iter, ref) {
- if ((ref->to > addr) && (ref->to < addr+len))
+ if ((ref->to > addr) && (ref->to < addr + len)) {
return true;
+ }
}
}
return false;
diff --git a/libr/anal/value.c b/libr/anal/value.c
index ee20b24a31..841d110d3f 100644
--- a/libr/anal/value.c
+++ b/libr/anal/value.c
@@ -13,7 +13,9 @@ R_API RAnalValue *r_anal_value_new_from_string(const char *str) {
R_API RAnalValue *r_anal_value_copy(RAnalValue *ov) {
RAnalValue *v = R_NEW0 (RAnalValue);
- if (!v) return NULL;
+ if (!v) {
+ return NULL;
+ }
memcpy (v, ov, sizeof (RAnalValue));
// reference to reg and regdelta should be kept
return v;
@@ -34,13 +36,16 @@ R_API void r_anal_value_free(RAnalValue *value) {
// mul*value+regbase+regidx+delta
R_API ut64 r_anal_value_to_ut64(RAnal *anal, RAnalValue *val) {
ut64 num;
- if (!val)
+ if (!val) {
return 0LL;
+ }
num = val->base + (val->delta*(val->mul?val->mul:1));
- if (val->reg)
+ if (val->reg) {
num += r_reg_get_value (anal->reg, val->reg);
- if (val->regdelta)
+ }
+ if (val->regdelta) {
num += r_reg_get_value (anal->reg, val->regdelta);
+ }
switch (val->memref) {
case 1:
case 2:
@@ -60,10 +65,13 @@ R_API int r_anal_value_set_ut64(RAnal *anal, RAnalValue *val, ut64 num) {
ut64 addr = r_anal_value_to_ut64 (anal, val);
r_mem_set_num (data, val->memref, num);
anal->iob.write_at (anal->iob.io, addr, data, val->memref);
- } else eprintf ("No IO binded to r_anal\n");
+ } else {
+ eprintf ("No IO binded to r_anal\n");
+ }
} else {
- if (val->reg)
+ if (val->reg) {
r_reg_set_value (anal->reg, val->reg, num);
+ }
}
return false; //is this necessary
}
@@ -73,9 +81,11 @@ R_API char *r_anal_value_to_string (RAnalValue *value) {
if (value) {
out = r_str_new ("");
if (!value->base && !value->reg) {
- if (value->imm != -1LL)
+ if (value->imm != -1LL) {
out = r_str_appendf (out, "0x%"PFMT64x, value->imm);
- else out = r_str_append (out, "-1");
+ } else {
+ out = r_str_append (out, "-1");
+ }
} else {
if (value->memref) {
switch (value->memref) {
@@ -86,13 +96,26 @@ R_API char *r_anal_value_to_string (RAnalValue *value) {
}
out = r_str_append (out, "[");
}
- if (value->mul) out = r_str_appendf (out, "%d*", value->mul);
- if (value->reg) out = r_str_appendf (out, "%s", value->reg->name);
- if (value->regdelta) out = r_str_appendf (out, "+%s", value->regdelta->name);
- if (value->base!=0) out = r_str_appendf (out, "0x%"PFMT64x, value->base);
- if (value->delta>0) out = r_str_appendf (out, "+0x%"PFMT64x, value->delta);
- else if (value->delta<0) out = r_str_appendf (out, "-0x%"PFMT64x, -value->delta);
- if (value->memref) out = r_str_append (out, "]");
+ if (value->mul) {
+ out = r_str_appendf (out, "%d*", value->mul);
+ }
+ if (value->reg) {
+ out = r_str_appendf (out, "%s", value->reg->name);
+ }
+ if (value->regdelta) {
+ out = r_str_appendf (out, "+%s", value->regdelta->name);
+ }
+ if (value->base != 0) {
+ out = r_str_appendf (out, "0x%" PFMT64x, value->base);
+ }
+ if (value->delta > 0) {
+ out = r_str_appendf (out, "+0x%" PFMT64x, value->delta);
+ } else if (value->delta < 0) {
+ out = r_str_appendf (out, "-0x%" PFMT64x, -value->delta);
+ }
+ if (value->memref) {
+ out = r_str_append (out, "]");
+ }
}
}
return out;
diff --git a/libr/anal/vtable.c b/libr/anal/vtable.c
index 72adc40062..3dc9c1e704 100644
--- a/libr/anal/vtable.c
+++ b/libr/anal/vtable.c
@@ -247,8 +247,9 @@ R_API void r_anal_list_vtables(RAnal *anal, int rad) {
bool isFirstMethod = true;
r_cons_printf ("{\"offset\":%"PFMT64d",\"methods\":[", table->saddr);
r_vector_foreach (&table->methods, curMethod) {
- if(!isFirstMethod)
+ if (!isFirstMethod) {
r_cons_print (",");
+ }
RAnalFunction *fcn = r_anal_get_fcn_in (anal, curMethod->addr, 0);
const char* const name = fcn ? fcn->name : NULL;
r_cons_printf ("{\"offset\":%"PFMT64d",\"name\":\"%s\"}",
diff --git a/libr/asm/arch/arc/gnu/arc-dis.c b/libr/asm/arch/arc/gnu/arc-dis.c
index b1b871e361..1e8f6fb39d 100644
--- a/libr/asm/arch/arc/gnu/arc-dis.c
+++ b/libr/asm/arch/arc/gnu/arc-dis.c
@@ -183,25 +183,28 @@ typedef enum
static const char *
core_reg_name (struct arcDisState * state, int val)
{
- if (state->coreRegName)
- return (*state->coreRegName)(state->_this, val);
- return 0;
+ if (state->coreRegName) {
+ return (*state->coreRegName) (state->_this, val);
+ }
+ return 0;
}
static const char *
aux_reg_name (struct arcDisState * state, int val)
{
- if (state->auxRegName)
- return (*state->auxRegName)(state->_this, val);
- return 0;
+ if (state->auxRegName) {
+ return (*state->auxRegName) (state->_this, val);
+ }
+ return 0;
}
static const char *
cond_code_name (struct arcDisState * state, int val)
{
- if (state->condCodeName)
- return (*state->condCodeName)(state->_this, val);
- return 0;
+ if (state->condCodeName) {
+ return (*state->condCodeName) (state->_this, val);
+ }
+ return 0;
}
static const char *
@@ -210,16 +213,18 @@ instruction_name (struct arcDisState * state,
int op2,
int * flags)
{
- if (state->instName)
- return (*state->instName)(state->_this, op1, op2, flags);
- return 0;
+ if (state->instName) {
+ return (*state->instName) (state->_this, op1, op2, flags);
+ }
+ return 0;
}
static void
mwerror (struct arcDisState * state, const char * msg)
{
- if (state->err != 0)
- (*state->err)(state->_this, (msg));
+ if (state->err != 0) {
+ (*state->err) (state->_this, (msg));
+ }
}
static const char *
@@ -258,42 +263,39 @@ arc_sprintf (struct arcDisState *state, char *buf, const char *format, ...)
regMap[0] = 0;
regMap[1] = 0;
- while (1)
- switch (*p++)
- {
- case 0:
- goto DOCOMM; /* Return. */
- default:
- *bp++ = p[-1];
- break;
- case '%':
- size = 0;
- leading_zero = 0;
- RETRY: ;
- switch (*p++)
- {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- {
- /* size. */
- size = p[-1] - '0';
- if (size == 0)
- leading_zero = 1; /* e.g. %08x */
- while (*p >= '0' && *p <= '9')
- {
- size = size * 10 + *p - '0';
- p++;
- }
- goto RETRY;
- }
+ while (1) {
+ switch (*p++) {
+ case 0:
+ goto DOCOMM; /* Return. */
+ default:
+ *bp++ = p[-1];
+ break;
+ case '%':
+ size = 0;
+ leading_zero = 0;
+ RETRY:;
+ switch (*p++) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9': {
+ /* size. */
+ size = p[-1] - '0';
+ if (size == 0) {
+ leading_zero = 1; /* e.g. %08x */
+ }
+ while (*p >= '0' && *p <= '9') {
+ size = size * 10 + *p - '0';
+ p++;
+ }
+ goto RETRY;
+ }
#define inc_bp() bp = bp + strlen (bp)
case 'h':
@@ -307,13 +309,15 @@ arc_sprintf (struct arcDisState *state, char *buf, const char *format, ...)
{
int val = va_arg (ap, int);
- if (size != 0)
- if (leading_zero)
- sprintf (bp, "%0*x", size, val);
- else
- sprintf (bp, "%*x", size, val);
- else
- sprintf (bp, "%x", val);
+ if (size != 0) {
+ if (leading_zero) {
+ sprintf (bp, "%0*x", size, val);
+ } else {
+ sprintf (bp, "%*x", size, val);
+ }
+ } else {
+ sprintf (bp, "%x", val);
+ }
inc_bp ();
}
break;
@@ -321,10 +325,11 @@ arc_sprintf (struct arcDisState *state, char *buf, const char *format, ...)
{
int val = va_arg (ap, int);
- if (size != 0)
- sprintf (bp, "%*d", size, val);
- else
- sprintf (bp, "%d", val);
+ if (size != 0) {
+ sprintf (bp, "%*d", size, val);
+ } else {
+ sprintf (bp, "%d", val);
+ }
inc_bp ();
}
break;
@@ -349,10 +354,11 @@ arc_sprintf (struct arcDisState *state, char *buf, const char *format, ...)
const char *ext;
ext = core_reg_name (state, val);
- if (ext)
- sprintf (bp, "%s", ext);
- else
- sprintf (bp, "r%d", val);
+ if (ext) {
+ sprintf (bp, "%s", ext);
+ } else {
+ sprintf (bp, "r%d", val);
+ }
}
break;
}
@@ -378,10 +384,11 @@ arc_sprintf (struct arcDisState *state, char *buf, const char *format, ...)
const char *ext;
ext = aux_reg_name (state, val);
- if (ext)
- sprintf (bp, "%s", ext);
- else
- arc_sprintf (state, bp, "%h", val);
+ if (ext) {
+ sprintf (bp, "%s", ext);
+ } else {
+ arc_sprintf (state, bp, "%h", val);
+ }
}
break;
}
@@ -398,7 +405,8 @@ arc_sprintf (struct arcDisState *state, char *buf, const char *format, ...)
fprintf (stderr, "?? format %c\n", p[-1]);
break;
}
- }
+ }
+ }
DOCOMM: *bp = 0;
va_end (ap);
@@ -426,20 +434,23 @@ write_instr_name_(struct arcDisState * state,
{
const char *cc = 0;
- if (!condCodeIsPartOfName)
- strcat (state->instrBuffer, ".");
- if (cond < 16)
- cc = condName[cond];
- else
- cc = cond_code_name (state, cond);
- if (!cc)
- cc = "???";
+ if (!condCodeIsPartOfName) {
+ strcat (state->instrBuffer, ".");
+ }
+ if (cond < 16) {
+ cc = condName[cond];
+ } else {
+ cc = cond_code_name (state, cond);
+ }
+ if (!cc) {
+ cc = "???";
+ }
strcat (state->instrBuffer, cc);
}
- if (flag)
- strcat (state->instrBuffer, ".f");
- switch (state->nullifyMode)
- {
+ if (flag) {
+ strcat (state->instrBuffer, ".f");
+ }
+ switch (state->nullifyMode) {
case BR_exec_always:
strcat (state->instrBuffer, ".d");
break;
@@ -449,12 +460,15 @@ write_instr_name_(struct arcDisState * state,
case BR_exec_when_no_jump:
break;
}
- if (signExtend)
- strcat (state->instrBuffer, ".x");
- if (addrWriteBack)
- strcat (state->instrBuffer, ".a");
- if (directMem)
- strcat (state->instrBuffer, ".di");
+ if (signExtend) {
+ strcat (state->instrBuffer, ".x");
+ }
+ if (addrWriteBack) {
+ strcat (state->instrBuffer, ".a");
+ }
+ if (directMem) {
+ strcat (state->instrBuffer, ".di");
+ }
}
#define write_instr_name() \
@@ -506,8 +520,9 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState * state)
state->ea_reg2 = no_reg;
state->_offset = 0;
- if (! NEXT_WORD (0))
- return 0;
+ if (!NEXT_WORD (0)) {
+ return 0;
+ }
state->_opcode = OPCODE (state->words[0]);
instrName = 0;
@@ -651,16 +666,23 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState * state)
instrName = "???";
state->flow = invalid_instr;
}
- if (flags & IGNORE_FIRST_OPD)
- ignoreFirstOpd = 1;
- break;
+ if (flags & IGNORE_FIRST_OPD) {
+ ignoreFirstOpd = 1;
+ }
+ break;
}
break;
case op_BC: instrName = "b";
- case op_BLC: if (!instrName) instrName = "bl";
- case op_LPC: if (!instrName) instrName = "lp";
+ case op_BLC:
+ if (!instrName) {
+ instrName = "bl";
+ }
+ case op_LPC:
+ if (!instrName) {
+ instrName = "lp";
+ }
case op_JC:
if (!instrName)
{
@@ -706,9 +728,9 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState * state)
with ARC). This encoding says: xor -1, -1, -1. */
instrName = "nop";
decodingClass = CLASS_A4_OP3_SUBOPC3F;
- }
- else
- instrName = "xor";
+ } else {
+ instrName = "xor";
+ }
break;
default:
@@ -719,9 +741,10 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState * state)
instrName = "???";
state->flow=invalid_instr;
}
- if (flags & IGNORE_FIRST_OPD)
- ignoreFirstOpd = 1;
- break;
+ if (flags & IGNORE_FIRST_OPD) {
+ ignoreFirstOpd = 1;
+ }
+ break;
}
fieldAisReg = fieldBisReg = fieldCisReg = 1; /* Assume regs for now. */
@@ -735,8 +758,9 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState * state)
case CLASS_A4_ARITH:
CHECK_FIELD_A ();
CHECK_FIELD_B ();
- if (!repeatsOp)
- CHECK_FIELD_C ();
+ if (!repeatsOp) {
+ CHECK_FIELD_C ();
+ }
CHECK_FLAG_COND_NULLIFY ();
write_instr_name ();
@@ -744,8 +768,9 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState * state)
{
WRITE_FORMAT_x (A);
WRITE_FORMAT_COMMA_x (B);
- if (!repeatsOp)
- WRITE_FORMAT_COMMA_x (C);
+ if (!repeatsOp) {
+ WRITE_FORMAT_COMMA_x (C);
+ }
WRITE_NOP_COMMENT ();
arc_sprintf (state, state->operandBuffer, formatString,
fieldA, fieldB, fieldC);
@@ -753,8 +778,9 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState * state)
else
{
WRITE_FORMAT_x (B);
- if (!repeatsOp)
- WRITE_FORMAT_COMMA_x (C);
+ if (!repeatsOp) {
+ WRITE_FORMAT_COMMA_x (C);
+ }
arc_sprintf (state, state->operandBuffer, formatString,
fieldB, fieldC);
}
@@ -831,8 +857,9 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState * state)
add_target (fieldB);
/* Screwy JLcc requires .jd mode to execute correctly
but we pretend it is .nd (no delay slot). */
- if (is_linked && state->nullifyMode == BR_exec_when_jump)
- state->nullifyMode = BR_exec_when_no_jump;
+ if (is_linked && state->nullifyMode == BR_exec_when_jump) {
+ state->nullifyMode = BR_exec_when_no_jump;
+ }
}
else
{
@@ -852,31 +879,35 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState * state)
fieldAisReg = 0;
WRITE_FORMAT_COMMA_x (A);
}
- if (IS_REG (B))
- arc_sprintf (state, state->operandBuffer, formatString, fieldB, fieldA);
- else
- arc_sprintf (state, state->operandBuffer, formatString,
- post_address (state, fieldB), fieldA);
- break;
+ if (IS_REG (B)) {
+ arc_sprintf (state, state->operandBuffer, formatString, fieldB, fieldA);
+ } else {
+ arc_sprintf (state, state->operandBuffer, formatString,
+ post_address (state, fieldB), fieldA);
+ }
+ break;
case CLASS_A4_LD0:
/* LD instruction. B and C can be regs, or one (both?) can be limm. */
CHECK_FIELD_A ();
CHECK_FIELD_B ();
CHECK_FIELD_C ();
- if (dbg)
- printf ("5:b reg %d %d c reg %d %d \n",
- fieldBisReg,fieldB,fieldCisReg,fieldC);
+ if (dbg) {
+ printf ("5:b reg %d %d c reg %d %d \n",
+ fieldBisReg, fieldB, fieldCisReg, fieldC);
+ }
state->_offset = 0;
state->_ea_present = 1;
- if (fieldBisReg)
- state->ea_reg1 = fieldB;
- else
- state->_offset += fieldB;
- if (fieldCisReg)
- state->ea_reg2 = fieldC;
- else
- state->_offset += fieldC;
+ if (fieldBisReg) {
+ state->ea_reg1 = fieldB;
+ } else {
+ state->_offset += fieldB;
+ }
+ if (fieldCisReg) {
+ state->ea_reg2 = fieldC;
+ } else {
+ state->_offset += fieldC;
+ }
state->_mem_load = 1;
directMem = BIT (state->words[0], 5);
@@ -885,10 +916,11 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState * state)
write_instr_name ();
WRITE_FORMAT_x_COMMA_LB(A);
- if (fieldBisReg || fieldB != 0)
- WRITE_FORMAT_x_COMMA (B);
- else
- fieldB = fieldC;
+ if (fieldBisReg || fieldB != 0) {
+ WRITE_FORMAT_x_COMMA (B);
+ } else {
+ fieldB = fieldC;
+ }
WRITE_FORMAT_x_RB (C);
arc_sprintf (state, state->operandBuffer, formatString,
@@ -901,18 +933,20 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState * state)
CHECK_FIELD_A ();
fieldC = FIELDD (state->words[0]);
- if (dbg)
- eprintf ("6:b reg %d %d c 0x%x \n",
- fieldBisReg, fieldB, fieldC);
+ if (dbg) {
+ eprintf ("6:b reg %d %d c 0x%x \n",
+ fieldBisReg, fieldB, fieldC);
+ }
state->_ea_present = 1;
state->_offset = fieldC;
state->_mem_load = 1;
- if (fieldBisReg)
- state->ea_reg1 = fieldB;
- /* Field B is either a shimm (same as fieldC) or limm (different!)
+ if (fieldBisReg) {
+ state->ea_reg1 = fieldB;
+ /* Field B is either a shimm (same as fieldC) or limm (different!)
Say ea is not present, so only one of us will do the name lookup. */
- else
- state->_offset += fieldB, state->_ea_present = 0;
+ } else {
+ state->_offset += fieldB, state->_ea_present = 0;
+ }
directMem = BIT (state->words[0],14);
addrWriteBack = BIT (state->words[0],12);
@@ -932,9 +966,9 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState * state)
{
fieldCisReg = 0;
WRITE_FORMAT_COMMA_x_RB (C);
- }
- else
- WRITE_FORMAT_RB ();
+ } else {
+ WRITE_FORMAT_RB ();
+ }
}
arc_sprintf (state, state->operandBuffer, formatString,
fieldA, fieldB, fieldC);
@@ -947,17 +981,20 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState * state)
fieldA = FIELDD(state->words[0]); /* shimm */
/* [B,A offset] */
- if (dbg) eprintf("7:b reg %d %x off %x\n",
- fieldBisReg,fieldB,fieldA);
+ if (dbg) {
+ eprintf ("7:b reg %d %x off %x\n",
+ fieldBisReg, fieldB, fieldA);
+ }
state->_ea_present = 1;
state->_offset = fieldA;
- if (fieldBisReg)
- state->ea_reg1 = fieldB;
- /* Field B is either a shimm (same as fieldA) or limm (different!)
+ if (fieldBisReg) {
+ state->ea_reg1 = fieldB;
+ /* Field B is either a shimm (same as fieldA) or limm (different!)
Say ea is not present, so only one of us will do the name lookup.
(for is_limm we do the name translation here). */
- else
- state->_offset += fieldB, state->_ea_present = 0;
+ } else {
+ state->_offset += fieldB, state->_ea_present = 0;
+ }
directMem = BIT (state->words[0], 26);
addrWriteBack = BIT (state->words[0], 24);
@@ -977,9 +1014,9 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState * state)
{
fieldAisReg = 0;
WRITE_FORMAT_COMMA_x_RB(A);
- }
- else
- WRITE_FORMAT_RB();
+ } else {
+ WRITE_FORMAT_RB ();
+ }
}
arc_sprintf (state, state->operandBuffer, formatString,
fieldC, fieldB, fieldA);
@@ -1088,45 +1125,46 @@ ARCTangent_decodeInstr (bfd_vma address, disassemble_info *info)
(*info->memory_error_func) (status, address, info);
return -1;
}
- if (info->endian == BFD_ENDIAN_LITTLE)
- s.words[0] = bfd_getl32(buffer);
- else
- s.words[0] = bfd_getb32(buffer);
- /* Always read second word in case of limm. */
- /* We ignore the result since last insn may not have a limm. */
- status = (*info->read_memory_func) (address + 4, buffer, 4, info);
- if (info->endian == BFD_ENDIAN_LITTLE)
- s.words[1] = bfd_getl32(buffer);
- else
- s.words[1] = bfd_getb32(buffer);
+ if (info->endian == BFD_ENDIAN_LITTLE) {
+ s.words[0] = bfd_getl32 (buffer);
+ } else {
+ s.words[0] = bfd_getb32 (buffer);
+ }
+ /* Always read second word in case of limm. */
+ /* We ignore the result since last insn may not have a limm. */
+ status = (*info->read_memory_func) (address + 4, buffer, 4, info);
+ if (info->endian == BFD_ENDIAN_LITTLE) {
+ s.words[1] = bfd_getl32 (buffer);
+ } else {
+ s.words[1] = bfd_getb32 (buffer);
+ }
- s._this = &s;
- s.coreRegName = _coreRegName;
- s.auxRegName = _auxRegName;
- s.condCodeName = _condCodeName;
- s.instName = _instName;
+ s._this = &s;
+ s.coreRegName = _coreRegName;
+ s.auxRegName = _auxRegName;
+ s.condCodeName = _condCodeName;
+ s.instName = _instName;
- /* Disassemble. */
- dsmOneArcInst (address, (void *)&s);
+ /* Disassemble. */
+ dsmOneArcInst (address, (void *)&s);
- /* Display the disassembly instruction. */
-/*
+ /* Display the disassembly instruction. */
+ /*
(*func) (stream, "%08lx ", s.words[0]);
(*func) (stream, " ");
*/
- (*func) (stream, "%s ", s.instrBuffer);
+ (*func) (stream, "%s ", s.instrBuffer);
- if (__TRANSLATION_REQUIRED (s))
- {
- bfd_vma addr = s.addresses[s.operandBuffer[1] - '0'];
+ if (__TRANSLATION_REQUIRED (s)) {
+ bfd_vma addr = s.addresses[s.operandBuffer[1] - '0'];
- (*info->print_address_func) ((bfd_vma) addr, info);
- //(*func) (stream, "\n");
+ (*info->print_address_func) ((bfd_vma)addr, info);
+ //(*func) (stream, "\n");
+ } else {
+ (*func) (stream, "%s", s.operandBuffer);
}
- else
- (*func) (stream, "%s",s.operandBuffer);
- return s.instructionLen;
+ return s.instructionLen;
}
diff --git a/libr/asm/arch/arc/gnu/arc-ext.c b/libr/asm/arch/arc/gnu/arc-ext.c
index 85938df59c..bc8bd748e4 100644
--- a/libr/asm/arch/arc/gnu/arc-ext.c
+++ b/libr/asm/arch/arc/gnu/arc-ext.c
@@ -329,10 +329,11 @@ arcExtMap_instName (int opcode, int insn, int *flags)
c = (insn & 0x00e0) >> 5;
i = (insn & 0x001f);
- if (i)
- minor = i;
- else
- minor = (c == 0x07) ? b : c;
+ if (i) {
+ minor = i;
+ } else {
+ minor = (c == 0x07) ? b : c;
+ }
}
/* 32-bit instructions. */
else
@@ -370,15 +371,16 @@ arcExtMap_instName (int opcode, int insn, int *flags)
}
else
{
- if (A != 0x3f)
- minor = A;
- else
- minor = B;
+ if (A != 0x3f) {
+ minor = A;
+ } else {
+ minor = B;
+ }
}
}
- }
- else /* ARCTangent extension instructions. */
- minor = insn;
+ } else { /* ARCTangent extension instructions. */
+ minor = insn;
+ }
temp = arc_extension_map.instructions[INST_HASH (opcode, minor)];
while (temp)
@@ -399,9 +401,10 @@ arcExtMap_instName (int opcode, int insn, int *flags)
const char *
arcExtMap_coreRegName (int regnum)
{
- if (regnum < FIRST_EXTENSION_CORE_REGISTER || regnum > LAST_EXTENSION_CORE_REGISTER)
- return NULL;
- return arc_extension_map.coreRegisters[regnum - FIRST_EXTENSION_CORE_REGISTER].name;
+ if (regnum < FIRST_EXTENSION_CORE_REGISTER || regnum > LAST_EXTENSION_CORE_REGISTER) {
+ return NULL;
+ }
+ return arc_extension_map.coreRegisters[regnum - FIRST_EXTENSION_CORE_REGISTER].name;
}
@@ -409,9 +412,10 @@ arcExtMap_coreRegName (int regnum)
enum ExtReadWrite
arcExtMap_coreReadWrite (int regnum)
{
- if (regnum < FIRST_EXTENSION_CORE_REGISTER || regnum > LAST_EXTENSION_CORE_REGISTER)
- return REG_INVALID;
- return arc_extension_map.coreRegisters[regnum - FIRST_EXTENSION_CORE_REGISTER].rw;
+ if (regnum < FIRST_EXTENSION_CORE_REGISTER || regnum > LAST_EXTENSION_CORE_REGISTER) {
+ return REG_INVALID;
+ }
+ return arc_extension_map.coreRegisters[regnum - FIRST_EXTENSION_CORE_REGISTER].rw;
}
@@ -419,9 +423,10 @@ arcExtMap_coreReadWrite (int regnum)
const char *
arcExtMap_condCodeName (int code)
{
- if (code < FIRST_EXTENSION_CONDITION_CODE || code > LAST_EXTENSION_CONDITION_CODE)
- return NULL;
- return arc_extension_map.condCodes[code - FIRST_EXTENSION_CONDITION_CODE];
+ if (code < FIRST_EXTENSION_CONDITION_CODE || code > LAST_EXTENSION_CONDITION_CODE) {
+ return NULL;
+ }
+ return arc_extension_map.condCodes[code - FIRST_EXTENSION_CONDITION_CODE];
}
@@ -434,8 +439,9 @@ arcExtMap_auxRegName (long address)
for (r = arc_extension_map.auxRegisters; r; r = r->next)
{
- if (r->address == address)
- return (const char *)r->name;
+ if (r->address == address) {
+ return (const char *)r->name;
+ }
}
return NULL;
}
@@ -491,21 +497,25 @@ void dump_ARC_extmap (void)
{
struct ExtInstruction *insn;
- for (insn = arc_extension_map.instructions[i]; insn != NULL; insn = insn->next)
- printf("INST: %d %d %x %s\n", insn->major, insn->minor, insn->flags, insn->name);
+ for (insn = arc_extension_map.instructions[i]; insn != NULL; insn = insn->next) {
+ printf ("INST: %d %d %x %s\n", insn->major, insn->minor, insn->flags, insn->name);
+ }
}
for (i = 0; i < NUM_EXT_CORE; i++)
{
struct ExtCoreRegister reg = arc_extension_map.coreRegisters[i];
- if (reg.name)
- printf("CORE: %s %d %s\n", reg.name, reg.number, ExtReadWrite_image(reg.rw));
+ if (reg.name) {
+ printf ("CORE: %s %d %s\n", reg.name, reg.number, ExtReadWrite_image (reg.rw));
+ }
}
- for (i = 0; i < NUM_EXT_COND; i++)
- if (arc_extension_map.condCodes[i])
- printf("COND: %s\n", arc_extension_map.condCodes[i]);
+ for (i = 0; i < NUM_EXT_COND; i++) {
+ if (arc_extension_map.condCodes[i]) {
+ printf ("COND: %s\n", arc_extension_map.condCodes[i]);
+ }
+ }
}
/******************************************************************************/
diff --git a/libr/asm/arch/arc/gnu/arc-opc.c b/libr/asm/arch/arc/gnu/arc-opc.c
index aa1e3eff7b..c4e24e172d 100644
--- a/libr/asm/arch/arc/gnu/arc-opc.c
+++ b/libr/asm/arch/arc/gnu/arc-opc.c
@@ -950,8 +950,9 @@ insert_s12 (arc_insn insn, long *ex,
lsb6 = (value & 0x3f) << 6 ;
insn |= lsb6;
- if(ex)
- *ex |= msb6;
+ if (ex) {
+ *ex |= msb6;
+ }
return insn;
}
/* Insert an unsigned sixteen bit number into a 64 bit instruction.
@@ -982,8 +983,9 @@ insert_u16 (arc_insn insn, long *ex,
lsb6 = (value & 0x3f) << 6 ;
insn |= lsb6;
- if(ex)
- *ex |= msb6;
+ if (ex) {
+ *ex |= msb6;
+ }
return insn;
}
/* Insert upper half of unsigned sixteen bit number into a 64 bit instruction.
@@ -1010,8 +1012,9 @@ insert_uu16 (arc_insn insn, long *ex,
long msb8;
msb8 = (value & 0xff) << 2;
- if(ex)
- *ex |= msb8;
+ if (ex) {
+ *ex |= msb8;
+ }
return insn;
}
/* Insert lower eight bits of unsigned sixteen bit number into a 64 bit
@@ -1043,8 +1046,9 @@ insert_ul16 (arc_insn insn, long *ex,
lsb6 = (value & 0x3f) << 6 ;
insn |= lsb6;
- if(ex)
- *ex |= msb2;
+ if (ex) {
+ *ex |= msb2;
+ }
return insn;
}
/* Insert 15 bits of signed number into a 64 bit instruction.
@@ -1066,9 +1070,10 @@ insert_s15 (arc_insn insn, long *ex,
)
{
- if(ex)
- *ex |= (value & 0x7fff);
- return insn;
+ if (ex) {
+ *ex |= (value & 0x7fff);
+ }
+ return insn;
}
/* Discarded field.
* insn is top 32 bits of instruction and gets the least significant six
@@ -1153,18 +1158,20 @@ insert_reg (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
{
/* if an ld/ldw insn */
if ((((insn >> 7) & 3) == 0) ||
- (((insn >> 7) & 3) == 2))
- /* Set .aa to 3 */
- addrwb_p = 0x600;
+ (((insn >> 7) & 3) == 2)) {
+ /* Set .aa to 3 */
+ addrwb_p = 0x600;
+ }
}
/* Check for st with .aa=0 */
else if ((insn & 0xf8000001) == 0x18000000)
{
/* if an st/stw insn */
if ((((insn >> 1) & 3) == 0) ||
- (((insn >> 1) & 3) == 2))
- /* Set .aa to 3 */
- addrwb_p = 0x18;
+ (((insn >> 1) & 3) == 2)) {
+ /* Set .aa to 3 */
+ addrwb_p = 0x18;
+ }
}
} /* addrwb_p == 0 */
}
@@ -1176,15 +1183,17 @@ insert_reg (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
op_type = OP_LIMM;
limm_p = 1;
limm = value;
- if (arc_mach_a4)
- insn |= ARC_REG_LIMM << operand->shift;
+ if (arc_mach_a4) {
+ insn |= ARC_REG_LIMM << operand->shift;
+ }
/* The constant is stored later. */
}
else
{
- if (arc_mach_a4)
- insn |= ARC_REG_SHIMM << operand->shift;
- /* insn |= value & 511; - done later. */
+ if (arc_mach_a4) {
+ insn |= ARC_REG_SHIMM << operand->shift;
+ }
+ /* insn |= value & 511; - done later. */
}
}
else{
@@ -1197,22 +1206,21 @@ insert_reg (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
if ((reg->type == AUXREG) || (reg->type == AUXREG_AC))
{
- if (!(mods & ARC_MOD_AUXREG))
- *errmsg = _("auxiliary register not allowed here");
- else if (arc_mach_a4)
- {
- if ((insn & I(-1)) == I(2)) /* Check for use validity. */
- {
- if (reg->flags & ARC_REGISTER_READONLY)
- *errmsg = _("attempt to set readonly register");
- }
- else
- {
- if (reg->flags & ARC_REGISTER_WRITEONLY)
- *errmsg = _("attempt to read writeonly register");
- }
- insn |= ARC_REG_SHIMM << operand->shift;
- insn |= reg->value << arc_operands[reg->type].shift;
+ if (!(mods & ARC_MOD_AUXREG)) {
+ *errmsg = _ ("auxiliary register not allowed here");
+ } else if (arc_mach_a4) {
+ if ((insn & I (-1)) == I (2)) /* Check for use validity. */
+ {
+ if (reg->flags & ARC_REGISTER_READONLY) {
+ *errmsg = _ ("attempt to set readonly register");
+ }
+ } else {
+ if (reg->flags & ARC_REGISTER_WRITEONLY) {
+ *errmsg = _ ("attempt to read writeonly register");
+ }
+ }
+ insn |= ARC_REG_SHIMM << operand->shift;
+ insn |= reg->value << arc_operands[reg->type].shift;
}
else /* Insert auxiliary register value for ARCompact ISA. */
{
@@ -1233,13 +1241,15 @@ insert_reg (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
if (('a' == operand->fmt) || (arc_mach_a4 && ((insn & I(-1)) < I(2))) ||
(!arc_mach_a4 && (('A' == operand->fmt)||('#' == operand->fmt))))
{
- if (reg->flags & ARC_REGISTER_READONLY)
- *errmsg = _("attempt to set readonly register");
- }
+ if (reg->flags & ARC_REGISTER_READONLY) {
+ *errmsg = _ ("attempt to set readonly register");
+ }
+ }
if ('a' != operand->fmt || (!arc_mach_a4 && ('A' != operand->fmt)))
{
- if (reg->flags & ARC_REGISTER_WRITEONLY)
- *errmsg = _("attempt to read writeonly register");
+ if (reg->flags & ARC_REGISTER_WRITEONLY) {
+ *errmsg = _ ("attempt to read writeonly register");
+ }
}
/* We should never get an invalid register number here. */
if (arc_mach_a4 && ((unsigned int) reg->value > 60))
@@ -1271,12 +1281,13 @@ insert_reg (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
register field, H, will raise an Instruction Error
exception.
This should solve the mov_s pcl, whatever bug. */
- if ((insn & 0xFF) == 0xFF)
- *errmsg = _("attempt to set readonly register");
- }
- else
- insn |= reg->value << operand->shift;
- op_type = OP_REG;
+ if ((insn & 0xFF) == 0xFF) {
+ *errmsg = _ ("attempt to set readonly register");
+ }
+ } else {
+ insn |= reg->value << operand->shift;
+ }
+ op_type = OP_REG;
}
}
@@ -1291,11 +1302,12 @@ insert_reg (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
ls_operand[LS_BASE] = op_type;
break;
case 'c':
- if ((insn & I(-1)) == I(2))
- ls_operand[LS_VALUE] = op_type;
- else
- ls_operand[LS_OFFSET] = op_type;
- break;
+ if ((insn & I (-1)) == I (2)) {
+ ls_operand[LS_VALUE] = op_type;
+ } else {
+ ls_operand[LS_OFFSET] = op_type;
+ }
+ break;
case 'o': case 'O':
ls_operand[LS_OFFSET] = op_type;
break;
@@ -1315,11 +1327,12 @@ insert_reg (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
case ')':
case '}':
case '>':
- if ((insn & I(-1)) == I(3))
- ls_operand[LS_VALUE] = op_type;
- else
- ls_operand[LS_OFFSET] = op_type;
- break;
+ if ((insn & I (-1)) == I (3)) {
+ ls_operand[LS_VALUE] = op_type;
+ } else {
+ ls_operand[LS_OFFSET] = op_type;
+ }
+ break;
}
}
return insn;
@@ -1425,13 +1438,11 @@ insert_addr_wb (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
* adding suport for it in the arc_suffixes_ac by defining aw, ab and as
* to be ADDRESS3_AC also */
- if (!arc_mach_a4 && (('p' == operand->fmt)
- || ('P' == operand->fmt)
- || ('w' == operand->fmt)
- || ('&' == operand->fmt)))
- addrwb_p = value << operand->shift;
- else
- addrwb_p = 1 << operand->shift;
+ if (!arc_mach_a4 && (('p' == operand->fmt) || ('P' == operand->fmt) || ('w' == operand->fmt) || ('&' == operand->fmt))) {
+ addrwb_p = value << operand->shift;
+ } else {
+ addrwb_p = 1 << operand->shift;
+ }
return insn;
}
@@ -1446,13 +1457,11 @@ insert_base (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
if (reg != NULL)
{
arc_insn myinsn;
- if (!arc_mach_a4 && ('g' == operand->fmt))
- insn |= insert_reg (0, ex, operand,mods, reg, value, errmsg);
- else
- {
- myinsn = (insert_reg (0, ex, operand,mods, reg, value, errmsg)
- >> operand->shift);
- insn |= B (myinsn);
+ if (!arc_mach_a4 && ('g' == operand->fmt)) {
+ insn |= insert_reg (0, ex, operand, mods, reg, value, errmsg);
+ } else {
+ myinsn = (insert_reg (0, ex, operand, mods, reg, value, errmsg) >> operand->shift);
+ insn |= B (myinsn);
}
ls_operand[LS_BASE] = OP_REG;
}
@@ -1511,25 +1520,28 @@ insert_offset (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
>> operand->shift);
/* Not if store, catch it later. */
- if (operand->flags & ARC_OPERAND_LOAD)
- /* Not if opcode == 1, catch it later. */
- if ((insn & I(-1)) != I(1))
- insn |= C(myinsn);
- }
- else
- insn |= insert_reg (0, ex, operand, mods, reg, value, errmsg);
+ if (operand->flags & ARC_OPERAND_LOAD) {
+ /* Not if opcode == 1, catch it later. */
+ if ((insn & I (-1)) != I (1)) {
+ insn |= C (myinsn);
+ }
+ }
+ } else {
+ insn |= insert_reg (0, ex, operand, mods, reg, value, errmsg);
+ }
ls_operand[LS_OFFSET] = OP_REG;
}
else
{
int bits;
- if (operand->flags & ARC_OPERAND_2BYTE_ALIGNED)
- bits = operand->bits + 1;
- else if (operand->flags & ARC_OPERAND_4BYTE_ALIGNED)
- bits = operand->bits + 2;
- else
- bits = operand->bits;
+ if (operand->flags & ARC_OPERAND_2BYTE_ALIGNED) {
+ bits = operand->bits + 1;
+ } else if (operand->flags & ARC_OPERAND_4BYTE_ALIGNED) {
+ bits = operand->bits + 2;
+ } else {
+ bits = operand->bits;
+ }
/* This is *way* more general than necessary, but maybe some day it'll
be useful. */
@@ -1545,54 +1557,48 @@ insert_offset (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
}
if (arc_mach_a4 && ((arc_cond_p && !limm_p) || value < minval || value > maxval))
{
- if (limm_p && value != limm)
- *errmsg = _("too many long constants");
- else
- {
- limm_p = 1;
- limm = value;
- if (operand->flags & ARC_OPERAND_STORE)
- insn |= B(ARC_REG_LIMM);
- if (operand->flags & ARC_OPERAND_LOAD)
- insn |= C(ARC_REG_LIMM);
- ls_operand[LS_OFFSET] = OP_LIMM;
+ if (limm_p && value != limm) {
+ *errmsg = _ ("too many long constants");
+ } else {
+ limm_p = 1;
+ limm = value;
+ if (operand->flags & ARC_OPERAND_STORE) {
+ insn |= B (ARC_REG_LIMM);
+ }
+ if (operand->flags & ARC_OPERAND_LOAD) {
+ insn |= C (ARC_REG_LIMM);
+ }
+ ls_operand[LS_OFFSET] = OP_LIMM;
}
}
else
{
- if ((value < minval || value > maxval))
- *errmsg = _("need too many limms");
- else if (arc_mach_a4 && shimm_p && value != shimm)
- {
- /* Check for bad operand combinations
+ if ((value < minval || value > maxval)) {
+ *errmsg = _ ("need too many limms");
+ } else if (arc_mach_a4 && shimm_p && value != shimm) {
+ /* Check for bad operand combinations
before we lose info about them. */
- if ((insn & I(-1)) == I(1))
- {
- *errmsg = _("to many shimms in load");
- goto out;
- }
- if (limm_p && operand->flags & ARC_OPERAND_LOAD)
- {
- *errmsg = _("too many long constants");
- goto out;
- }
- /* Convert what we thought was a shimm to a limm. */
- limm_p = 1;
- limm = shimm;
- if (ls_operand[LS_VALUE] == OP_SHIMM
- && operand->flags & ARC_OPERAND_STORE)
- {
- insn &= ~C(-1);
- insn |= C(ARC_REG_LIMM);
- ls_operand[LS_VALUE] = OP_LIMM;
- }
- if (ls_operand[LS_BASE] == OP_SHIMM
- && operand->flags & ARC_OPERAND_STORE)
- {
- insn &= ~B(-1);
- insn |= B(ARC_REG_LIMM);
- ls_operand[LS_BASE] = OP_LIMM;
- }
+ if ((insn & I (-1)) == I (1)) {
+ *errmsg = _ ("to many shimms in load");
+ goto out;
+ }
+ if (limm_p && operand->flags & ARC_OPERAND_LOAD) {
+ *errmsg = _ ("too many long constants");
+ goto out;
+ }
+ /* Convert what we thought was a shimm to a limm. */
+ limm_p = 1;
+ limm = shimm;
+ if (ls_operand[LS_VALUE] == OP_SHIMM && operand->flags & ARC_OPERAND_STORE) {
+ insn &= ~C (-1);
+ insn |= C (ARC_REG_LIMM);
+ ls_operand[LS_VALUE] = OP_LIMM;
+ }
+ if (ls_operand[LS_BASE] == OP_SHIMM && operand->flags & ARC_OPERAND_STORE) {
+ insn &= ~B (-1);
+ insn |= B (ARC_REG_LIMM);
+ ls_operand[LS_BASE] = OP_LIMM;
+ }
}
if (!arc_mach_a4)
{
@@ -1642,22 +1648,10 @@ extract_st_syntax (arc_insn *insn,
ls_operand[LS_BASE] == (B) && \
ls_operand[LS_OFFSET] == (O)))
- if (!((ST_SYNTAX(OP_REG,OP_REG,OP_NONE) && (insn[0] & 511) == 0)
- || ST_SYNTAX(OP_REG,OP_LIMM,OP_NONE)
- || (ST_SYNTAX(OP_SHIMM,OP_REG,OP_NONE) && (insn[0] & 511) == 0)
- || (ST_SYNTAX(OP_SHIMM,OP_SHIMM,OP_NONE) && (insn[0] & 511) == 0)
- || ST_SYNTAX(OP_SHIMM,OP_LIMM,OP_NONE)
- || ST_SYNTAX(OP_SHIMM,OP_LIMM,OP_SHIMM)
- || ST_SYNTAX(OP_SHIMM,OP_SHIMM,OP_SHIMM)
- || (ST_SYNTAX(OP_LIMM,OP_REG,OP_NONE) && (insn[0] & 511) == 0)
- || ST_SYNTAX(OP_REG,OP_REG,OP_SHIMM)
- || ST_SYNTAX(OP_REG,OP_SHIMM,OP_SHIMM)
- || ST_SYNTAX(OP_SHIMM,OP_REG,OP_SHIMM)
- || ST_SYNTAX(OP_LIMM,OP_SHIMM,OP_SHIMM)
- || ST_SYNTAX(OP_LIMM,OP_SHIMM,OP_NONE)
- || ST_SYNTAX(OP_LIMM,OP_REG,OP_SHIMM)))
- *invalid = 1;
- return 0;
+ if (!((ST_SYNTAX (OP_REG, OP_REG, OP_NONE) && (insn[0] & 511) == 0) || ST_SYNTAX (OP_REG, OP_LIMM, OP_NONE) || (ST_SYNTAX (OP_SHIMM, OP_REG, OP_NONE) && (insn[0] & 511) == 0) || (ST_SYNTAX (OP_SHIMM, OP_SHIMM, OP_NONE) && (insn[0] & 511) == 0) || ST_SYNTAX (OP_SHIMM, OP_LIMM, OP_NONE) || ST_SYNTAX (OP_SHIMM, OP_LIMM, OP_SHIMM) || ST_SYNTAX (OP_SHIMM, OP_SHIMM, OP_SHIMM) || (ST_SYNTAX (OP_LIMM, OP_REG, OP_NONE) && (insn[0] & 511) == 0) || ST_SYNTAX (OP_REG, OP_REG, OP_SHIMM) || ST_SYNTAX (OP_REG, OP_SHIMM, OP_SHIMM) || ST_SYNTAX (OP_SHIMM, OP_REG, OP_SHIMM) || ST_SYNTAX (OP_LIMM, OP_SHIMM, OP_SHIMM) || ST_SYNTAX (OP_LIMM, OP_SHIMM, OP_NONE) || ST_SYNTAX (OP_LIMM, OP_REG, OP_SHIMM))) {
+ *invalid = 1;
+ }
+ return 0;
}
int
@@ -1671,8 +1665,9 @@ arc_limm_fixup_adjust (arc_insn insn)
(I(2) | C(ARC_REG_SHIMM) | B(ARC_REG_LIMM)))
{
retval = insn & 0x1ff;
- if (retval & 0x100) /* Sign extend 9 bit offset. */
- retval |= ~0x1ff;
+ if (retval & 0x100) { /* Sign extend 9 bit offset. */
+ retval |= ~0x1ff;
+ }
}
return -retval; /* Negate offset for return. */
}
@@ -1694,9 +1689,10 @@ insert_st_syntax (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
if (addrwb_p)
{
- if (ls_operand[LS_BASE] != OP_REG)
- *errmsg = _("address writeback not allowed");
- insn |= addrwb_p;
+ if (ls_operand[LS_BASE] != OP_REG) {
+ *errmsg = _ ("address writeback not allowed");
+ }
+ insn |= addrwb_p;
}
return insn;
}
@@ -1721,15 +1717,16 @@ insert_st_syntax (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
/* Try to salvage this syntax. */
if (shimm & 0x1) /* Odd shimms won't work. */
{
- if (limm_p) /* Do we have a limm already? */
- *errmsg = _("impossible store");
- limm_p = 1;
- limm = shimm;
- shimm = 0;
- shimm_p = 0;
- insn = insn & ~(B(-1) | 511);
- insn |= B(ARC_REG_LIMM);
- ls_operand[LS_BASE] = OP_LIMM;
+ if (limm_p) { /* Do we have a limm already? */
+ *errmsg = _ ("impossible store");
+ }
+ limm_p = 1;
+ limm = shimm;
+ shimm = 0;
+ shimm_p = 0;
+ insn = insn & ~(B (-1) | 511);
+ insn |= B (ARC_REG_LIMM);
+ ls_operand[LS_BASE] = OP_LIMM;
}
else
{
@@ -1739,38 +1736,29 @@ insert_st_syntax (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
ls_operand[LS_OFFSET] = OP_SHIMM;
}
}
- if (ST_SYNTAX (OP_SHIMM, OP_LIMM, OP_NONE))
- limm += arc_limm_fixup_adjust (insn);
- if (ST_SYNTAX (OP_LIMM, OP_SHIMM, OP_SHIMM) && (shimm * 2 == limm))
- {
- insn &= ~C (-1);
- limm_p = 0;
- limm = 0;
- insn |= C (ARC_REG_SHIMM);
- ls_operand[LS_VALUE] = OP_SHIMM;
+ if (ST_SYNTAX (OP_SHIMM, OP_LIMM, OP_NONE)) {
+ limm += arc_limm_fixup_adjust (insn);
}
- if (!( ST_SYNTAX (OP_REG,OP_REG,OP_NONE)
- || ST_SYNTAX (OP_REG,OP_LIMM,OP_NONE)
- || ST_SYNTAX (OP_REG,OP_REG,OP_SHIMM)
- || ST_SYNTAX (OP_REG,OP_SHIMM,OP_SHIMM)
- || (ST_SYNTAX (OP_SHIMM,OP_SHIMM,OP_NONE) && (shimm == 0))
- || ST_SYNTAX (OP_SHIMM,OP_LIMM,OP_NONE)
- || ST_SYNTAX (OP_SHIMM,OP_REG,OP_NONE)
- || ST_SYNTAX (OP_SHIMM,OP_REG,OP_SHIMM)
- || ST_SYNTAX (OP_SHIMM,OP_SHIMM,OP_SHIMM)
- || ST_SYNTAX (OP_LIMM,OP_SHIMM,OP_SHIMM)
- || ST_SYNTAX (OP_LIMM,OP_REG,OP_NONE)
- || ST_SYNTAX (OP_LIMM,OP_REG,OP_SHIMM)))
- *errmsg = _("st operand error");
- if (addrwb_p)
- {
- if (ls_operand[LS_BASE] != OP_REG)
- *errmsg = _("address writeback not allowed");
- insn |= addrwb_p;
+ if (ST_SYNTAX (OP_LIMM, OP_SHIMM, OP_SHIMM) && (shimm * 2 == limm)) {
+ insn &= ~C (-1);
+ limm_p = 0;
+ limm = 0;
+ insn |= C (ARC_REG_SHIMM);
+ ls_operand[LS_VALUE] = OP_SHIMM;
}
- if (ST_SYNTAX(OP_SHIMM,OP_REG,OP_NONE) && shimm)
- *errmsg = _("store value must be zero");
- return insn;
+ if (!(ST_SYNTAX (OP_REG, OP_REG, OP_NONE) || ST_SYNTAX (OP_REG, OP_LIMM, OP_NONE) || ST_SYNTAX (OP_REG, OP_REG, OP_SHIMM) || ST_SYNTAX (OP_REG, OP_SHIMM, OP_SHIMM) || (ST_SYNTAX (OP_SHIMM, OP_SHIMM, OP_NONE) && (shimm == 0)) || ST_SYNTAX (OP_SHIMM, OP_LIMM, OP_NONE) || ST_SYNTAX (OP_SHIMM, OP_REG, OP_NONE) || ST_SYNTAX (OP_SHIMM, OP_REG, OP_SHIMM) || ST_SYNTAX (OP_SHIMM, OP_SHIMM, OP_SHIMM) || ST_SYNTAX (OP_LIMM, OP_SHIMM, OP_SHIMM) || ST_SYNTAX (OP_LIMM, OP_REG, OP_NONE) || ST_SYNTAX (OP_LIMM, OP_REG, OP_SHIMM))) {
+ *errmsg = _ ("st operand error");
+ }
+ if (addrwb_p) {
+ if (ls_operand[LS_BASE] != OP_REG) {
+ *errmsg = _ ("address writeback not allowed");
+ }
+ insn |= addrwb_p;
+ }
+ if (ST_SYNTAX (OP_SHIMM, OP_REG, OP_NONE) && shimm) {
+ *errmsg = _ ("store value must be zero");
+ }
+ return insn;
}
/* Used in ld insns to do final syntax check. */
@@ -1802,11 +1790,12 @@ insert_ld_syntax (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
if (addrwb_p)
{
- if (ls_operand[LS_BASE] != OP_REG
- /* .as is not actually an address write-back. */
- && addrwb_p != 0xc00000)
- *errmsg = _("address writeback not allowed");
- insn |= addrwb_p;
+ if (ls_operand[LS_BASE] != OP_REG
+ /* .as is not actually an address write-back. */
+ && addrwb_p != 0xc00000) {
+ *errmsg = _ ("address writeback not allowed");
+ }
+ insn |= addrwb_p;
}
/* Fixme: We should hash define register names to their respective
@@ -1814,8 +1803,9 @@ insert_ld_syntax (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
if (0x20 <= ac_reg_num && ac_reg_num <= 0x3F)
{
- if (!((arc_ld_ext_mask >> (ac_reg_num - 32)) & 1))
- *errmsg = _("ld operand error: Instruction Error exception");
+ if (!((arc_ld_ext_mask >> (ac_reg_num - 32)) & 1)) {
+ *errmsg = _ ("ld operand error: Instruction Error exception");
+ }
}
/* Ravi: operand validity checks for the ARC700 */
@@ -1834,23 +1824,18 @@ insert_ld_syntax (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
/* do syntax check for ARCtangent-A4 'ld' insn */
if (!(test == I (1)))
{
- if ((ls_operand[LS_DEST] == OP_SHIMM || ls_operand[LS_BASE] == OP_SHIMM
- || ls_operand[LS_OFFSET] == OP_SHIMM))
- *errmsg = _("invalid load/shimm insn");
+ if ((ls_operand[LS_DEST] == OP_SHIMM || ls_operand[LS_BASE] == OP_SHIMM || ls_operand[LS_OFFSET] == OP_SHIMM)) {
+ *errmsg = _ ("invalid load/shimm insn");
+ }
}
- if (!(LD_SYNTAX(OP_REG,OP_REG,OP_NONE)
- || LD_SYNTAX(OP_REG,OP_REG,OP_REG)
- || LD_SYNTAX(OP_REG,OP_REG,OP_SHIMM)
- || (LD_SYNTAX(OP_REG,OP_LIMM,OP_REG) && !(test == I(1)))
- || (LD_SYNTAX(OP_REG,OP_REG,OP_LIMM) && !(test == I(1)))
- || LD_SYNTAX(OP_REG,OP_SHIMM,OP_SHIMM)
- || (LD_SYNTAX(OP_REG,OP_LIMM,OP_NONE) && (test == I(1)))))
- *errmsg = _("ld operand error");
- if (addrwb_p)
- {
- if (ls_operand[LS_BASE] != OP_REG)
- *errmsg = _("address writeback not allowed");
- insn |= addrwb_p;
+ if (!(LD_SYNTAX (OP_REG, OP_REG, OP_NONE) || LD_SYNTAX (OP_REG, OP_REG, OP_REG) || LD_SYNTAX (OP_REG, OP_REG, OP_SHIMM) || (LD_SYNTAX (OP_REG, OP_LIMM, OP_REG) && !(test == I (1))) || (LD_SYNTAX (OP_REG, OP_REG, OP_LIMM) && !(test == I (1))) || LD_SYNTAX (OP_REG, OP_SHIMM, OP_SHIMM) || (LD_SYNTAX (OP_REG, OP_LIMM, OP_NONE) && (test == I (1))))) {
+ *errmsg = _ ("ld operand error");
+ }
+ if (addrwb_p) {
+ if (ls_operand[LS_BASE] != OP_REG) {
+ *errmsg = _ ("address writeback not allowed");
+ }
+ insn |= addrwb_p;
}
return insn;
}
@@ -1868,20 +1853,14 @@ extract_ld_syntax (arc_insn *insn,
if (!(test == I(1)))
{
- if ((ls_operand[LS_DEST] == OP_SHIMM || ls_operand[LS_BASE] == OP_SHIMM
- || ls_operand[LS_OFFSET] == OP_SHIMM))
- *invalid = 1;
+ if ((ls_operand[LS_DEST] == OP_SHIMM || ls_operand[LS_BASE] == OP_SHIMM || ls_operand[LS_OFFSET] == OP_SHIMM)) {
+ *invalid = 1;
+ }
}
- if (!( (LD_SYNTAX (OP_REG, OP_REG, OP_NONE) && test == I (1))
- || LD_SYNTAX (OP_REG, OP_REG, OP_REG)
- || LD_SYNTAX (OP_REG, OP_REG, OP_SHIMM)
- || (LD_SYNTAX (OP_REG, OP_REG, OP_LIMM) && test != I (1))
- || (LD_SYNTAX (OP_REG, OP_LIMM, OP_REG) && test != I (1))
- || (LD_SYNTAX (OP_REG, OP_SHIMM, OP_NONE) && shimm == 0)
- || LD_SYNTAX (OP_REG, OP_SHIMM, OP_SHIMM)
- || (LD_SYNTAX (OP_REG, OP_LIMM, OP_NONE) && test == I (1))))
- *invalid = 1;
- return 0;
+ if (!((LD_SYNTAX (OP_REG, OP_REG, OP_NONE) && test == I (1)) || LD_SYNTAX (OP_REG, OP_REG, OP_REG) || LD_SYNTAX (OP_REG, OP_REG, OP_SHIMM) || (LD_SYNTAX (OP_REG, OP_REG, OP_LIMM) && test != I (1)) || (LD_SYNTAX (OP_REG, OP_LIMM, OP_REG) && test != I (1)) || (LD_SYNTAX (OP_REG, OP_SHIMM, OP_NONE) && shimm == 0) || LD_SYNTAX (OP_REG, OP_SHIMM, OP_SHIMM) || (LD_SYNTAX (OP_REG, OP_LIMM, OP_NONE) && test == I (1)))) {
+ *invalid = 1;
+ }
+ return 0;
}
static arc_insn
@@ -1900,11 +1879,12 @@ insert_ex_syntax (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
unsigned ac_reg_lo = X (insn, 24, 3);
unsigned ac_reg_num = (ac_reg_hi << 3) | ac_reg_lo;
- if (arc_user_mode_only && (ac_reg_num == 29 || ac_reg_num == 30))
- *errmsg = _("ex operand error: Privilege Violation exception");
- if (0x20 <= ac_reg_num && ac_reg_num <= 0x3F
- && !((arc_ld_ext_mask >> (ac_reg_num - 32)) & 1))
- *errmsg = _("ld operand error: Instruction Error exception");
+ if (arc_user_mode_only && (ac_reg_num == 29 || ac_reg_num == 30)) {
+ *errmsg = _ ("ex operand error: Privilege Violation exception");
+ }
+ if (0x20 <= ac_reg_num && ac_reg_num <= 0x3F && !((arc_ld_ext_mask >> (ac_reg_num - 32)) & 1)) {
+ *errmsg = _ ("ld operand error: Instruction Error exception");
+ }
}
return insn;
}
@@ -1921,9 +1901,10 @@ insert_shimmfinish (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
long value ATTRIBUTE_UNUSED,
const char **errmsg ATTRIBUTE_UNUSED)
{
- if (shimm_p)
- insn |= (shimm & ((1 << operand->bits) - 1)) << operand->shift;
- return insn;
+ if (shimm_p) {
+ insn |= (shimm & ((1 << operand->bits) - 1)) << operand->shift;
+ }
+ return insn;
}
/* Called at the end of processing normal insns (eg: add) to insert a limm
@@ -1957,25 +1938,25 @@ insert_jumpflags (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
long value,
const char **errmsg)
{
- if (!flag_p)
- *errmsg = _("jump flags, but no .f seen");
+ if (!flag_p) {
+ *errmsg = _ ("jump flags, but no .f seen");
- else if (!limm_p)
- *errmsg = _("jump flags, but no limm addr");
+ } else if (!limm_p) {
+ *errmsg = _ ("jump flags, but no limm addr");
- else if (limm & 0xfc000000)
- *errmsg = _("flag bits of jump address limm lost");
+ } else if (limm & 0xfc000000) {
+ *errmsg = _ ("flag bits of jump address limm lost");
- else if (limm & 0x03000000)
- *errmsg = _("attempt to set HR bits");
+ } else if (limm & 0x03000000) {
+ *errmsg = _ ("attempt to set HR bits");
- else if ((value & ((1 << operand->bits) - 1)) != value)
- *errmsg = _("bad jump flags value");
+ } else if ((value & ((1 << operand->bits) - 1)) != value) {
+ *errmsg = _ ("bad jump flags value");
+ }
- jumpflags_p = 1;
- limm = ((limm & ((1 << operand->shift) - 1))
- | ((value & ((1 << operand->bits) - 1)) << operand->shift));
- return insn;
+ jumpflags_p = 1;
+ limm = ((limm & ((1 << operand->shift) - 1)) | ((value & ((1 << operand->bits) - 1)) << operand->shift));
+ return insn;
}
/* Called at the end of unary operand macros to copy the B field to C. */
@@ -2004,51 +1985,55 @@ insert_reladdr (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
{
if (!arc_mach_a4 && ('h' == operand->fmt))
{
- if (value & 3)
- *errmsg = _("branch address not on 4 byte boundary");
+ if (value & 3) {
+ *errmsg = _ ("branch address not on 4 byte boundary");
+ }
- value = value >> 2;
- /* Insert least significant 9-bits. */
- insn |= (value & 0x1ff) << operand->shift;
- /* Insert most significant 10-bits. */
- insn |= ((value >> 9) & 0x3ff) << 6;
+ value = value >> 2;
+ /* Insert least significant 9-bits. */
+ insn |= (value & 0x1ff) << operand->shift;
+ /* Insert most significant 10-bits. */
+ insn |= ((value >> 9) & 0x3ff) << 6;
}
else if (!arc_mach_a4 && ('H' == operand->fmt))
{
- if (value & 3)
- *errmsg = _("branch address not on 4 byte boundary");
+ if (value & 3) {
+ *errmsg = _ ("branch address not on 4 byte boundary");
+ }
- value = value >> 2;
- /* Insert least significant 9-bits. */
- insn |= (value & 0x1ff) << operand->shift;
- /* Insert next least significant 10-bits. */
- insn |= ((value >> 9) & 0x3ff) << 6;
- /* Insert most significant 4-bits. */
- insn |= (value >> 19) & 0xf;
+ value = value >> 2;
+ /* Insert least significant 9-bits. */
+ insn |= (value & 0x1ff) << operand->shift;
+ /* Insert next least significant 10-bits. */
+ insn |= ((value >> 9) & 0x3ff) << 6;
+ /* Insert most significant 4-bits. */
+ insn |= (value >> 19) & 0xf;
}
else if (!arc_mach_a4 && ('i' == operand->fmt))
{
- if (value & 1)
- *errmsg = _("branch address not on 2 byte boundary");
+ if (value & 1) {
+ *errmsg = _ ("branch address not on 2 byte boundary");
+ }
- value = value >> 1;
- /* Insert least significant 10-bits. */
- insn |= (value & 0x3ff) << operand->shift;
- /* Insert most significant 10-bits. */
- insn |= ((value >> 10) & 0x3ff) << 6;
+ value = value >> 1;
+ /* Insert least significant 10-bits. */
+ insn |= (value & 0x3ff) << operand->shift;
+ /* Insert most significant 10-bits. */
+ insn |= ((value >> 10) & 0x3ff) << 6;
}
else if (!arc_mach_a4 && ('I' == operand->fmt))
{
- if (value & 1)
- *errmsg = _("branch address not on 2 byte boundary");
+ if (value & 1) {
+ *errmsg = _ ("branch address not on 2 byte boundary");
+ }
- value = value >> 1;
- /* Insert least significant 10-bits. */
- insn |= (value & 0x3ff) << operand->shift;
- /* Insert next least significant 10-bits. */
- insn |= ((value >> 10) & 0x3ff) << 6;
- /* Insert most significant 4-bits. */
- insn |= (value >> 20) & 0xf;
+ value = value >> 1;
+ /* Insert least significant 10-bits. */
+ insn |= (value & 0x3ff) << operand->shift;
+ /* Insert next least significant 10-bits. */
+ insn |= ((value >> 10) & 0x3ff) << 6;
+ /* Insert most significant 4-bits. */
+ insn |= (value >> 20) & 0xf;
}
else if (!arc_mach_a4 && ('d' == operand->fmt))
{
@@ -2072,22 +2057,25 @@ insert_reladdr (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
else if (!arc_mach_a4 && (('s' == operand->fmt) || ('S' == operand->fmt)
|| ('Z' == operand->fmt)))
{
- if (value & 1)
- *errmsg = _("branch address not on 2 byte boundary");
- insn |= ((value >> 1) & ((1 << operand->bits) - 1)) << operand->shift;
+ if (value & 1) {
+ *errmsg = _ ("branch address not on 2 byte boundary");
+ }
+ insn |= ((value >> 1) & ((1 << operand->bits) - 1)) << operand->shift;
}
else if (!arc_mach_a4 && ('W' == operand->fmt))
{
- if (value & 3)
- *errmsg = _("branch address not on 4 byte boundary");
- insn |= ((value >> 2) & ((1 << operand->bits) - 1)) << operand->shift;
+ if (value & 3) {
+ *errmsg = _ ("branch address not on 4 byte boundary");
+ }
+ insn |= ((value >> 2) & ((1 << operand->bits) - 1)) << operand->shift;
}
else
{
/* for ARCtangent-A4 */
- if (value & 3)
- *errmsg = _("branch address not on 4 byte boundary");
+ if (value & 3) {
+ *errmsg = _ ("branch address not on 4 byte boundary");
+ }
insn |= ((value >> 2) & ((1 << operand->bits) - 1)) << operand->shift;
}
return insn;
@@ -2120,10 +2108,11 @@ insert_absaddr (arc_insn insn,long *ex ATTRIBUTE_UNUSED,
/* If it is a jump and link, .jd must be specified. */
if (insn & R (-1, 9, 1))
{
- if (!nullify_p)
- insn |= 0x02 << 5; /* Default nullify to .jd. */
- else if (nullify != 0x02)
- *errmsg = _("must specify .jd or no nullify suffix");
+ if (!nullify_p) {
+ insn |= 0x02 << 5; /* Default nullify to .jd. */
+ } else if (nullify != 0x02) {
+ *errmsg = _ ("must specify .jd or no nullify suffix");
+ }
}
}
return insn;
@@ -2152,20 +2141,24 @@ lookup_register (int type, long regno)
while (ext_oper)
{
- if (ext_oper->operand.type == type && ext_oper->operand.value == regno)
- return (&ext_oper->operand);
- ext_oper = ext_oper->next;
+ if (ext_oper->operand.type == type && ext_oper->operand.value == regno) {
+ return (&ext_oper->operand);
+ }
+ ext_oper = ext_oper->next;
}
- if (type == REG || type == REG_AC)
- return &arc_reg_names[regno];
+ if (type == REG || type == REG_AC) {
+ return &arc_reg_names[regno];
+ }
- /* ??? This is a little slow and can be speeded up. */
- for (r = arc_reg_names, end = arc_reg_names + arc_reg_names_count;
- r < end; ++r)
- if (type == r->type && regno == r->value)
- return r;
- return 0;
+ /* ??? This is a little slow and can be speeded up. */
+ for (r = arc_reg_names, end = arc_reg_names + arc_reg_names_count;
+ r < end; ++r) {
+ if (type == r->type && regno == r->value) {
+ return r;
+ }
+ }
+ return 0;
}
/* As we're extracting registers, keep an eye out for the 'f' indicator
@@ -2198,15 +2191,16 @@ extract_reg (arc_insn *insn,
if ('a' != operand->fmt)
{
value = *insn & 511;
- if ((operand->flags & ARC_OPERAND_SIGNED)
- && (value & 256))
- value -= 512;
- if (!flagshimm_handled_p)
- flag_p = 0;
+ if ((operand->flags & ARC_OPERAND_SIGNED) && (value & 256)) {
+ value -= 512;
+ }
+ if (!flagshimm_handled_p) {
+ flag_p = 0;
+ }
flagshimm_handled_p = 1;
- }
- else
- value = 0;
+ } else {
+ value = 0;
+ }
}
else if (regno == ARC_REG_SHIMM_UPDATE)
{
@@ -2216,11 +2210,12 @@ extract_reg (arc_insn *insn,
if ('a' != operand->fmt)
{
value = *insn & 511;
- if ((operand->flags & ARC_OPERAND_SIGNED) && (value & 256))
- value -= 512;
- }
- else
- value = 0;
+ if ((operand->flags & ARC_OPERAND_SIGNED) && (value & 256)) {
+ value -= 512;
+ }
+ } else {
+ value = 0;
+ }
flag_p = 1;
flagshimm_handled_p = 1;
@@ -2232,8 +2227,9 @@ extract_reg (arc_insn *insn,
limm_p = 1;
/* If this is a jump instruction (j,jl), show new pc correctly. */
- if (0x07 == ((*insn & I(-1)) >> 27))
- value = (value & 0xffffff);
+ if (0x07 == ((*insn & I (-1)) >> 27)) {
+ value = (value & 0xffffff);
+ }
}
/* It's a register, set OPVAL (that's the only way we distinguish registers
@@ -2244,10 +2240,12 @@ extract_reg (arc_insn *insn,
op_type = OP_REG;
- if (!reg)
- return 0;
- if (opval != NULL)
- *opval = reg;
+ if (!reg) {
+ return 0;
+ }
+ if (opval != NULL) {
+ *opval = reg;
+ }
value = regno;
}
@@ -2259,8 +2257,9 @@ extract_reg (arc_insn *insn,
/* This is really a constant, but tell the caller it has a special
name. */
- if (reg != NULL && opval != NULL)
- *opval = reg;
+ if (reg != NULL && opval != NULL) {
+ *opval = reg;
+ }
}
switch (operand->fmt)
@@ -2272,11 +2271,12 @@ extract_reg (arc_insn *insn,
ls_operand[LS_BASE] = op_type;
break;
case 'c':
- if ((insn[0]& I(-1)) == I(2))
- ls_operand[LS_VALUE] = op_type;
- else
- ls_operand[LS_OFFSET] = op_type;
- break;
+ if ((insn[0] & I (-1)) == I (2)) {
+ ls_operand[LS_VALUE] = op_type;
+ } else {
+ ls_operand[LS_OFFSET] = op_type;
+ }
+ break;
case 'o': case 'O':
ls_operand[LS_OFFSET] = op_type;
break;
@@ -2298,18 +2298,21 @@ extract_flag (arc_insn *insn,
int f;
const struct arc_operand_value *val;
- if (flagshimm_handled_p)
- f = flag_p != 0;
- else
- f = (*insn & (1 << operand->shift)) != 0;
+ if (flagshimm_handled_p) {
+ f = flag_p != 0;
+ } else {
+ f = (*insn & (1 << operand->shift)) != 0;
+ }
/* There is no text for zero values. */
- if (f == 0)
- return 0;
+ if (f == 0) {
+ return 0;
+ }
flag_p = 1;
val = arc_opcode_lookup_suffix (operand, 1);
- if (opval != NULL && val != NULL)
- *opval = val;
+ if (opval != NULL && val != NULL) {
+ *opval = val;
+ }
return val?val->value:0;
}
@@ -2328,16 +2331,18 @@ extract_cond (arc_insn *insn,
long cond;
const struct arc_operand_value *val;
- if (flagshimm_handled_p)
- return 0;
+ if (flagshimm_handled_p) {
+ return 0;
+ }
cond = (*insn >> operand->shift) & ((1 << operand->bits) - 1);
val = arc_opcode_lookup_suffix (operand, cond);
/* Ignore NULL values of `val'. Several condition code values are
reserved for extensions. */
- if (opval != NULL && val != NULL)
- *opval = val;
+ if (opval != NULL && val != NULL) {
+ *opval = val;
+ }
return cond;
}
@@ -2354,9 +2359,9 @@ extract_reladdr (arc_insn *insn,
long addr;
addr = (*insn >> operand->shift) & ((1 << operand->bits) - 1);
- if ((operand->flags & ARC_OPERAND_SIGNED)
- && (addr & (1 << (operand->bits - 1))))
- addr -= 1 << operand->bits;
+ if ((operand->flags & ARC_OPERAND_SIGNED) && (addr & (1 << (operand->bits - 1)))) {
+ addr -= 1 << operand->bits;
+ }
return addr << 2;
}
@@ -2370,10 +2375,12 @@ extract_jumpflags (arc_insn *insn,
const struct arc_operand_value **opval ATTRIBUTE_UNUSED,
int *invalid)
{
- if (!flag_p || !limm_p)
- *invalid = 1;
- return ((flag_p && limm_p)
- ? (insn[1] >> operand->shift) & ((1 << operand->bits) -1): 0);
+ if (!flag_p || !limm_p) {
+ *invalid = 1;
+ }
+ return ((flag_p && limm_p)
+ ? (insn[1] >> operand->shift) & ((1 << operand->bits) - 1)
+ : 0);
}
/* Extract st insn's offset. */
@@ -2390,13 +2397,15 @@ extract_st_offset (arc_insn *insn,
if (ls_operand[LS_VALUE] != OP_SHIMM || ls_operand[LS_BASE] != OP_LIMM)
{
value = insn[0] & 511;
- if ((operand->flags & ARC_OPERAND_SIGNED) && (value & 256))
- value -= 512;
- if (value)
- ls_operand[LS_OFFSET] = OP_SHIMM;
- }
- else
- *invalid = 1;
+ if ((operand->flags & ARC_OPERAND_SIGNED) && (value & 256)) {
+ value -= 512;
+ }
+ if (value) {
+ ls_operand[LS_OFFSET] = OP_SHIMM;
+ }
+ } else {
+ *invalid = 1;
+ }
return value;
}
@@ -2416,10 +2425,12 @@ extract_ld_offset (arc_insn *insn,
if (test)
{
value = insn[0] & 511;
- if ((operand->flags & ARC_OPERAND_SIGNED) && (value & 256))
- value -= 512;
- if (value)
- ls_operand[LS_OFFSET] = OP_SHIMM;
+ if ((operand->flags & ARC_OPERAND_SIGNED) && (value & 256)) {
+ value -= 512;
+ }
+ if (value) {
+ ls_operand[LS_OFFSET] = OP_SHIMM;
+ }
return value;
}
@@ -2442,10 +2453,11 @@ extract_unopmacro (arc_insn *insn,
/* This misses the case where B == ARC_REG_SHIMM_UPDATE &&
C == ARC_REG_SHIMM (or vice versa). No big deal. Those insns will get
printed as "and"s. */
- if (((*insn >> ARC_SHIFT_REGB) & ARC_MASK_REG)
- != ((*insn >> ARC_SHIFT_REGC) & ARC_MASK_REG))
- if (invalid != NULL)
- *invalid = 1;
+ if (((*insn >> ARC_SHIFT_REGB) & ARC_MASK_REG) != ((*insn >> ARC_SHIFT_REGC) & ARC_MASK_REG)) {
+ if (invalid != NULL) {
+ *invalid = 1;
+ }
+ }
return 0;
}
@@ -4296,8 +4308,9 @@ arc_opcode_init_tables (int flags)
/* If initialization was already done but current cpu type is different
from the one for which initialization was done earlier, then do
initialization again */
- if (init_p && cpu_type != flags)
- init_p = 0;
+ if (init_p && cpu_type != flags) {
+ init_p = 0;
+ }
cpu_type = flags;
@@ -4315,10 +4328,11 @@ arc_opcode_init_tables (int flags)
/* Initialize operand map table for ARCtanget-A4 */
memset (arc_operand_map_a4, 0, sizeof (arc_operand_map_a4));
- for (i = 0; i < (int) ELEMENTS_IN (arc_operands_a4); ++i)
- arc_operand_map_a4[arc_operands_a4[i].fmt] = i;
+ for (i = 0; i < (int)ELEMENTS_IN (arc_operands_a4); ++i) {
+ arc_operand_map_a4[arc_operands_a4[i].fmt] = i;
+ }
- /* Set the pointers to operand table, operand map table */
+ /* Set the pointers to operand table, operand map table */
arc_operands = arc_operands_a4;
arc_operand_map = arc_operand_map_a4;
arc_reg_names = arc_reg_names_a4;
@@ -4331,10 +4345,11 @@ arc_opcode_init_tables (int flags)
/* Initialize operand map table for ARCompact */
memset (arc_operand_map_ac, 0, sizeof (arc_operand_map_ac));
- for (i = 0; i < (int) ELEMENTS_IN (arc_operands_ac); ++i)
- arc_operand_map_ac[arc_operands_ac[i].fmt] = i;
+ for (i = 0; i < (int)ELEMENTS_IN (arc_operands_ac); ++i) {
+ arc_operand_map_ac[arc_operands_ac[i].fmt] = i;
+ }
- /* Set the pointers to operand table, operand map table */
+ /* Set the pointers to operand table, operand map table */
arc_operands = arc_operands_ac;
arc_operand_map = arc_operand_map_ac;
@@ -4384,11 +4399,13 @@ arc_opcode_init_tables (int flags)
int
arc_opcode_supported (const struct arc_opcode *opcode)
{
- if (ARC_OPCODE_CPU (opcode->flags) == 0)
- return 1;
- if (ARC_OPCODE_CPU (opcode->flags) & ARC_HAVE_CPU (cpu_type))
- return 1;
- return 0;
+ if (ARC_OPCODE_CPU (opcode->flags) == 0) {
+ return 1;
+ }
+ if (ARC_OPCODE_CPU (opcode->flags) & ARC_HAVE_CPU (cpu_type)) {
+ return 1;
+ }
+ return 0;
}
@@ -4441,8 +4458,9 @@ arc_opcode_init_insert (void)
{
int i;
- for(i = 0; i < OPERANDS; i++)
- ls_operand[i] = OP_NONE;
+ for (i = 0; i < OPERANDS; i++) {
+ ls_operand[i] = OP_NONE;
+ }
flag_p = 0;
flagshimm_handled_p = 0;
@@ -4462,9 +4480,10 @@ arc_opcode_init_insert (void)
int
arc_opcode_limm_p (long *limmp)
{
- if (limmp)
- *limmp = limm;
- return limm_p;
+ if (limmp) {
+ *limmp = limm;
+ }
+ return limm_p;
}
@@ -4478,18 +4497,19 @@ arc_opcode_lookup_suffix (const struct arc_operand *type, int value)
struct arc_ext_operand_value *ext_oper = arc_ext_operands;
while (ext_oper)
{
- if (type == &arc_operands[ext_oper->operand.type]
- && value == ext_oper->operand.value)
- return (&ext_oper->operand);
- ext_oper = ext_oper->next;
+ if (type == &arc_operands[ext_oper->operand.type] && value == ext_oper->operand.value) {
+ return (&ext_oper->operand);
+ }
+ ext_oper = ext_oper->next;
}
/* ??? This is a little slow and can be speeded up. */
- for (v = arc_suffixes, end = arc_suffixes + arc_suffixes_count; v < end; ++v)
- if (type == &arc_operands[v->type]
- && value == v->value)
- return v;
- return 0;
+ for (v = arc_suffixes, end = arc_suffixes + arc_suffixes_count; v < end; ++v) {
+ if (type == &arc_operands[v->type] && value == v->value) {
+ return v;
+ }
+ }
+ return 0;
}
@@ -4634,21 +4654,23 @@ ac_get_load_sdasym_insn_type (arc_insn insn, int compact_insn_16)
{
/* ld */
case 0x10000000:
- if (((insn>>9) & 3) == 3)
- load_type = 0;
- else
- load_type = 1;
- break;
+ if (((insn >> 9) & 3) == 3) {
+ load_type = 0;
+ } else {
+ load_type = 1;
+ }
+ break;
- /* ldw */
+ /* ldw */
case 0x10000100:
- if (((insn>>9) & 3) == 3)
- load_type = 2;
- else
- load_type = 1;
- break;
+ if (((insn >> 9) & 3) == 3) {
+ load_type = 2;
+ } else {
+ load_type = 1;
+ }
+ break;
- /* ldb */
+ /* ldb */
case 0x10000080:
load_type = 1;
break;
@@ -4682,21 +4704,23 @@ ac_get_store_sdasym_insn_type (arc_insn insn,
{
/* st */
case 0x18000000:
- if (((insn>>3) & 3) == 3)
- store_type = 0;
- else
- store_type = 1;
- break;
+ if (((insn >> 3) & 3) == 3) {
+ store_type = 0;
+ } else {
+ store_type = 1;
+ }
+ break;
- /* stw */
+ /* stw */
case 0x18000004:
- if (((insn>>3) & 3) == 3)
- store_type = 2;
- else
- store_type = 1;
- break;
+ if (((insn >> 3) & 3) == 3) {
+ store_type = 2;
+ } else {
+ store_type = 1;
+ }
+ break;
- /* stb */
+ /* stb */
case 0x18000002:
store_type = 1;
break;
@@ -4917,14 +4941,14 @@ get_ext_suffix (char *s, char field)
ctype = arc_mach_a4 ? COND : COND_AC;
break;
} /* end switch(field) */
- if(ctype == 0)
- ctype = arc_mach_a4 ? COND : COND_AC;
- while (suffix){
- if ((suffix->operand.type == ctype)
- && !strcmp(s,suffix->operand.name)){
- return(&suffix->operand);
+ if (ctype == 0) {
+ ctype = arc_mach_a4 ? COND : COND_AC;
}
- suffix = suffix->next;
+ while (suffix) {
+ if ((suffix->operand.type == ctype) && !strcmp (s, suffix->operand.name)) {
+ return (&suffix->operand);
+ }
+ suffix = suffix->next;
} /* end while(suffix) */
return NULL;
@@ -4945,9 +4969,9 @@ arc_aux_reg_name (int regVal)
for (i= arc_reg_names_count ; i > 0 ; i--)
{
- if ((arc_reg_names[i].type == AUXREG_AC)
- && (arc_reg_names[i].value == regVal ))
- return arc_reg_names[i].name;
+ if ((arc_reg_names[i].type == AUXREG_AC) && (arc_reg_names[i].value == regVal)) {
+ return arc_reg_names[i].name;
+ }
}
return NULL;
diff --git a/libr/asm/arch/arc/gnu/arcompact-dis.c b/libr/asm/arch/arc/gnu/arcompact-dis.c
index 19b207aecb..329d9b6579 100644
--- a/libr/asm/arch/arc/gnu/arcompact-dis.c
+++ b/libr/asm/arch/arc/gnu/arcompact-dis.c
@@ -277,40 +277,45 @@ static short int enable_insn_stream = 0;
static const char *
core_reg_name(struct arcDisState *state, int val)
{
- if (state->coreRegName)
- return (*state->coreRegName)(state->_this, val);
- return 0;
+ if (state->coreRegName) {
+ return (*state->coreRegName) (state->_this, val);
+ }
+ return 0;
}
static const char *
aux_reg_name(struct arcDisState *state, int val)
{
- if (state->auxRegName)
- return (*state->auxRegName)(state->_this, val);
- return 0;
+ if (state->auxRegName) {
+ return (*state->auxRegName) (state->_this, val);
+ }
+ return 0;
}
static const char *
cond_code_name(struct arcDisState *state, int val)
{
- if (state->condCodeName)
- return (*state->condCodeName)(state->_this, val);
- return 0;
+ if (state->condCodeName) {
+ return (*state->condCodeName) (state->_this, val);
+ }
+ return 0;
}
static const char *
instruction_name(struct arcDisState *state, int op1, int op2, int *flags)
{
- if (state->instName)
- return (*state->instName)(state->_this, op1, op2, flags);
- return 0;
+ if (state->instName) {
+ return (*state->instName) (state->_this, op1, op2, flags);
+ }
+ return 0;
}
static void
mwerror(struct arcDisState *state, const char *msg)
{
- if (state->err != 0)
- (*state->err)(state->_this, (msg));
+ if (state->err != 0) {
+ (*state->err) (state->_this, (msg));
+ }
}
static const char *
@@ -344,36 +349,37 @@ my_sprintf (struct arcDisState *state, char *buf, const char*format, ...)
p = format;
regMap[0] = 0;
regMap[1] = 0;
- while (1)
- switch(*p++) {
- case 0: goto DOCOMM; /*(return) */
- default:
- *bp++ = p[-1];
- break;
- case '%':
- size = 0;
- leading_zero = 0;
- RETRY: ;
- switch(*p++)
- {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- {
- /* size. */
- size = p[-1]-'0';
- if (size == 0) leading_zero = 1; /* e.g. %08x */
- while (*p >= '0' && *p <= '9')
- size = size*10+*p-'0', p++;
- goto RETRY;
- }
+ while (1) {
+ switch (*p++) {
+ case 0: goto DOCOMM; /*(return) */
+ default:
+ *bp++ = p[-1];
+ break;
+ case '%':
+ size = 0;
+ leading_zero = 0;
+ RETRY:;
+ switch (*p++) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9': {
+ /* size. */
+ size = p[-1] - '0';
+ if (size == 0) {
+ leading_zero = 1; /* e.g. %08x */
+ }
+ while (*p >= '0' && *p <= '9') {
+ size = size * 10 + *p - '0', p++;
+ }
+ goto RETRY;
+ }
#define inc_bp() bp = bp+strlen(bp)
case 'h':
@@ -385,32 +391,41 @@ my_sprintf (struct arcDisState *state, char *buf, const char*format, ...)
* We add underscores for easy reading.
*/
#define CDT_DEBUG
- if (u > 65536)
+ if (u > 65536) {
#ifndef CDT_DEBUG
sprintf(bp,"0x%x_%04x",u >> 16, u & 0xffff);
#else
sprintf(bp,"0x%08x",u);
#endif // CDT_DEBUG
- else
- sprintf(bp,"0x%x",u);
+ } else {
+ sprintf (bp, "0x%x", u);
+ }
inc_bp();
}
break;
case 'X': case 'x':
{
int val = va_arg(ap,int);
- if (size != 0)
- if (leading_zero) sprintf(bp,"%0*x",size,val);
- else sprintf(bp,"%*x",size,val);
- else sprintf(bp,"%x",val);
+ if (size != 0) {
+ if (leading_zero) {
+ sprintf (bp, "%0*x", size, val);
+ } else {
+ sprintf (bp, "%*x", size, val);
+ }
+ } else {
+ sprintf (bp, "%x", val);
+ }
inc_bp();
}
break;
case 'd':
{
int val = va_arg(ap,int);
- if (size != 0) sprintf(bp,"%*d",size,val);
- else sprintf(bp,"%d",val);
+ if (size != 0) {
+ sprintf (bp, "%*d", size, val);
+ } else {
+ sprintf (bp, "%d", val);
+ }
inc_bp();
}
break;
@@ -435,8 +450,11 @@ my_sprintf (struct arcDisState *state, char *buf, const char*format, ...)
{
const char *ext;
ext = core_reg_name(state, val);
- if (ext) sprintf(bp, "%s", ext);
- else sprintf(bp,"r%d",val);
+ if (ext) {
+ sprintf (bp, "%s", ext);
+ } else {
+ sprintf (bp, "r%d", val);
+ }
}break;
}
inc_bp();
@@ -448,14 +466,16 @@ my_sprintf (struct arcDisState *state, char *buf, const char*format, ...)
int val = va_arg(ap,int);
char *ret;
ret = arc_aux_reg_name(val);
- if(ret)
- sprintf(bp,"%s",ret);
- else
- {
- const char *ext;
- ext = aux_reg_name(state, val);
- if (ext) sprintf(bp, "%s", ext);
- else my_sprintf(state, bp,"%h",val);
+ if (ret) {
+ sprintf (bp, "%s", ret);
+ } else {
+ const char *ext;
+ ext = aux_reg_name (state, val);
+ if (ext) {
+ sprintf (bp, "%s", ext);
+ } else {
+ my_sprintf (state, bp, "%h", val);
+ }
}
inc_bp();
@@ -513,8 +533,8 @@ my_sprintf (struct arcDisState *state, char *buf, const char*format, ...)
fprintf(stderr,"?? format %c\n",p[-1]);
break;
}
- }
-
+ }
+ }
DOCOMM:
*bp = 0;
@@ -540,34 +560,46 @@ write_instr_name_(struct arcDisState *state,
int addrWriteBack,
int directMem)
{
- if(!instrName)
- return;
- strncpy(state->instrBuffer, instrName, sizeof(state->instrBuffer)-1);
- if (cond > 0)
- {
- int condlim = 0; /* condition code limit*/
- const char *cc = 0;
- if (!condCodeIsPartOfName) strcat(state->instrBuffer, ".");
- condlim = 18;
- if (cond < condlim)
- cc = condName[cond];
- else
- cc = cond_code_name(state, cond);
- if (!cc) cc = "???";
- strcat(state->instrBuffer, cc);
+ if (!instrName) {
+ return;
+ }
+ strncpy (state->instrBuffer, instrName, sizeof (state->instrBuffer) - 1);
+ if (cond > 0) {
+ int condlim = 0; /* condition code limit*/
+ const char *cc = 0;
+ if (!condCodeIsPartOfName) {
+ strcat (state->instrBuffer, ".");
+ }
+ condlim = 18;
+ if (cond < condlim) {
+ cc = condName[cond];
+ } else {
+ cc = cond_code_name (state, cond);
+ }
+ if (!cc) {
+ cc = "???";
+ }
+ strcat (state->instrBuffer, cc);
}
- if (flag) strcat(state->instrBuffer, ".f");
- if (state->nullifyMode)
- if (strstr(state->instrBuffer, ".d") == NULL)
- strcat(state->instrBuffer, ".d");
- if (signExtend) strcat(state->instrBuffer, ".x");
- switch (addrWriteBack)
- {
+ if (flag) {
+ strcat (state->instrBuffer, ".f");
+ }
+ if (state->nullifyMode) {
+ if (strstr (state->instrBuffer, ".d") == NULL) {
+ strcat (state->instrBuffer, ".d");
+ }
+ }
+ if (signExtend) {
+ strcat (state->instrBuffer, ".x");
+ }
+ switch (addrWriteBack) {
case 1: strcat(state->instrBuffer, ".a"); break;
case 2: strcat(state->instrBuffer, ".ab"); break;
case 3: strcat(state->instrBuffer, ".as"); break;
}
- if (directMem) strcat(state->instrBuffer, ".di");
+ if (directMem) {
+ strcat (state->instrBuffer, ".di");
+ }
}
#define write_instr_name() {\
@@ -625,9 +657,10 @@ bfd_getm32_ac (data)
static int
sign_extend (int value, int bits)
{
- if (BIT(value, (bits-1)))
- value |= (0xffffffff << bits);
- return value;
+ if (BIT (value, (bits - 1))) {
+ value |= (0xffffffff << bits);
+ }
+ return value;
}
/* dsmOneArcInst - This module is used to identify the instruction
@@ -673,21 +706,24 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
state->sourceType = ARC_UNDEFINED;
/* ARCtangent-A5 basecase instruction and little-endian mode */
- if ((info->endian == BFD_ENDIAN_LITTLE) && (state->instructionLen == 4))
- state->words[0] = bfd_getm32(state->words[0]);
+ if ((info->endian == BFD_ENDIAN_LITTLE) && (state->instructionLen == 4)) {
+ state->words[0] = bfd_getm32 (state->words[0]);
+ }
if (state->instructionLen == 4)
{
- if (!NEXT_WORD(0))
- return 0;
- /* Get the major opcode of the ARCtangent-A5 32-bit instruction. */
- state->_opcode = OPCODE(state->words[0]);
+ if (!NEXT_WORD (0)) {
+ return 0;
+ }
+ /* Get the major opcode of the ARCtangent-A5 32-bit instruction. */
+ state->_opcode = OPCODE (state->words[0]);
}
else
{
/* ARCompact 16-bit instruction */
- if (!NEXT_WORD_AC(0))
- return 0;
+ if (!NEXT_WORD_AC (0)) {
+ return 0;
+ }
/* Get the major opcode of the ARCompact 16-bit instruction. */
state->_opcode = OPCODE_AC(state->words[0]);
}
@@ -726,11 +762,12 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
switch (BITS(state->words[0],16,16))
{
case 0:
- if (!instrName)
- instrName = "bl";
- decodingClass = 13;
- condCodeIsPartOfName = 1;
- break;
+ if (!instrName) {
+ instrName = "bl";
+ }
+ decodingClass = 13;
+ condCodeIsPartOfName = 1;
+ break;
case 1:
switch (BITS(state->words[0],0,3))
{
@@ -837,11 +874,13 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
instrName = "j";
case 34:
case 35:
- if (!instrName) instrName = "jl";
- decodingClass = 4;
- condCodeIsPartOfName = 1;
- state->isBranch = 1;
- break;
+ if (!instrName) {
+ instrName = "jl";
+ }
+ decodingClass = 4;
+ condCodeIsPartOfName = 1;
+ state->isBranch = 1;
+ break;
case 40:
instrName = "lp";
decodingClass = 11;
@@ -884,17 +923,19 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
{
case 1 : instrName = "sleep"; decodingClass = 32; break;
case 2 :
- if((info->mach) == ARC_MACH_ARC7)
- instrName = "trap0";
- else
- instrName = "swi";
- break;
+ if ((info->mach) == ARC_MACH_ARC7) {
+ instrName = "trap0";
+ } else {
+ instrName = "swi";
+ }
+ break;
case 3:
- if(BITS(state->words[0],22,23) == 1)
- instrName = "sync" ;
+ if (BITS (state->words[0], 22, 23) == 1) {
+ instrName = "sync";
+ }
- break;
+ break;
case 4 : instrName = "rtie" ; break;
case 5 : instrName = "brk"; break;
default:
@@ -2028,15 +2069,24 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
switch(BITS(state->words[0],5,7))
{
case 0 : instrName = "j_s";
- case 2 : if (!instrName) instrName = "jl_s";
- state->isBranch = 1;
- state->nullifyMode = BR_exec_when_no_jump;
- break;
- case 1 : if (!instrName) instrName = "j_s.d";
- case 3 : if (!instrName) instrName = "jl_s.d";
- state->isBranch = 1;
- state->nullifyMode = BR_exec_always;
- break;
+ case 2 :
+ if (!instrName) {
+ instrName = "jl_s";
+ }
+ state->isBranch = 1;
+ state->nullifyMode = BR_exec_when_no_jump;
+ break;
+ case 1 :
+ if (!instrName) {
+ instrName = "j_s.d";
+ }
+ case 3 :
+ if (!instrName) {
+ instrName = "jl_s.d";
+ }
+ state->isBranch = 1;
+ state->nullifyMode = BR_exec_always;
+ break;
case 6 : instrName = "sub_s.ne";
decodingClass = 35;
break;
@@ -2051,19 +2101,24 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
case 4: instrName = "jeq_s [blink]";
- case 5: if (!instrName) instrName = "jne_s [blink]";
+ case 5:
+ if (!instrName) {
+ instrName = "jne_s [blink]";
+ }
case 6:
- if (!instrName)
- instrName = "j_s [blink]";
- state->isBranch = 1;
- state->nullifyMode = BR_exec_when_no_jump;
- break;
+ if (!instrName) {
+ instrName = "j_s [blink]";
+ }
+ state->isBranch = 1;
+ state->nullifyMode = BR_exec_when_no_jump;
+ break;
case 7:
- if (!instrName)
- instrName = "j_s.d [blink]";
- state->isBranch = 1;
- state->nullifyMode = BR_exec_always;
- break;
+ if (!instrName) {
+ instrName = "j_s.d [blink]";
+ }
+ state->isBranch = 1;
+ state->nullifyMode = BR_exec_always;
+ break;
default:
instrName = "??? (2[3])";
state->flow = invalid_instr;
@@ -2178,11 +2233,12 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
case 3: instrName = "stb_s"; break;
case 4: instrName = "add_s"; break;
case 5:
- if (!BITS(state->words[0],8,8))
- instrName = "add_s";
- else
- instrName = "sub_s";
- break;
+ if (!BITS (state->words[0], 8, 8)) {
+ instrName = "add_s";
+ } else {
+ instrName = "sub_s";
+ }
+ break;
case 6: instrName = "pop_s"; decodingClass = 31; break;
case 7: instrName = "push_s"; decodingClass = 31; break;
default:
@@ -2219,19 +2275,21 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
case op_ADD_CMP:
/* ARCompact 16-bit Add/compare immediate */
decodingClass = 21; /* default for major opcode 0x1c ... */
- if (BIT(state->words[0],7))
- instrName = "cmp_s";
- else
- instrName = "add_s";
+ if (BIT (state->words[0], 7)) {
+ instrName = "cmp_s";
+ } else {
+ instrName = "add_s";
+ }
break;
case op_BR_S:
/* ARCompact 16-bit Branch conditionally on reg z/nz */
decodingClass = 25; /* Default for BR_S instruction ... */
- if (BIT(state->words[0],7))
- instrName = "brne_s";
- else
- instrName = "breq_s";
+ if (BIT (state->words[0], 7)) {
+ instrName = "brne_s";
+ } else {
+ instrName = "breq_s";
+ }
state->isBranch = 1;
break;
@@ -2278,30 +2336,29 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
* instead of all over this crazy switch case. */
if (state->flow == invalid_instr)
{
- if (!((state->_opcode == op_SIMD) && enable_simd))
- instrName = instruction_name(state,state->_opcode,
- state->words[0],
- &flags);
+ if (!((state->_opcode == op_SIMD) && enable_simd)) {
+ instrName = instruction_name (state, state->_opcode,
+ state->words[0],
+ &flags);
+ }
- if (state->instructionLen == 2)
- {
- switch (flags)
- {
- case AC_SYNTAX_3OP:
- decodingClass = 22;
- break;
- case AC_SYNTAX_2OP:
- decodingClass = 14;
- break;
- case AC_SYNTAX_1OP:
- decodingClass = 36;
- break;
- case AC_SYNTAX_NOP:
- decodingClass = 26;
- break;
- default:
- mwerror(state, "Invalid syntax class\n");
- }
+ if (state->instructionLen == 2) {
+ switch (flags) {
+ case AC_SYNTAX_3OP:
+ decodingClass = 22;
+ break;
+ case AC_SYNTAX_2OP:
+ decodingClass = 14;
+ break;
+ case AC_SYNTAX_1OP:
+ decodingClass = 36;
+ break;
+ case AC_SYNTAX_NOP:
+ decodingClass = 26;
+ break;
+ default:
+ mwerror (state, "Invalid syntax class\n");
+ }
}
else
{
@@ -2364,8 +2421,9 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
else
{
FIELD_B();
- if (!fieldBisReg)
- fieldB = fieldC;
+ if (!fieldBisReg) {
+ fieldB = fieldC;
+ }
}
CHECK_FIELD_A();
CHECK_FLAG();
@@ -2401,11 +2459,12 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
/* Say ea is not present, so only one of us will do the
name lookup. */
state->_offset += fieldB, state->_ea_present = 0;
- if (is_limm)
- fieldAisReg = fieldA = 0;
- else
- fieldA = fieldB;
- CHECK_FLAG();
+ if (is_limm) {
+ fieldAisReg = fieldA = 0;
+ } else {
+ fieldA = fieldB;
+ }
+ CHECK_FLAG();
break;
case 3:
@@ -2422,12 +2481,11 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
{
fieldAisReg = fieldA = 0;
FIELD_C();
- if (BIT(state->words[0],5))
- fieldCisReg = 0;
- else if (fieldC == 62)
- {
- fieldCisReg = 0;
- fieldC = fieldB;
+ if (BIT (state->words[0], 5)) {
+ fieldCisReg = 0;
+ } else if (fieldC == 62) {
+ fieldCisReg = 0;
+ fieldC = fieldB;
}
}
else
@@ -2464,12 +2522,16 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
FIELD_B();
CHECK_FLAG();
- if (BITS(state->words[0],22,23) == 1 )
- fieldCisReg = 0;
- if (fieldCisReg) state->ea_reg1 = fieldC;
- /* field C is either a shimm (same as fieldC) or limm (different!) */
- /* Say ea is not present, so only one of us will do the name lookup. */
- else state->_offset += fieldB, state->_ea_present = 0;
+ if (BITS (state->words[0], 22, 23) == 1) {
+ fieldCisReg = 0;
+ }
+ if (fieldCisReg) {
+ state->ea_reg1 = fieldC;
+ /* field C is either a shimm (same as fieldC) or limm (different!) */
+ /* Say ea is not present, so only one of us will do the name lookup. */
+ } else {
+ state->_offset += fieldB, state->_ea_present = 0;
+ }
write_instr_name();
WRITE_FORMAT_x(B);
@@ -2490,8 +2552,9 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
if (is_limm)
{
FIELD_B();
- if (!fieldBisReg)
- fieldB = fieldC;
+ if (!fieldBisReg) {
+ fieldB = fieldC;
+ }
}
else
{
@@ -2513,10 +2576,13 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
if (subopcode == 3)
CHECK_COND();
- if (fieldCisReg) state->ea_reg1 = fieldC;
- /* field C is either a shimm (same as fieldC) or limm (different!) */
- /* Say ea is not present, so only one of us will do the name lookup. */
- else state->_offset += fieldB, state->_ea_present = 0;
+ if (fieldCisReg) {
+ state->ea_reg1 = fieldC;
+ /* field C is either a shimm (same as fieldC) or limm (different!) */
+ /* Say ea is not present, so only one of us will do the name lookup. */
+ } else {
+ state->_offset += fieldB, state->_ea_present = 0;
+ }
write_instr_name();
if (mul)
@@ -2617,11 +2683,12 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
strcat(formatString,
IS_REG(C)?"[%r]":"%s"); /* address/label name */
- if (IS_REG(C))
- my_sprintf(state, state->operandBuffer, formatString, fieldC);
- else
- my_sprintf(state, state->operandBuffer, formatString,
- post_address(state, fieldC));
+ if (IS_REG (C)) {
+ my_sprintf (state, state->operandBuffer, formatString, fieldC);
+ } else {
+ my_sprintf (state, state->operandBuffer, formatString,
+ post_address (state, fieldC));
+ }
break;
case 5:
@@ -2640,19 +2707,30 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
if (is_limm)
{
FIELD_C();
- if (!fieldCisReg)
- fieldC = fieldB;
+ if (!fieldCisReg) {
+ fieldC = fieldB;
+ }
}
else
{
CHECK_FIELD_C();
}
- if (dbg) printf("5:b reg %d %d c reg %d %d \n",
- fieldBisReg,fieldB,fieldCisReg,fieldC);
+ if (dbg) {
+ printf ("5:b reg %d %d c reg %d %d \n",
+ fieldBisReg, fieldB, fieldCisReg, fieldC);
+ }
state->_offset = 0;
state->_ea_present = 1;
- if (fieldBisReg) state->ea_reg1 = fieldB; else state->_offset += fieldB;
- if (fieldCisReg) state->ea_reg2 = fieldC; else state->_offset += fieldC;
+ if (fieldBisReg) {
+ state->ea_reg1 = fieldB;
+ } else {
+ state->_offset += fieldB;
+ }
+ if (fieldCisReg) {
+ state->ea_reg2 = fieldC;
+ } else {
+ state->_offset += fieldC;
+ }
state->_mem_load = 1;
directMem = BIT(state->words[0],15);
@@ -2671,23 +2749,22 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
write_instr_name();
/* Check for prefetch or ld 0,...*/
- if(IS_REG(A))
- WRITE_FORMAT_x_COMMA_LB(A);
- else
- {
- strcat(formatString,"%*");
- WRITE_FORMAT_LB();
+ if (IS_REG (A)) {
+ WRITE_FORMAT_x_COMMA_LB (A);
+ } else {
+ strcat (formatString, "%*");
+ WRITE_FORMAT_LB ();
}
+ if (fieldBisReg || fieldB != 0) {
+ WRITE_FORMAT_x (B);
+ } else {
+ fieldB = fieldC;
+ }
- if (fieldBisReg || fieldB != 0)
- WRITE_FORMAT_x(B);
- else
- fieldB = fieldC;
-
- WRITE_FORMAT_COMMA_x_RB(C);
- my_sprintf(state, state->operandBuffer, formatString, fieldA, fieldB, fieldC);
- break;
+ WRITE_FORMAT_COMMA_x_RB (C);
+ my_sprintf (state, state->operandBuffer, formatString, fieldA, fieldB, fieldC);
+ break;
case 6:
/* LD instruction. */
@@ -2704,30 +2781,35 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
fieldC = FIELDD9(state->words[0]);
fieldCisReg = 0;
- if (dbg) eprintf("6:b reg %d %d c 0x%x \n",
- fieldBisReg,fieldB,fieldC);
+ if (dbg) {
+ eprintf ("6:b reg %d %d c 0x%x \n",
+ fieldBisReg, fieldB, fieldC);
+ }
state->_ea_present = 1;
state->_offset = fieldC;
state->_mem_load = 1;
- if (fieldBisReg) state->ea_reg1 = fieldB;
- /* field B is either a shimm (same as fieldC) or limm (different!) */
- /* Say ea is not present, so only one of us will do the name lookup. */
- else state->_offset += fieldB, state->_ea_present = 0;
+ if (fieldBisReg) {
+ state->ea_reg1 = fieldB;
+ /* field B is either a shimm (same as fieldC) or limm (different!) */
+ /* Say ea is not present, so only one of us will do the name lookup. */
+ } else {
+ state->_offset += fieldB, state->_ea_present = 0;
+ }
directMem = BIT(state->words[0],11);
/* Check if address writeback is allowed before decoding the
address writeback field of a load instruction.*/
- if (fieldBisReg && (fieldB != 62))
- addrWriteBack = BITS(state->words[0],9,10);
+ if (fieldBisReg && (fieldB != 62)) {
+ addrWriteBack = BITS (state->words[0], 9, 10);
+ }
signExtend = BIT(state->words[0],6);
write_instr_name();
- if(IS_REG(A))
- WRITE_FORMAT_x_COMMA_LB(A);
- else
- {
- strcat(formatString,"%*");
- WRITE_FORMAT_LB();
+ if (IS_REG (A)) {
+ WRITE_FORMAT_x_COMMA_LB (A);
+ } else {
+ strcat (formatString, "%*");
+ WRITE_FORMAT_LB ();
}
if (!fieldBisReg)
{
@@ -2752,18 +2834,22 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
fieldAisReg=0;
/* [B,A offset] */
- if (dbg) eprintf("7:b reg %d %x off %x\n",
- fieldBisReg,fieldB,fieldA);
+ if (dbg) {
+ eprintf ("7:b reg %d %x off %x\n",
+ fieldBisReg, fieldB, fieldA);
+ }
state->_ea_present = 1;
state->_offset = fieldA;
- if (fieldBisReg) state->ea_reg1 = fieldB;
- /*
+ if (fieldBisReg) {
+ state->ea_reg1 = fieldB;
+ /*
* field B is either a shimm (same as fieldA) or limm (different!)
* Say ea is not present, so only one of us will do the name lookup.
* (for is_limm we do the name translation here).
*/
- else
- state->_offset += fieldB, state->_ea_present = 0;
+ } else {
+ state->_offset += fieldB, state->_ea_present = 0;
+ }
directMem = BIT(state->words[0],5);
addrWriteBack = BITS(state->words[0],3,4);
@@ -2792,9 +2878,10 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
if (is_limm)
{
FIELD_C();
- if (!fieldCisReg)
- fieldC = fieldB;
- }
+ if (!fieldCisReg) {
+ fieldC = fieldB;
+ }
+ }
else
{
CHECK_FIELD_C();
@@ -2962,27 +3049,26 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
fieldA = fieldA << 1;
}
- if ((state->_opcode == op_BC && (BIT(state->words[0],16))) ||
- (state->_opcode == op_BLC && (BIT(state->words[0],17))))
- /* unconditional branch s25 or branch and link d25 */
- fieldA = sign_extend(fieldA, 25);
- else
- /* conditional branch s21 or branch and link d21 */
- fieldA = sign_extend(fieldA, 21);
+ if ((state->_opcode == op_BC && (BIT (state->words[0], 16))) ||
+ (state->_opcode == op_BLC && (BIT (state->words[0], 17)))) {
+ /* unconditional branch s25 or branch and link d25 */
+ fieldA = sign_extend (fieldA, 25);
+ } else {
+ /* conditional branch s21 or branch and link d21 */
+ fieldA = sign_extend (fieldA, 21);
+ }
fieldA += (addr & ~0x3);
- if (BIT(state->words[0],16) && state->_opcode == op_BC)
- CHECK_NULLIFY();
- else
- /* Checking for bl unconditionally FIX For Bug #553 */
- if((state->_opcode == op_BLC && BITS(state->words[0],16,17) == 2 )
- ||(state->_opcode == op_BC && (BIT(state->words[0],16))))
- CHECK_NULLIFY();
- else
- CHECK_COND_NULLIFY();
-
-
+ if (BIT (state->words[0], 16) && state->_opcode == op_BC) {
+ CHECK_NULLIFY ();
+ } else
+ /* Checking for bl unconditionally FIX For Bug #553 */
+ if ((state->_opcode == op_BLC && BITS (state->words[0], 16, 17) == 2) || (state->_opcode == op_BC && (BIT (state->words[0], 16)))) {
+ CHECK_NULLIFY ();
+ } else {
+ CHECK_COND_NULLIFY ();
+ }
write_instr_name();
/* This address could be a label we know. Convert it. */
@@ -3010,15 +3096,16 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
fieldA = fieldAisReg = 0;
WRITE_FORMAT_x(A);
WRITE_FORMAT_COMMA_x(B);
+ } else {
+ WRITE_FORMAT_x (B);
}
- else
- WRITE_FORMAT_x(B);
WRITE_FORMAT_COMMA_x(C);
WRITE_NOP_COMMENT();
- if (mul)
- my_sprintf(state, state->operandBuffer, formatString, 0, fieldB, fieldC);
- else
- my_sprintf(state, state->operandBuffer, formatString, fieldB, fieldC);
+ if (mul) {
+ my_sprintf (state, state->operandBuffer, formatString, 0, fieldB, fieldC);
+ } else {
+ my_sprintf (state, state->operandBuffer, formatString, fieldB, fieldC);
+ }
break;
case 15:
@@ -3114,12 +3201,11 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
/* Stack pointer-based instructions [major opcode 0x18] */
- if (BITS(state->words[0],5,7) == 5)
- fieldA = 28;
- else
- {
- FIELD_B_AC();
- fieldA = fieldB;
+ if (BITS (state->words[0], 5, 7) == 5) {
+ fieldA = 28;
+ } else {
+ FIELD_B_AC ();
+ fieldA = fieldB;
}
fieldB = 28; /* Field B is the stack pointer register */
fieldC = (FIELDU_AC(state->words[0])) << 2;
@@ -3188,10 +3274,11 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
/* add/cmp/btst instructions [major opcode 28] */
FIELD_B_AC();
- if (state->_opcode == op_Su5)
- fieldC = (BITS(state->words[0],0,4));
- else
- fieldC = (BITS(state->words[0],0,6));
+ if (state->_opcode == op_Su5) {
+ fieldC = (BITS (state->words[0], 0, 4));
+ } else {
+ fieldC = (BITS (state->words[0], 0, 6));
+ }
fieldCisReg = 0;
write_instr_name();
@@ -3393,9 +3480,9 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
if (BITS(state->words[0],0,4) == 1)
{
FIELD_B_AC();
+ } else if (BITS (state->words[0], 0, 4) == 17) {
+ fieldB = 31;
}
- else if (BITS(state->words[0],0,4) == 17)
- fieldB = 31;
write_instr_name();
@@ -3420,13 +3507,12 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
write_instr_name();
- if (!fieldC)
- state->operandBuffer[0] = '\0';
- else
- {
- WRITE_FORMAT_x(C);
- WRITE_NOP_COMMENT();
- my_sprintf(state, state->operandBuffer, formatString, fieldC);
+ if (!fieldC) {
+ state->operandBuffer[0] = '\0';
+ } else {
+ WRITE_FORMAT_x (C);
+ WRITE_NOP_COMMENT ();
+ my_sprintf (state, state->operandBuffer, formatString, fieldC);
}
break;
@@ -3459,11 +3545,12 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
FIELD_B();
directMem = BIT(state->words[0],15);
-
- if (BITS(state->words[0],22,23) == 1 )
- fieldCisReg = 0;
- if (fieldCisReg)
- state->ea_reg1 = fieldC;
+ if (BITS (state->words[0], 22, 23) == 1) {
+ fieldCisReg = 0;
+ }
+ if (fieldCisReg) {
+ state->ea_reg1 = fieldC;
+ }
write_instr_name();
WRITE_FORMAT_x_COMMA_LB(B);
@@ -3536,8 +3623,9 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
{
FIELD_U8();
- if (simd_scale_u8>0)
- fieldC = fieldC << simd_scale_u8;
+ if (simd_scale_u8 > 0) {
+ fieldC = fieldC << simd_scale_u8;
+ }
}
fieldCisReg = 0;
@@ -3604,8 +3692,9 @@ dsmOneArcInst (bfd_vma addr, struct arcDisState *state, disassemble_info * info)
%C*/
CHECK_FIELD_C();
- if (BITS(state->words[0], 17, 23) == 55)
- fieldCisReg = 0;
+ if (BITS (state->words[0], 17, 23) == 55) {
+ fieldCisReg = 0;
+ }
write_instr_name();
WRITE_FORMAT_x(C);
@@ -3697,10 +3786,10 @@ parse_disassembler_options (char *options)
}
p = strchr (p, ',');
-
- if (p != NULL)
- p++;
-
+
+ if (p != NULL) {
+ p++;
+ }
}
}
@@ -3747,10 +3836,11 @@ ARCompact_decodeInstr (bfd_vma address, /* Address of this instruct
s.instructionLen = 2;
s.words[0] = (buffer[lowbyte] << 8) | buffer[highbyte];
status = (*info->read_memory_func) (address + 2, buffer, 4, info);
- if (info->endian == BFD_ENDIAN_LITTLE)
- s.words[1] = bfd_getl32(buffer);
- else
- s.words[1] = bfd_getb32(buffer);
+ if (info->endian == BFD_ENDIAN_LITTLE) {
+ s.words[1] = bfd_getl32 (buffer);
+ } else {
+ s.words[1] = bfd_getb32 (buffer);
+ }
}
else
{
@@ -3761,18 +3851,20 @@ ARCompact_decodeInstr (bfd_vma address, /* Address of this instruct
(*info->memory_error_func) (status, address + 2, info);
return -1;
}
- if (info->endian == BFD_ENDIAN_LITTLE)
- s.words[0] = bfd_getl32(buffer);
- else
- s.words[0] = bfd_getb32(buffer);
+ if (info->endian == BFD_ENDIAN_LITTLE) {
+ s.words[0] = bfd_getl32 (buffer);
+ } else {
+ s.words[0] = bfd_getb32 (buffer);
+ }
/* always read second word in case of limm */
/* we ignore the result since last insn may not have a limm */
status = (*info->read_memory_func) (address + 4, buffer, 4, info);
- if (info->endian == BFD_ENDIAN_LITTLE)
- s.words[1] = bfd_getl32(buffer);
- else
- s.words[1] = bfd_getb32(buffer);
+ if (info->endian == BFD_ENDIAN_LITTLE) {
+ s.words[1] = bfd_getl32 (buffer);
+ } else {
+ s.words[1] = bfd_getb32 (buffer);
+ }
}
s._this = &s;
@@ -3794,12 +3886,13 @@ ARCompact_decodeInstr (bfd_vma address, /* Address of this instruct
{
/* Show instruction stream from MSB to LSB*/
- if (s.instructionLen == 2)
- (*func) (stream, " %04x ", (unsigned int) s.words[0]);
- else
- (*func) (stream, "%08x ", (unsigned int) s.words[0]);
+ if (s.instructionLen == 2) {
+ (*func) (stream, " %04x ", (unsigned int)s.words[0]);
+ } else {
+ (*func) (stream, "%08x ", (unsigned int)s.words[0]);
+ }
- (*func) (stream, " ");
+ (*func) (stream, " ");
}
/* if the operand is actually in the instruction buffer */
@@ -3830,9 +3923,9 @@ ARCompact_decodeInstr (bfd_vma address, /* Address of this instruct
addr = s.addresses[operand[i] - '0'];
(*info->print_address_func) ((bfd_vma) addr, info);
//(*func) (stream, "\n");
- }
- else
- (*func) (stream, "%s", operand);
+ } else {
+ (*func) (stream, "%s", operand);
+ }
}
/* We print max bytes for instruction */
@@ -3880,10 +3973,11 @@ arcAnalyzeInstr
s.instructionLen = 2;
s.words[0] = (buffer[lowbyte] << 8) | buffer[highbyte];
status = (*info->read_memory_func) (address + 2, buffer, 4, info);
- if (info->endian == BFD_ENDIAN_LITTLE)
- s.words[1] = bfd_getl32(buffer);
- else
- s.words[1] = bfd_getb32(buffer);
+ if (info->endian == BFD_ENDIAN_LITTLE) {
+ s.words[1] = bfd_getl32 (buffer);
+ } else {
+ s.words[1] = bfd_getb32 (buffer);
+ }
}
else
{
@@ -3895,18 +3989,20 @@ arcAnalyzeInstr
s.instructionLen = -1;
return s;
}
- if (info->endian == BFD_ENDIAN_LITTLE)
- s.words[0] = bfd_getl32(buffer);
- else
- s.words[0] = bfd_getb32(buffer);
+ if (info->endian == BFD_ENDIAN_LITTLE) {
+ s.words[0] = bfd_getl32 (buffer);
+ } else {
+ s.words[0] = bfd_getb32 (buffer);
+ }
/* always read second word in case of limm */
/* we ignore the result since last insn may not have a limm */
status = (*info->read_memory_func) (address + 4, buffer, 4, info);
- if (info->endian == BFD_ENDIAN_LITTLE)
- s.words[1] = bfd_getl32(buffer);
- else
- s.words[1] = bfd_getb32(buffer);
+ if (info->endian == BFD_ENDIAN_LITTLE) {
+ s.words[1] = bfd_getl32 (buffer);
+ } else {
+ s.words[1] = bfd_getb32 (buffer);
+ }
}
s._this = &s;
diff --git a/libr/asm/arch/arm/aarch64/aarch64-dis.c b/libr/asm/arch/arm/aarch64/aarch64-dis.c
index b678e81acb..72b2d4c510 100644
--- a/libr/asm/arch/arm/aarch64/aarch64-dis.c
+++ b/libr/asm/arch/arm/aarch64/aarch64-dis.c
@@ -87,8 +87,9 @@ parse_aarch64_dis_options (const char *options)
{
const char *option_end;
- if (!options)
- return;
+ if (!options) {
+ return;
+ }
while (*options != '\0')
{
@@ -101,8 +102,9 @@ parse_aarch64_dis_options (const char *options)
/* We know that *options is neither NUL or a comma. */
option_end = options + 1;
- while (*option_end != ',' && *option_end != '\0')
- option_end++;
+ while (*option_end != ',' && *option_end != '\0') {
+ option_end++;
+ }
parse_aarch64_dis_option (options, option_end - options);
@@ -212,10 +214,11 @@ get_expected_qualifier (const aarch64_inst *inst, int i)
/* Should not be called if the qualifier is known. */
assert (inst->operands[i].qualifier == AARCH64_OPND_QLF_NIL);
if (aarch64_find_best_match (inst, inst->opcode->qualifiers_list,
- i, qualifiers))
- return qualifiers[i];
- else
- return AARCH64_OPND_QLF_NIL;
+ i, qualifiers)) {
+ return qualifiers[i];
+ } else {
+ return AARCH64_OPND_QLF_NIL;
+ }
}
/* Operand extractors. */
@@ -284,10 +287,12 @@ aarch64_ext_reglane (const aarch64_operand *self, aarch64_opnd_info *info,
1000 D */
int pos = -1;
aarch64_insn value = extract_field (FLD_imm5, code, 0);
- while (++pos <= 3 && (value & 0x1) == 0)
- value >>= 1;
- if (pos > 3)
- return 0;
+ while (++pos <= 3 && (value & 0x1) == 0) {
+ value >>= 1;
+ }
+ if (pos > 3) {
+ return 0;
+ }
info->qualifier = get_sreg_qualifier_from_value (pos);
info->reglane.index = (unsigned) (value >> 1);
}
@@ -368,8 +373,9 @@ aarch64_ext_ldst_reglist (const aarch64_operand *self ATTRIBUTE_UNUSED,
info->reglist.first_regno = extract_field (FLD_Rt, code, 0);
/* opcode */
value = extract_field (FLD_opcode, code, 0);
- if (expected_num != data[value].num_elements || data[value].is_reserved)
- return 0;
+ if (expected_num != data[value].num_elements || data[value].is_reserved) {
+ return 0;
+ }
info->reglist.num_regs = data[value].num_regs;
return 1;
@@ -395,8 +401,9 @@ aarch64_ext_ldst_reglist_r (const aarch64_operand *self ATTRIBUTE_UNUSED,
assert (info->reglist.num_regs >= 1 && info->reglist.num_regs <= 4);
/* Except when it is LD1R. */
- if (info->reglist.num_regs == 1 && value == (aarch64_insn) 1)
- info->reglist.num_regs = 2;
+ if (info->reglist.num_regs == 1 && value == (aarch64_insn)1) {
+ info->reglist.num_regs = 2;
+ }
return 1;
}
@@ -443,9 +450,10 @@ aarch64_ext_ldst_elemlist (const aarch64_operand *self ATTRIBUTE_UNUSED,
info->qualifier = AARCH64_OPND_QLF_S_D;
/* Index encoded in "Q". */
info->reglist.index = QSsize >> 3;
- if (extract_field (FLD_S, code, 0))
- /* UND */
- return 0;
+ if (extract_field (FLD_S, code, 0)) {
+ /* UND */
+ return 0;
+ }
}
break;
default:
@@ -476,13 +484,15 @@ aarch64_ext_advsimd_imm_shift (const aarch64_operand *self ATTRIBUTE_UNUSED,
enum aarch64_insn_class iclass = inst->opcode->iclass;
immh = extract_field (FLD_immh, code, 0);
- if (immh == 0)
- return 0;
+ if (immh == 0) {
+ return 0;
+ }
imm = extract_fields (code, 0, 2, FLD_immh, FLD_immb);
pos = 4;
/* Get highest set bit in immh. */
- while (--pos >= 0 && (immh & 0x8) == 0)
- immh <<= 1;
+ while (--pos >= 0 && (immh & 0x8) == 0) {
+ immh <<= 1;
+ }
assert ((iclass == asimdshf || iclass == asisdshf)
&& (info->type == AARCH64_OPND_IMM_VLSR
@@ -503,27 +513,28 @@ aarch64_ext_advsimd_imm_shift (const aarch64_operand *self ATTRIBUTE_UNUSED,
1xxx 1 2D */
info->qualifier =
get_vreg_qualifier_from_value ((pos << 1) | (int) Q);
- }
- else
- info->qualifier = get_sreg_qualifier_from_value (pos);
+ } else {
+ info->qualifier = get_sreg_qualifier_from_value (pos);
+ }
- if (info->type == AARCH64_OPND_IMM_VLSR)
- /* immh
+ if (info->type == AARCH64_OPND_IMM_VLSR) {
+ /* immh
0000 SEE AdvSIMD modified immediate
0001 (16-UInt(immh:immb))
001x (32-UInt(immh:immb))
01xx (64-UInt(immh:immb))
1xxx (128-UInt(immh:immb)) */
- info->imm.value = (16 << pos) - imm;
- else
- /* immh:immb
+ info->imm.value = (16 << pos) - imm;
+ } else {
+ /* immh:immb
immh
0000 SEE AdvSIMD modified immediate
0001 (UInt(immh:immb)-8)
001x (UInt(immh:immb)-16)
01xx (UInt(immh:immb)-32)
1xxx (UInt(immh:immb)-64) */
- info->imm.value = imm - (8 << pos);
+ info->imm.value = imm - (8 << pos);
+ }
return 1;
}
@@ -559,23 +570,28 @@ aarch64_ext_imm (const aarch64_operand *self, aarch64_opnd_info *info,
/* Maximum of two fields to extract. */
assert (self->fields[2] == FLD_NIL);
- if (self->fields[1] == FLD_NIL)
- imm = extract_field (self->fields[0], code, 0);
- else
- /* e.g. TBZ b5:b40. */
- imm = extract_fields (code, 0, 2, self->fields[0], self->fields[1]);
+ if (self->fields[1] == FLD_NIL) {
+ imm = extract_field (self->fields[0], code, 0);
+ } else {
+ /* e.g. TBZ b5:b40. */
+ imm = extract_fields (code, 0, 2, self->fields[0], self->fields[1]);
+ }
- if (info->type == AARCH64_OPND_FPIMM)
- info->imm.is_fp = 1;
+ if (info->type == AARCH64_OPND_FPIMM) {
+ info->imm.is_fp = 1;
+ }
- if (operand_need_sign_extension (self))
- imm = sign_extend (imm, get_operand_fields_width (self) - 1);
+ if (operand_need_sign_extension (self)) {
+ imm = sign_extend (imm, get_operand_fields_width (self) - 1);
+ }
- if (operand_need_shift_by_two (self))
- imm <<= 2;
+ if (operand_need_shift_by_two (self)) {
+ imm <<= 2;
+ }
- if (info->type == AARCH64_OPND_ADDR_ADRP)
- imm <<= 12;
+ if (info->type == AARCH64_OPND_ADDR_ADRP) {
+ imm <<= 12;
+ }
info->imm.value = imm;
return 1;
@@ -607,8 +623,9 @@ aarch64_ext_advsimd_imm_modified (const aarch64_operand *self ATTRIBUTE_UNUSED,
assert (info->idx == 1);
- if (info->type == AARCH64_OPND_SIMD_FPIMM)
- info->imm.is_fp = 1;
+ if (info->type == AARCH64_OPND_SIMD_FPIMM) {
+ info->imm.is_fp = 1;
+ }
/* a:b:c:d:e:f:g:h */
imm = extract_fields (code, 0, 2, FLD_abc, FLD_defgh);
@@ -621,9 +638,11 @@ aarch64_ext_advsimd_imm_modified (const aarch64_operand *self ATTRIBUTE_UNUSED,
encoded in "a:b:c:d:e:f:g:h". */
int i;
unsigned abcdefgh = imm;
- for (imm = 0ull, i = 0; i < 8; i++)
- if (((abcdefgh >> i) & 0x1) != 0)
- imm |= 0xffull << (8 * i);
+ for (imm = 0ull, i = 0; i < 8; i++) {
+ if (((abcdefgh >> i) & 0x1) != 0) {
+ imm |= 0xffull << (8 * i);
+ }
+ }
}
info->imm.value = imm;
@@ -684,8 +703,9 @@ aarch64_ext_aimm (const aarch64_operand *self ATTRIBUTE_UNUSED,
info->shifter.kind = AARCH64_MOD_LSL;
/* shift */
value = extract_field (FLD_shift, code, 0);
- if (value >= 2)
- return 0;
+ if (value >= 2) {
+ return 0;
+ }
info->shifter.amount = value ? 12 : 0;
/* imm12 (unsigned) */
info->imm.value = extract_field (FLD_imm12, code, 0);
@@ -716,8 +736,9 @@ aarch64_ext_limm (const aarch64_operand *self ATTRIBUTE_UNUSED,
R = (value >> 6) & 0x3f;
N = (value >> 12) & 0x1;
- if (sf == 0 && N == 1)
- return 0;
+ if (sf == 0 && N == 1) {
+ return 0;
+ }
/* The immediate value is S+1 bits to 1, left rotated by SIMDsize - R
(in other words, right rotated by R), then replicated. */
@@ -739,17 +760,18 @@ aarch64_ext_limm (const aarch64_operand *self ATTRIBUTE_UNUSED,
R &= simd_size - 1;
}
/* NOTE: if S = simd_size - 1 we get 0xf..f which is rejected. */
- if (S == simd_size - 1)
- return 0;
- /* S+1 consecutive bits to 1. */
- /* NOTE: S can't be 63 due to detection above. */
- imm = (1ull << (S + 1)) - 1;
- /* Rotate to the left by simd_size - R. */
- if (R != 0)
- imm = ((imm << (simd_size - R)) & mask) | (imm >> R);
- /* Replicate the value according to SIMD size. */
- switch (simd_size)
- {
+ if (S == simd_size - 1) {
+ return 0;
+ }
+ /* S+1 consecutive bits to 1. */
+ /* NOTE: S can't be 63 due to detection above. */
+ imm = (1ull << (S + 1)) - 1;
+ /* Rotate to the left by simd_size - R. */
+ if (R != 0) {
+ imm = ((imm << (simd_size - R)) & mask) | (imm >> R);
+ }
+ /* Replicate the value according to SIMD size. */
+ switch (simd_size) {
case 2: imm = (imm << 2) | imm;
case 4: imm = (imm << 4) | imm;
case 8: imm = (imm << 8) | imm;
@@ -797,8 +819,9 @@ aarch64_ext_ft (const aarch64_operand *self ATTRIBUTE_UNUSED,
{
/* opc1:size */
value = extract_fields (code, 0, 2, FLD_opc1, FLD_ldst_size);
- if (value > 0x4)
- return 0;
+ if (value > 0x4) {
+ return 0;
+ }
info->qualifier = get_sreg_qualifier_from_value (value);
}
@@ -836,8 +859,9 @@ aarch64_ext_addr_regoff (const aarch64_operand *self ATTRIBUTE_UNUSED,
aarch64_get_operand_modifier_from_value (value, TRUE /* extend_p */);
/* Fix-up the shifter kind; although the table-driven approach is
efficient, it is slightly inflexible, thus needing this fix-up. */
- if (info->shifter.kind == AARCH64_MOD_UXTX)
- info->shifter.kind = AARCH64_MOD_LSL;
+ if (info->shifter.kind == AARCH64_MOD_UXTX) {
+ info->shifter.kind = AARCH64_MOD_LSL;
+ }
/* S */
S = extract_field (FLD_S, code, 0);
if (S == 0)
@@ -874,23 +898,21 @@ aarch64_ext_addr_simm (const aarch64_operand *self, aarch64_opnd_info *info,
/* simm (imm9 or imm7) */
imm = extract_field (self->fields[0], code, 0);
info->addr.offset.imm = sign_extend (imm, aarch64_fields[self->fields[0]].width - 1);
- if (self->fields[0] == FLD_imm7)
- /* scaled immediate in ld/st pair instructions. */
- info->addr.offset.imm *= aarch64_get_qualifier_esize (info->qualifier);
+ if (self->fields[0] == FLD_imm7) {
+ /* scaled immediate in ld/st pair instructions. */
+ info->addr.offset.imm *= aarch64_get_qualifier_esize (info->qualifier);
+ }
/* qualifier */
- if (inst->opcode->iclass == ldst_unscaled
- || inst->opcode->iclass == ldstnapair_offs
- || inst->opcode->iclass == ldstpair_off
- || inst->opcode->iclass == ldst_unpriv)
- info->addr.writeback = 0;
- else
- {
- /* pre/post- index */
- info->addr.writeback = 1;
- if (extract_field (self->fields[1], code, 0) == 1)
- info->addr.preind = 1;
- else
- info->addr.postind = 1;
+ if (inst->opcode->iclass == ldst_unscaled || inst->opcode->iclass == ldstnapair_offs || inst->opcode->iclass == ldstpair_off || inst->opcode->iclass == ldst_unpriv) {
+ info->addr.writeback = 0;
+ } else {
+ /* pre/post- index */
+ info->addr.writeback = 1;
+ if (extract_field (self->fields[1], code, 0) == 1) {
+ info->addr.preind = 1;
+ } else {
+ info->addr.postind = 1;
+ }
}
return 1;
@@ -929,18 +951,17 @@ aarch64_ext_simd_addr_post (const aarch64_operand *self ATTRIBUTE_UNUSED,
info->addr.offset.regno = extract_field (FLD_Rm, code, 0);
if (info->addr.offset.regno == 31)
{
- if (inst->opcode->operands[0] == AARCH64_OPND_LVt_AL)
- /* Special handling of loading single structure to all lane. */
- info->addr.offset.imm = (is_ld1r ? 1
- : inst->operands[0].reglist.num_regs)
- * aarch64_get_qualifier_esize (inst->operands[0].qualifier);
- else
- info->addr.offset.imm = inst->operands[0].reglist.num_regs
- * aarch64_get_qualifier_esize (inst->operands[0].qualifier)
- * aarch64_get_qualifier_nelem (inst->operands[0].qualifier);
- }
- else
- info->addr.offset.is_reg = 1;
+ if (inst->opcode->operands[0] == AARCH64_OPND_LVt_AL) {
+ /* Special handling of loading single structure to all lane. */
+ info->addr.offset.imm = (is_ld1r ? 1
+ : inst->operands[0].reglist.num_regs) *
+ aarch64_get_qualifier_esize (inst->operands[0].qualifier);
+ } else {
+ info->addr.offset.imm = inst->operands[0].reglist.num_regs * aarch64_get_qualifier_esize (inst->operands[0].qualifier) * aarch64_get_qualifier_nelem (inst->operands[0].qualifier);
+ }
+ } else {
+ info->addr.offset.is_reg = 1;
+ }
info->addr.writeback = 1;
return 1;
@@ -981,9 +1002,11 @@ aarch64_ext_pstatefield (const aarch64_operand *self ATTRIBUTE_UNUSED,
int i;
/* op1:op2 */
info->pstatefield = extract_fields (code, 0, 2, FLD_op1, FLD_op2);
- for (i = 0; aarch64_pstatefields[i].name != NULL; ++i)
- if (aarch64_pstatefields[i].value == (aarch64_insn)info->pstatefield)
- return 1;
+ for (i = 0; aarch64_pstatefields[i].name != NULL; ++i) {
+ if (aarch64_pstatefields[i].value == (aarch64_insn)info->pstatefield) {
+ return 1;
+ }
+ }
/* Reserved value in . */
return 0;
}
@@ -1012,18 +1035,18 @@ aarch64_ext_sysins_op (const aarch64_operand *self ATTRIBUTE_UNUSED,
default: assert (0); return 0;
}
- for (i = 0; sysins_ops[i].template != NULL; ++i)
- if (sysins_ops[i].value == value)
- {
- info->sysins_op = sysins_ops + i;
- DEBUG_TRACE ("%s found value: %x, has_xt: %d, i: %d.",
- info->sysins_op->template,
- (unsigned)info->sysins_op->value,
- info->sysins_op->has_xt, i);
- return 1;
- }
+ for (i = 0; sysins_ops[i].template != NULL; ++i) {
+ if (sysins_ops[i].value == value) {
+ info->sysins_op = sysins_ops + i;
+ DEBUG_TRACE ("%s found value: %x, has_xt: %d, i: %d.",
+ info->sysins_op->template,
+ (unsigned)info->sysins_op->value,
+ info->sysins_op->has_xt, i);
+ return 1;
+ }
+ }
- return 0;
+ return 0;
}
/* Decode the memory barrier option operand for e.g. DMB
\n",
top, left, bbi->addr, str);
left = left? 0: 600;
- if (!left) top += 250;
+ if (!left) {
+ top += 250;
+ }
} else if (!is_json && !is_keva) {
bool current = r_anal_bb_is_in_offset (bbi, core->offset);
const char *label_color = bbi->traced
@@ -1560,8 +1564,9 @@ R_API int r_core_anal_fcn_clean(RCore *core, ut64 addr) {
if (!addr) {
r_list_purge (core->anal->fcns);
core->anal->fcn_tree = NULL;
- if (!(core->anal->fcns = r_anal_fcn_list_new ()))
+ if (!(core->anal->fcns = r_anal_fcn_list_new ())) {
return false;
+ }
} else {
r_list_foreach_safe (core->anal->fcns, iter, iter_tmp, fcni) {
if (r_anal_fcn_in (fcni, addr)) {
diff --git a/libr/core/cbin.c b/libr/core/cbin.c
index 37a353217c..927d98f2f0 100644
--- a/libr/core/cbin.c
+++ b/libr/core/cbin.c
@@ -2018,8 +2018,9 @@ static int bin_symbols_internal(RCore *r, int mode, ut64 laddr, int va, ut64 at,
char *name = strdup (sn.demname? sn.demname: symbol->name);
r_name_filter (name, -1);
if (!strncmp (name, "imp.", 4)) {
- if (lastfs != 'i')
+ if (lastfs != 'i') {
r_cons_printf ("fs imports\n");
+ }
lastfs = 'i';
} else {
if (lastfs != 's') {
@@ -2155,7 +2156,9 @@ static char *build_hash_string(int mode, const char *chksum, ut8 *data, ut32 dat
ret = r_str_append (ret, aux);
free (chkstr);
free (aux);
- if (*ptr && *ptr == ',') ptr++;
+ if (*ptr && *ptr == ',') {
+ ptr++;
+ }
} while (*ptr);
return ret;
@@ -2228,10 +2231,18 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c
continue;
}
- if (section->srwx & R_BIN_SCN_SHAREABLE) perms[0] = 's';
- if (section->srwx & R_BIN_SCN_READABLE) perms[1] = 'r';
- if (section->srwx & R_BIN_SCN_WRITABLE) perms[2] = 'w';
- if (section->srwx & R_BIN_SCN_EXECUTABLE) perms[3] = 'x';
+ if (section->srwx & R_BIN_SCN_SHAREABLE) {
+ perms[0] = 's';
+ }
+ if (section->srwx & R_BIN_SCN_READABLE) {
+ perms[1] = 'r';
+ }
+ if (section->srwx & R_BIN_SCN_WRITABLE) {
+ perms[2] = 'w';
+ }
+ if (section->srwx & R_BIN_SCN_EXECUTABLE) {
+ perms[3] = 'x';
+ }
if (IS_MODE_SET (mode)) {
#if LOAD_BSS_MALLOC
@@ -2378,8 +2389,12 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c
const char *arch = section->arch;
int bits = section->bits;
if (info) {
- if (!arch) arch = info->arch;
- if (!bits) bits = info->bits;
+ if (!arch) {
+ arch = info->arch;
+ }
+ if (!bits) {
+ bits = info->bits;
+ }
}
if (!arch) {
arch = r_config_get (r->config, "asm.arch");
@@ -2872,7 +2887,9 @@ static void bin_mem_print(RList *mems, int perms, int depth, int mode) {
static int bin_mem(RCore *r, int mode) {
RList *mem = NULL;
- if (!r) return false;
+ if (!r) {
+ return false;
+ }
if (!IS_MODE_JSON (mode)) {
if (!(IS_MODE_RAD (mode) || IS_MODE_SET (mode))) {
r_cons_println ("[Memory]\n");
@@ -3408,30 +3425,74 @@ R_API int r_core_bin_info(RCore *core, int action, int mode, int va, RCoreBinFil
r_core_cmd0 (core, "aar");
}
#endif
- if ((action & R_CORE_BIN_ACC_STRINGS)) ret &= bin_strings (core, mode, va);
- if ((action & R_CORE_BIN_ACC_RAW_STRINGS)) ret &= bin_raw_strings (core, mode, va);
- if ((action & R_CORE_BIN_ACC_INFO)) ret &= bin_info (core, mode);
- if ((action & R_CORE_BIN_ACC_MAIN)) ret &= bin_main (core, mode, va);
- if ((action & R_CORE_BIN_ACC_DWARF)) ret &= bin_dwarf (core, mode);
- if ((action & R_CORE_BIN_ACC_PDB)) ret &= bin_pdb (core, mode);
- if ((action & R_CORE_BIN_ACC_SOURCE)) ret &= bin_source (core, mode);
- if ((action & R_CORE_BIN_ACC_ENTRIES)) ret &= bin_entry (core, mode, loadaddr, va, false);
- if ((action & R_CORE_BIN_ACC_INITFINI)) ret &= bin_entry (core, mode, loadaddr, va, true);
- if ((action & R_CORE_BIN_ACC_SECTIONS)) ret &= bin_sections (core, mode, loadaddr, va, at, name, chksum, false);
- if ((action & R_CORE_BIN_ACC_SEGMENTS)) ret &= bin_sections (core, mode, loadaddr, va, at, name, chksum, true);
- if (r_config_get_i (core->config, "bin.relocs")) {
- if ((action & R_CORE_BIN_ACC_RELOCS)) ret &= bin_relocs (core, mode, va);
+ if ((action & R_CORE_BIN_ACC_STRINGS)) {
+ ret &= bin_strings (core, mode, va);
+ }
+ if ((action & R_CORE_BIN_ACC_RAW_STRINGS)) {
+ ret &= bin_raw_strings (core, mode, va);
+ }
+ if ((action & R_CORE_BIN_ACC_INFO)) {
+ ret &= bin_info (core, mode);
+ }
+ if ((action & R_CORE_BIN_ACC_MAIN)) {
+ ret &= bin_main (core, mode, va);
+ }
+ if ((action & R_CORE_BIN_ACC_DWARF)) {
+ ret &= bin_dwarf (core, mode);
+ }
+ if ((action & R_CORE_BIN_ACC_PDB)) {
+ ret &= bin_pdb (core, mode);
+ }
+ if ((action & R_CORE_BIN_ACC_SOURCE)) {
+ ret &= bin_source (core, mode);
+ }
+ if ((action & R_CORE_BIN_ACC_ENTRIES)) {
+ ret &= bin_entry (core, mode, loadaddr, va, false);
+ }
+ if ((action & R_CORE_BIN_ACC_INITFINI)) {
+ ret &= bin_entry (core, mode, loadaddr, va, true);
+ }
+ if ((action & R_CORE_BIN_ACC_SECTIONS)) {
+ ret &= bin_sections (core, mode, loadaddr, va, at, name, chksum, false);
+ }
+ if ((action & R_CORE_BIN_ACC_SEGMENTS)) {
+ ret &= bin_sections (core, mode, loadaddr, va, at, name, chksum, true);
+ }
+ if (r_config_get_i (core->config, "bin.relocs")) {
+ if ((action & R_CORE_BIN_ACC_RELOCS)) {
+ ret &= bin_relocs (core, mode, va);
+ }
+ }
+ if ((action & R_CORE_BIN_ACC_IMPORTS)) {
+ ret &= bin_imports (core, mode, va, name); // 6s
+ }
+ if ((action & R_CORE_BIN_ACC_EXPORTS)) {
+ ret &= bin_exports (core, mode, loadaddr, va, at, name, chksum);
+ }
+ if ((action & R_CORE_BIN_ACC_SYMBOLS)) {
+ ret &= bin_symbols (core, mode, loadaddr, va, at, name, chksum); // 6s
+ }
+ if ((action & R_CORE_BIN_ACC_LIBS)) {
+ ret &= bin_libs (core, mode);
+ }
+ if ((action & R_CORE_BIN_ACC_CLASSES)) {
+ ret &= bin_classes (core, mode); // 3s
+ }
+ if ((action & R_CORE_BIN_ACC_SIZE)) {
+ ret &= bin_size (core, mode);
+ }
+ if ((action & R_CORE_BIN_ACC_MEM)) {
+ ret &= bin_mem (core, mode);
+ }
+ if ((action & R_CORE_BIN_ACC_VERSIONINFO)) {
+ ret &= bin_versioninfo (core, mode);
+ }
+ if ((action & R_CORE_BIN_ACC_RESOURCES)) {
+ ret &= bin_resources (core, mode);
+ }
+ if ((action & R_CORE_BIN_ACC_SIGNATURE)) {
+ ret &= bin_signature (core, mode);
}
- if ((action & R_CORE_BIN_ACC_IMPORTS)) ret &= bin_imports (core, mode, va, name); // 6s
- if ((action & R_CORE_BIN_ACC_EXPORTS)) ret &= bin_exports (core, mode, loadaddr, va, at, name, chksum);
- if ((action & R_CORE_BIN_ACC_SYMBOLS)) ret &= bin_symbols (core, mode, loadaddr, va, at, name, chksum); // 6s
- if ((action & R_CORE_BIN_ACC_LIBS)) ret &= bin_libs (core, mode);
- if ((action & R_CORE_BIN_ACC_CLASSES)) ret &= bin_classes (core, mode); // 3s
- if ((action & R_CORE_BIN_ACC_SIZE)) ret &= bin_size (core, mode);
- if ((action & R_CORE_BIN_ACC_MEM)) ret &= bin_mem (core, mode);
- if ((action & R_CORE_BIN_ACC_VERSIONINFO)) ret &= bin_versioninfo (core, mode);
- if ((action & R_CORE_BIN_ACC_RESOURCES)) ret &= bin_resources (core, mode);
- if ((action & R_CORE_BIN_ACC_SIGNATURE)) ret &= bin_signature (core, mode);
if ((action & R_CORE_BIN_ACC_FIELDS)) {
if (IS_MODE_SIMPLE (mode)) {
if ((action & R_CORE_BIN_ACC_HEADER) || action & R_CORE_BIN_ACC_FIELDS) {
diff --git a/libr/core/cconfig.c b/libr/core/cconfig.c
index 3fe40e3d25..961f76540d 100644
--- a/libr/core/cconfig.c
+++ b/libr/core/cconfig.c
@@ -136,15 +136,31 @@ static void rasm2_list(RCore *core, const char *arch, int fmt) {
bits[0] = 0;
/* The underscore makes it easier to distinguish the
* columns */
- if (h->bits&8) strcat (bits, "_8");
- if (h->bits&16) strcat (bits, "_16");
- if (h->bits&32) strcat (bits, "_32");
- if (h->bits&64) strcat (bits, "_64");
- if (!*bits) strcat (bits, "_0");
+ if (h->bits & 8) {
+ strcat (bits, "_8");
+ }
+ if (h->bits & 16) {
+ strcat (bits, "_16");
+ }
+ if (h->bits & 32) {
+ strcat (bits, "_32");
+ }
+ if (h->bits & 64) {
+ strcat (bits, "_64");
+ }
+ if (!*bits) {
+ strcat (bits, "_0");
+ }
feat = "__";
- if (h->assemble && h->disassemble) feat = "ad";
- if (h->assemble && !h->disassemble) feat = "a_";
- if (!h->assemble && h->disassemble) feat = "_d";
+ if (h->assemble && h->disassemble) {
+ feat = "ad";
+ }
+ if (h->assemble && !h->disassemble) {
+ feat = "a_";
+ }
+ if (!h->assemble && h->disassemble) {
+ feat = "_d";
+ }
feat2 = has_esil (core, h->name);
if (fmt == 'q') {
r_cons_println (h->name);
@@ -1998,7 +2014,9 @@ static int cb_binmaxstr(void *user, void *data) {
RConfigNode *node = (RConfigNode *) data;
if (core->bin) {
int v = node->i_value;
- if (v<1) v = 4; // HACK
+ if (v < 1) {
+ v = 4; // HACK
+ }
core->bin->maxstrlen = v;
// TODO: Do not refresh if nothing changed (minstrlen ?)
r_core_bin_refresh_strings (core);
@@ -2012,7 +2030,9 @@ static int cb_binminstr(void *user, void *data) {
RConfigNode *node = (RConfigNode *) data;
if (core->bin) {
int v = node->i_value;
- if (v<1) v = 4; // HACK
+ if (v < 1) {
+ v = 4; // HACK
+ }
core->bin->minstrlen = v;
// TODO: Do not refresh if nothing changed (minstrlen ?)
r_core_bin_refresh_strings (core);
diff --git a/libr/core/cfile.c b/libr/core/cfile.c
index 70c110969e..b1b135c99b 100644
--- a/libr/core/cfile.c
+++ b/libr/core/cfile.c
@@ -1153,8 +1153,9 @@ R_API RCoreFile *r_core_file_find_by_name(RCore *core, const char *name) {
RCoreFile *cf = NULL;
RIODesc *desc;
- if (!core)
+ if (!core) {
return NULL;
+ }
r_list_foreach (core->files, iter, cf) {
desc = r_io_desc_get (core->io, cf->fd);
diff --git a/libr/core/cio.c b/libr/core/cio.c
index 3503f48a61..e60290037a 100644
--- a/libr/core/cio.c
+++ b/libr/core/cio.c
@@ -76,8 +76,9 @@ R_API bool r_core_dump(RCore *core, const char *file, ut64 addr, ut64 size, int
return false;
}
/* some io backends seems to be buggy in those cases */
- if (bs > 4096)
+ if (bs > 4096) {
bs = 4096;
+ }
buf = malloc (bs);
if (!buf) {
eprintf ("Cannot alloc %d byte(s)\n", bs);
@@ -122,8 +123,9 @@ R_API int r_core_write_op(RCore *core, const char *arg, char op) {
// r_hex_str2bin() is guaranteed to output maximum half the
// input size, or 1 byte if there is just a single nibble.
str = (char *)malloc (strlen (arg) / 2 + 1);
- if (!str)
+ if (!str) {
goto beach;
+ }
len = r_hex_str2bin (arg, (ut8 *)str);
// Output is invalid if there was just a single nibble,
// but in that case, len is negative (-1).
@@ -138,10 +140,13 @@ R_API int r_core_write_op(RCore *core, const char *arg, char op) {
goto beach;
}
str = r_mem_dup (core->yank_buf->buf, len);
- if (!str)
+ if (!str) {
goto beach;
+ }
}
- } else len = 0;
+ } else {
+ len = 0;
+ }
// execute the operand
if (op=='e') {
@@ -243,7 +248,10 @@ R_API int r_core_write_op(RCore *core, const char *arg, char op) {
case 'o': buf[i] |= str[j]; break;
case 'A': buf[i] &= str[j]; break;
}
- j++; if (j>=len) j=0; /* cyclic key */
+ j++;
+ if (j >= len) {
+ j = 0; /* cyclic key */
+ }
}
}
diff --git a/libr/core/cmd.c b/libr/core/cmd.c
index 5d11942e6c..e5725e5387 100644
--- a/libr/core/cmd.c
+++ b/libr/core/cmd.c
@@ -284,10 +284,11 @@ static void recursive_help_go(RCore *core, int detail, RCmdDescriptor *desc) {
r_core_cmd_help (core, desc->help_detail2);
}
}
- for (i = 32; i < R_ARRAY_SIZE (desc->sub); i++)
+ for (i = 32; i < R_ARRAY_SIZE (desc->sub); i++) {
if (desc->sub[i]) {
recursive_help_go (core, detail, desc->sub[i]);
}
+ }
}
static void recursive_help(RCore *core, int detail, const char *cmd_prefix) {
@@ -442,8 +443,11 @@ static int cmd_alias(void *data, const char *input) {
def++;
}
if (!q || (q && q>def)) {
- if (*def) r_cmd_alias_set (core->rcmd, buf, def, 0);
- else r_cmd_alias_del (core->rcmd, buf);
+ if (*def) {
+ r_cmd_alias_set (core->rcmd, buf, def, 0);
+ } else {
+ r_cmd_alias_del (core->rcmd, buf);
+ }
}
/* Show command for alias */
} else if (desc && !q) {
@@ -1022,12 +1026,16 @@ static int cmd_kuery(void *data, const char *input) {
// TODO: slash split here? or inside sdb_ns ?
for (n = o = p; n; o = n) {
n = strchr (o, '/'); // SDB_NS_SEPARATOR NAMESPACE
- if (n) *n++ = 0;
+ if (n) {
+ *n++ = 0;
+ }
s = sdb_ns (s, o, 1);
}
free (p);
}
- if (!s) s = core->sdb;
+ if (!s) {
+ s = core->sdb;
+ }
RLine *line = core->cons->line;
if (!line->sdbshell_hist) {
line->sdbshell_hist = r_list_newf (free);
@@ -1080,9 +1088,15 @@ static int cmd_kuery(void *data, const char *input) {
} else {
eprintf ("Cannot open sdb '%s'\n", fn);
}
- } else eprintf ("Cannot find sdb '%s'\n", ns);
- } else eprintf ("Cannot open file\n");
- } else eprintf ("Missing sdb namespace\n");
+ } else {
+ eprintf ("Cannot find sdb '%s'\n", ns);
+ }
+ } else {
+ eprintf ("Cannot open file\n");
+ }
+ } else {
+ eprintf ("Missing sdb namespace\n");
+ }
free (fn);
} else {
eprintf ("Usage: ko [file] [namespace]\n");
@@ -1102,8 +1116,12 @@ static int cmd_kuery(void *data, const char *input) {
if (db) {
sdb_file (db, fn);
sdb_sync (db);
- } else eprintf ("Cannot find sdb '%s'\n", ns);
- } else eprintf ("Missing sdb namespace\n");
+ } else {
+ eprintf ("Cannot find sdb '%s'\n", ns);
+ }
+ } else {
+ eprintf ("Missing sdb namespace\n");
+ }
free (fn);
} else {
eprintf ("Usage: kd [file] [namespace]\n");
@@ -1143,8 +1161,11 @@ static int cmd_bsize(void *data, const char *input) {
switch (input[0]) {
case 'm': // "bm"
n = r_num_math (core->num, input + 1);
- if (n > 1) core->blocksize_max = n;
- else r_cons_printf ("0x%x\n", (ut32)core->blocksize_max);
+ if (n > 1) {
+ core->blocksize_max = n;
+ } else {
+ r_cons_printf ("0x%x\n", (ut32)core->blocksize_max);
+ }
break;
case '+': // "b+"
n = r_num_math (core->num, input + 1);
@@ -1643,7 +1664,9 @@ static int cmd_system(void *data, const char *input) {
n = atoi (input);
if (*input == '0' || n > 0) {
const char *cmd = r_line_hist_get (n);
- if (cmd) r_core_cmd0 (core, cmd);
+ if (cmd) {
+ r_core_cmd0 (core, cmd);
+ }
//else eprintf ("Error setting up system environment\n");
} else {
char *cmd = r_core_sysenv_begin (core, input);
@@ -1651,7 +1674,9 @@ static int cmd_system(void *data, const char *input) {
ret = r_sys_cmd (cmd);
r_core_sysenv_end (core, input);
free (cmd);
- } else eprintf ("Error setting up system environment\n");
+ } else {
+ eprintf ("Error setting up system environment\n");
+ }
}
break;
}
@@ -1958,7 +1983,9 @@ static int r_core_cmd_subst(RCore *core, char *cmd) {
core->print->cur_enabled = ocur_enabled;
}
if (colon && colon[1]) {
- for (++colon; *colon == ';'; colon++);
+ for (++colon; *colon == ';'; colon++) {
+ ;
+ }
r_core_cmd_subst (core, colon);
} else {
if (!*icmd) {
@@ -2291,7 +2318,9 @@ escape_pipe:
r_list_free (tmpenvs);
return ret;
}
- for (cmd = ptr + 2; cmd && *cmd == ' '; cmd++);
+ for (cmd = ptr + 2; cmd && *cmd == ' '; cmd++) {
+ ;
+ }
ptr = strchr (cmd, '&');
}
@@ -2820,7 +2849,9 @@ next_arroba:
if (ptr[1] == '@') {
if (ptr[2] == '@') {
char *rule = ptr + 3;
- while (*rule && *rule == ' ') rule++;
+ while (*rule && *rule == ' ') {
+ rule++;
+ }
ret = r_core_cmd_foreach3 (core, cmd, rule);
} else {
ret = r_core_cmd_foreach (core, cmd, ptr + 2);
@@ -2948,7 +2979,9 @@ static int foreach_comment(void *user, const char *k, const char *v) {
const char *cmd = ui->user;
if (!strncmp (k, "meta.C.", 7)) {
char *cmt = (char *)sdb_decode (v, 0);
- if (!cmt) cmt = strdup ("");
+ if (!cmt) {
+ cmt = strdup ("");
+ }
//eprintf ("--> %s = %s\n", k + 7, cmt);
r_core_cmdf (core, "s %s", k + 7);
r_core_cmd0 (core, cmd);
@@ -3001,8 +3034,9 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) { // "@@
int origpid = dbg->pid;
RDebugPid *p;
list = dbg->h->threads (dbg, dbg->pid);
- if (!list)
+ if (!list) {
return false;
+ }
r_list_foreach (list, iter, p) {
r_core_cmdf (core, "dp %d", p->pid);
r_cons_printf ("PID %d\n", p->pid);
@@ -3168,7 +3202,9 @@ static void foreachOffset (RCore *core, const char *_cmd, const char *each) {
// space separated numbers
while (each && *each) {
// find spaces
- while (*each== ' ') each++;
+ while (*each == ' ') {
+ each++;
+ }
str = strchr (each, ' ');
if (str) {
*str = '\0';
@@ -3200,7 +3236,9 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) {
RFlagItem *flag;
ut64 oseek, addr;
- for (; *cmd == ' '; cmd++);
+ for (; *cmd == ' '; cmd++) {
+ ;
+ }
oseek = core->offset;
ostr = str = strdup (each);
@@ -3395,7 +3433,9 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) {
if (out) {
each = out;
do {
- while (*each == ' ') each++;
+ while (*each == ' ') {
+ each++;
+ }
if (!*each) {
break;
}
@@ -3463,12 +3503,18 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) {
break;
default:
core->rcmd->macro.counter = 0;
- for (; *each == ' '; each++);
+ for (; *each == ' '; each++) {
+ ;
+ }
i = 0;
while (str[i]) {
j = i;
- for (; str[j] && str[j] == ' '; j++); // skip spaces
- for (i = j; str[i] && str[i] != ' '; i++); // find EOS
+ for (; str[j] && str[j] == ' '; j++) {
+ ; // skip spaces
+ }
+ for (i = j; str[i] && str[i] != ' '; i++) {
+ ; // find EOS
+ }
ch = str[i];
str[i] = '\0';
word = strdup (str + j);
@@ -3761,7 +3807,9 @@ R_API char *r_core_disassemble_bytes(RCore *core, ut64 addr, int b) {
R_API int r_core_cmd_buffer(void *user, const char *buf) {
char *ptr, *optr, *str = strdup (buf);
- if (!str) return false;
+ if (!str) {
+ return false;
+ }
optr = str;
ptr = strchr (str, '\n');
while (ptr) {
diff --git a/libr/core/cmd_api.c b/libr/core/cmd_api.c
index 099f3cda6d..08a32b8fe6 100644
--- a/libr/core/cmd_api.c
+++ b/libr/core/cmd_api.c
@@ -37,7 +37,9 @@ R_API RCmd *r_cmd_new () {
R_API RCmd *r_cmd_free(RCmd *cmd) {
int i;
- if (!cmd) return NULL;
+ if (!cmd) {
+ return NULL;
+ }
r_cmd_alias_free (cmd);
r_cmd_macro_free (&cmd->macro);
// dinitialize plugin commands
@@ -356,8 +358,9 @@ R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) {
macro->code = (char *)malloc (macro->codelen);
*macro->code = '\0';
macro->nargs = 0;
- if (!args)
+ if (!args) {
args = "";
+ }
macro->args = strdup (args);
ptr = strchr (macro->name, ' ');
if (ptr != NULL) {
@@ -369,11 +372,11 @@ R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) {
if (pbody) {
#endif
for (lidx=0; pbody[lidx]; lidx++) {
- if (pbody[lidx]==',')
+ if (pbody[lidx] == ',') {
pbody[lidx]='\n';
- else
- if (pbody[lidx]==')' && pbody[lidx-1]=='\n')
- pbody[lidx]='\0';
+ } else if (pbody[lidx] == ')' && pbody[lidx - 1] == '\n') {
+ pbody[lidx] = '\0';
+ }
}
strncpy (macro->code, pbody, macro->codelen);
macro->code[macro->codelen-1] = 0;
@@ -422,9 +425,13 @@ R_API int r_cmd_macro_rm(RCmdMacro *mac, const char *_name) {
RListIter *iter;
RCmdMacroItem *m;
char *name = strdup (_name);
- if (!name) return false;
+ if (!name) {
+ return false;
+ }
char *ptr = strchr (name, ')');
- if (ptr) *ptr = '\0';
+ if (ptr) {
+ *ptr = '\0';
+ }
r_list_foreach (mac->macros, iter, m) {
if (!strcmp (m->name, name)) {
r_list_delete (mac->macros, iter);
@@ -448,9 +455,11 @@ R_API void r_cmd_macro_list(RCmdMacro *mac) {
r_list_foreach (mac->macros, iter, m) {
mac->cb_printf ("%d (%s %s, ", idx, m->name, m->args);
for (j=0; m->code[j]; j++) {
- if (m->code[j]=='\n')
+ if (m->code[j] == '\n') {
mac->cb_printf (", ");
- else mac->cb_printf ("%c", m->code[j]);
+ } else {
+ mac->cb_printf ("%c", m->code[j]);
+ }
}
mac->cb_printf (")\n");
idx++;
@@ -465,9 +474,11 @@ R_API void r_cmd_macro_meta(RCmdMacro *mac) {
r_list_foreach (mac->macros, iter, m) {
mac->cb_printf ("(%s %s, ", m->name, m->args);
for (j=0; m->code[j]; j++) {
- if (m->code[j]=='\n')
+ if (m->code[j] == '\n') {
mac->cb_printf (", ");
- else mac->cb_printf ("%c", m->code[j]);
+ } else {
+ mac->cb_printf ("%c", m->code[j]);
+ }
}
mac->cb_printf (")\n");
}
@@ -499,20 +510,24 @@ R_API int r_cmd_macro_cmd_args(RCmdMacro *mac, const char *ptr, const char *args
const char *word = r_str_word_get0 (arg, w);
if (word && *word) {
wordlen = strlen (word);
- if ((i+wordlen+1) >= sizeof (cmd))
+ if ((i + wordlen + 1) >= sizeof (cmd)) {
return -1;
+ }
memcpy (cmd+i, word, wordlen+1);
i += wordlen-1;
j++;
- } else eprintf ("Undefined argument %d\n", w);
+ } else {
+ eprintf ("Undefined argument %d\n", w);
+ }
} else
if (ptr[j+1]=='@') {
char off[32];
int offlen;
offlen = snprintf (off, sizeof (off), "%d",
mac->counter);
- if ((i+offlen+1) >= sizeof (cmd))
+ if ((i + offlen + 1) >= sizeof (cmd)) {
return -1;
+ }
memcpy (cmd+i, off, offlen+1);
i += offlen-1;
j++;
@@ -525,7 +540,9 @@ R_API int r_cmd_macro_cmd_args(RCmdMacro *mac, const char *ptr, const char *args
cmd[i+1] = '\0';
}
}
- for (pcmd = cmd; *pcmd && (*pcmd==' ' || *pcmd == '\t'); pcmd++);
+ for (pcmd = cmd; *pcmd && (*pcmd == ' ' || *pcmd == '\t'); pcmd++) {
+ ;
+ }
//eprintf ("-pre %d\n", (int)mac->num->value);
int xx = (*pcmd==')')? 0: mac->cmd (mac->user, pcmd);
//eprintf ("-pos %p %d\n", mac->num, (int)mac->num->value);
@@ -534,7 +551,9 @@ R_API int r_cmd_macro_cmd_args(RCmdMacro *mac, const char *ptr, const char *args
R_API char *r_cmd_macro_label_process(RCmdMacro *mac, RCmdMacroLabel *labels, int *labels_n, char *ptr) {
int i;
- for (; *ptr==' '; ptr++);
+ for (; *ptr == ' '; ptr++) {
+ ;
+ }
if (ptr[strlen (ptr)-1]==':' && !strchr (ptr, ' ')) {
/* label detected */
if (ptr[0]=='.') {
@@ -552,12 +571,15 @@ R_API char *r_cmd_macro_label_process(RCmdMacro *mac, RCmdMacroLabel *labels, in
if (ptr[0]=='?' && ptr[1]=='!' && ptr[2] != '?') {
if (mac->num && mac->num->value != 0) {
char *label = ptr + 3;
- for (; *label==' '||*label=='.'; label++);
- // eprintf("===> GOTO %s\n", label);
+ for (; *label == ' ' || *label == '.'; label++) {
+ ;
+ }
+ // eprintf("===> GOTO %s\n", label);
/* goto label ptr+3 */
for (i=0;i<*labels_n;i++) {
- if (!strcmp (label, labels[i].name))
+ if (!strcmp (label, labels[i].name)) {
return labels[i].ptr;
+ }
}
return NULL;
}
@@ -566,12 +588,15 @@ R_API char *r_cmd_macro_label_process(RCmdMacro *mac, RCmdMacroLabel *labels, in
if (ptr[0]=='?' && ptr[1]=='?' && ptr[2] != '?') {
if (mac->num->value == 0) {
char *label = ptr + 3;
- for (;label[0]==' '||label[0]=='.'; label++);
- // eprintf("===> GOTO %s\n", label);
+ for (; label[0] == ' ' || label[0] == '.'; label++) {
+ ;
+ }
+ // eprintf("===> GOTO %s\n", label);
/* goto label ptr+3 */
for (i=0; i<*labels_n; i++) {
- if (!strcmp (label, labels[i].name))
+ if (!strcmp (label, labels[i].name)) {
return labels[i].ptr;
+ }
}
return NULL;
}
@@ -618,7 +643,9 @@ R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) {
eprintf ("Missing end ')' parenthesis.\n");
free (str);
return false;
- } else *ptr='\0';
+ } else {
+ *ptr = '\0';
+ }
args = strchr (str, ' ');
if (args) {
@@ -635,7 +662,9 @@ R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) {
return 0;
}
ptr = strchr (str, ',');
- if (ptr) *ptr =0;
+ if (ptr) {
+ *ptr = 0;
+ }
r_cons_break_push (NULL, NULL);
r_list_foreach (mac->macros, iter, m) {
@@ -651,7 +680,9 @@ R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) {
}
mac->brk = 0;
do {
- if (end) *end = '\0';
+ if (end) {
+ *end = '\0';
+ }
if (r_cons_is_breaked ()) {
eprintf ("Interrupted at (%s)\n", ptr);
if (end) {
@@ -669,7 +700,9 @@ R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) {
break;
} else if (ptr != ptr2) {
ptr = ptr2;
- if (end) *end ='\n';
+ if (end) {
+ *end = '\n';
+ }
end = strchr (ptr, '\n');
continue;
}
@@ -717,7 +750,8 @@ R_API int r_cmd_macro_break(RCmdMacro *mac, const char *value) {
mac->brk = 1;
mac->brk_value = NULL;
mac->_brk_value = (ut64)r_num_math (mac->num, value);
- if (value && *value)
+ if (value && *value) {
mac->brk_value = &mac->_brk_value;
+ }
return 0;
}
diff --git a/libr/core/core.c b/libr/core/core.c
index 73b835bfba..dd85070ae7 100644
--- a/libr/core/core.c
+++ b/libr/core/core.c
@@ -494,7 +494,9 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) {
return 0;
}
// pop state
- if (ok) *ok = 1;
+ if (ok) {
+ *ok = 1;
+ }
ut8 buf[sizeof (ut64)] = R_EMPTY;
(void)r_io_read_at (core->io, n, buf, R_MIN (sizeof (buf), refsz));
switch (refsz) {
@@ -709,7 +711,9 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) {
// NOTE: functions override flags
RAnalFunction *fcn = r_anal_fcn_find_name (core->anal, str);
if (fcn) {
- if (ok) *ok = true;
+ if (ok) {
+ *ok = true;
+ }
return fcn->addr;
}
#if 0
@@ -722,7 +726,9 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) {
#endif
if ((flag = r_flag_get (core->flags, str))) {
ret = flag->offset;
- if (ok) *ok = true;
+ if (ok) {
+ *ok = true;
+ }
return ret;
}
@@ -734,14 +740,18 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) {
const char *alias = r_reg_get_name (core->dbg->reg, role);
r = r_reg_get (core->dbg->reg, alias, -1);
if (r) {
- if (ok) *ok = true;
+ if (ok) {
+ *ok = true;
+ }
ret = r_reg_get_value (core->dbg->reg, r);
return ret;
}
}
}
else {
- if (ok) *ok = true;
+ if (ok) {
+ *ok = true;
+ }
ret = r_reg_get_value (core->dbg->reg, r);
return ret;
}
@@ -1557,7 +1567,9 @@ static int autocomplete(RLine *line) {
}
}
}
- if (j > 0) tmp_argv_heap = true;
+ if (j > 0) {
+ tmp_argv_heap = true;
+ }
tmp_argv[j] = NULL;
line->completion.argc = j;
line->completion.argv = tmp_argv;
@@ -1604,7 +1616,9 @@ static int autocomplete(RLine *line) {
}
}
}
- if (i > 0) tmp_argv_heap = true;
+ if (i > 0) {
+ tmp_argv_heap = true;
+ }
tmp_argv[i] = NULL;
ls_free (l);
line->completion.argc = i;
@@ -1623,7 +1637,9 @@ static int autocomplete(RLine *line) {
}
}
}
- if (i > 0) tmp_argv_heap = true;
+ if (i > 0) {
+ tmp_argv_heap = true;
+ }
tmp_argv[i] = NULL;
ls_free (l);
line->completion.argc = i;
@@ -1648,7 +1664,9 @@ static int autocomplete(RLine *line) {
}
}
}
- if (i > 0) tmp_argv_heap = true;
+ if (i > 0) {
+ tmp_argv_heap = true;
+ }
tmp_argv[i] = NULL;
ls_free (l);
line->completion.argc = i;
@@ -1820,29 +1838,41 @@ static char *r_core_anal_hasrefs_to_depth(RCore *core, ut64 value, int depth) {
R_FREE (mapname);
}
}
- if (fi) r_strbuf_appendf (s, " %s", fi->name);
- if (fcn) r_strbuf_appendf (s, " %s", fcn->name);
+ if (fi) {
+ r_strbuf_appendf (s, " %s", fi->name);
+ }
+ if (fcn) {
+ r_strbuf_appendf (s, " %s", fcn->name);
+ }
if (type) {
const char *c = r_core_anal_optype_colorfor (core, value, true);
const char *cend = (c && *c) ? Color_RESET: "";
- if (!c) c = "";
+ if (!c) {
+ c = "";
+ }
if (type & R_ANAL_ADDR_TYPE_HEAP) {
r_strbuf_appendf (s, " %sheap%s", c, cend);
} else if (type & R_ANAL_ADDR_TYPE_STACK) {
r_strbuf_appendf (s, " %sstack%s", c, cend);
}
- if (type & R_ANAL_ADDR_TYPE_PROGRAM)
+ if (type & R_ANAL_ADDR_TYPE_PROGRAM) {
r_strbuf_appendf (s, " %sprogram%s", c, cend);
- if (type & R_ANAL_ADDR_TYPE_LIBRARY)
+ }
+ if (type & R_ANAL_ADDR_TYPE_LIBRARY) {
r_strbuf_appendf (s, " %slibrary%s", c, cend);
- if (type & R_ANAL_ADDR_TYPE_ASCII)
+ }
+ if (type & R_ANAL_ADDR_TYPE_ASCII) {
r_strbuf_appendf (s, " %sascii%s", c, cend);
- if (type & R_ANAL_ADDR_TYPE_SEQUENCE)
+ }
+ if (type & R_ANAL_ADDR_TYPE_SEQUENCE) {
r_strbuf_appendf (s, " %ssequence%s", c, cend);
- if (type & R_ANAL_ADDR_TYPE_READ)
+ }
+ if (type & R_ANAL_ADDR_TYPE_READ) {
r_strbuf_appendf (s, " %sR%s", c, cend);
- if (type & R_ANAL_ADDR_TYPE_WRITE)
+ }
+ if (type & R_ANAL_ADDR_TYPE_WRITE) {
r_strbuf_appendf (s, " %sW%s", c, cend);
+ }
if (type & R_ANAL_ADDR_TYPE_EXEC) {
RAsmOp op;
ut8 buf[32];
@@ -2437,7 +2467,9 @@ R_API void r_core_prompt_loop(RCore *r) {
static int prompt_flag (RCore *r, char *s, size_t maxlen) {
const char DOTS[] = "...";
const RFlagItem *f = r_flag_get_at (r->flags, r->offset, false);
- if (!f) return false;
+ if (!f) {
+ return false;
+ }
if (f->offset < r->offset) {
snprintf (s, maxlen, "%s + %" PFMT64u, f->name, r->offset - f->offset);
@@ -2487,8 +2519,9 @@ static void set_prompt (RCore *r) {
const char *END = "";
const char *remote = "";
- if (cmdprompt && *cmdprompt)
+ if (cmdprompt && *cmdprompt) {
r_core_cmd (r, cmdprompt, 0);
+ }
if (r_config_get_i (r->config, "scr.prompt.file")) {
free (filename);
diff --git a/libr/core/disasm.c b/libr/core/disasm.c
index f6bb8b6a89..13fe30ae0c 100644
--- a/libr/core/disasm.c
+++ b/libr/core/disasm.c
@@ -2261,7 +2261,9 @@ static void ds_print_lines_right(RDisasmState *ds){
static void printCol(RDisasmState *ds, char *sect, int cols, const char *color) {
int pre, post;
- if (cols < 8) cols = 8;
+ if (cols < 8) {
+ cols = 8;
+ }
int outsz = cols + 32;
char *out = malloc (outsz);
if (!out) {
@@ -2902,7 +2904,9 @@ static void ds_print_show_bytes(RDisasmState *ds) {
str = flagstr;
if (ds->nb > 0) {
k = ds->nb - strlen (flagstr) - 1;
- if (k < 0 || k > sizeof(pad)) k = 0;
+ if (k < 0 || k > sizeof (pad)) {
+ k = 0;
+ }
for (j = 0; j < k; j++) {
pad[j] = ' ';
}
@@ -4470,15 +4474,23 @@ static char *_find_next_number(char *op) {
if (p) {
while (*p) {
// look for start of next separator or ANSI sequence
- while (*p && !IS_SEPARATOR (*p) && *p != 0x1b) p++;
+ while (*p && !IS_SEPARATOR (*p) && *p != 0x1b) {
+ p++;
+ }
if (*p == 0x1b) {
// skip to end of ANSI sequence (lower or uppercase char)
- while (*p && !(*p >= 'A' && *p <= 'Z') && !(*p >= 'a' && *p <= 'z')) p++;
- if (*p) p++;
+ while (*p && !(*p >= 'A' && *p <= 'Z') && !(*p >= 'a' && *p <= 'z')) {
+ p++;
+ }
+ if (*p) {
+ p++;
+ }
}
if (IS_SEPARATOR (*p)) {
// skip to end of separator
- while (*p && IS_SEPARATOR (*p)) p++;
+ while (*p && IS_SEPARATOR (*p)) {
+ p++;
+ }
}
if (IS_DIGIT (*p)) {
// we found the start of the next number
diff --git a/libr/core/hack.c b/libr/core/hack.c
index c367987331..2a61672fe6 100644
--- a/libr/core/hack.c
+++ b/libr/core/hack.c
@@ -149,20 +149,23 @@ R_API bool r_core_hack_arm(RCore *core, const char *op, const RAnalOp *analop) {
eprintf ("TODO: use jnz or jz\n");
return false;
} else if (!strcmp (op, "ret1")) {
- if (bits == 16)
+ if (bits == 16) {
r_core_cmd0 (core, "wx 01207047 @@ $$+1\n"); // mov r0, 1; bx lr
- else
+ } else {
r_core_cmd0 (core, "wx 0100b0e31eff2fe1 @@ $$+1\n"); // movs r0, 1; bx lr
+ }
} else if (!strcmp (op, "ret0")) {
- if (bits == 16)
+ if (bits == 16) {
r_core_cmd0 (core, "wx 00207047 @@ $$+1\n"); // mov r0, 0; bx lr
- else
+ } else {
r_core_cmd0 (core, "wx 0000a0e31eff2fe1 @@ $$+1\n"); // movs r0, 0; bx lr
+ }
} else if (!strcmp (op, "retn")) {
- if (bits == 16)
+ if (bits == 16) {
r_core_cmd0 (core, "wx ff207047 @@ $$+1\n"); // mov r0, -1; bx lr
- else
+ } else {
r_core_cmd0 (core, "wx ff00a0e31eff2fe1 @@ $$+1\n"); // movs r0, -1; bx lr
+ }
} else {
eprintf ("Invalid operation\n");
return false;
@@ -174,13 +177,16 @@ R_API bool r_core_hack_x86(RCore *core, const char *op, const RAnalOp *analop) {
const ut8 *b = core->block;
int i, size = analop->size;
if (!strcmp (op, "nop")) {
- if (size * 2 + 1 < size) return false;
+ if (size * 2 + 1 < size) {
+ return false;
+ }
char *str = malloc (size * 2 + 1);
if (!str) {
return false;
}
- for (i = 0; i < size; i++)
+ for (i = 0; i < size; i++) {
memcpy (str + (i * 2), "90", 2);
+ }
str[size*2] = '\0';
r_core_cmdf (core, "wx %s\n", str);
free (str);
diff --git a/libr/core/p/core_java.c b/libr/core/p/core_java.c
index fe9b27c67f..95ea2bc9b5 100644
--- a/libr/core/p/core_java.c
+++ b/libr/core/p/core_java.c
@@ -290,10 +290,18 @@ enum {
};
static ut8 _(r_cmd_java_obj_ref)(const char *name, const char *class_name, ut32 len) {
- if (!name || !class_name) return false;
- if (strncmp (class_name, name, len)) return false;
- if (*(name-1) == 'L' && *(name+len) == ';') return true;
- if (!strncmp (class_name, name, len) && !*(name+len)) return true;
+ if (!name || !class_name) {
+ return false;
+ }
+ if (strncmp (class_name, name, len)) {
+ return false;
+ }
+ if (*(name - 1) == 'L' && *(name + len) == ';') {
+ return true;
+ }
+ if (!strncmp (class_name, name, len) && !*(name + len)) {
+ return true;
+ }
return false;
}
@@ -304,7 +312,9 @@ static const char * r_cmd_get_next_classname_str (const char * str, const char *
result = str;
while (result && *result && (result - str < len)) {
result = strstr (result, match_me);
- if (result ) break;
+ if (result) {
+ break;
+ }
}
}
return result;
@@ -315,7 +325,9 @@ static ut32 r_cmd_get_num_classname_str_occ (const char * str, const char *match
ut32 len = match_me && *match_me ? strlen (match_me) : 0;
ut32 occ = 0;
- if (len == 0 || !str || !*str ) return 0;
+ if (len == 0 || !str || !*str) {
+ return 0;
+ }
result = str;
while (result && *result && (result - str < len)) {
result = strstr (result, match_me);
@@ -331,8 +343,12 @@ static ut32 r_cmd_get_num_classname_str_occ (const char * str, const char *match
static const char * r_cmd_java_consumetok (const char *str1, const char b, size_t len) {
const char *p = str1;
size_t i = 0;
- if (!p) return p;
- if (len == -1) len = strlen (str1);
+ if (!p) {
+ return p;
+ }
+ if (len == -1) {
+ len = strlen (str1);
+ }
for ( ; i < len; i++,p++) {
if (*p != b) {
break;
@@ -344,8 +360,12 @@ static const char * r_cmd_java_consumetok (const char *str1, const char b, size_
static const char * r_cmd_java_strtok (const char *str1, const char b, size_t len) {
const char *p = str1;
size_t i = 0;
- if (!p || !*p) return p;
- if (len == -1) len = strlen (str1);
+ if (!p || !*p) {
+ return p;
+ }
+ if (len == -1) {
+ len = strlen (str1);
+ }
IFDBG r_cons_printf ("Looking for char (%c) in (%s) up to %d\n", b, p, len);
for ( ; i < len; i++,p++) {
if (*p == b) {
@@ -353,7 +373,9 @@ static const char * r_cmd_java_strtok (const char *str1, const char b, size_t le
break;
}
}
- if (i == len) p = NULL;
+ if (i == len) {
+ p = NULL;
+ }
IFDBG r_cons_printf ("Found? for char (%c) @ %d: (%s)\n", b, len, p);
return p;
}
@@ -433,30 +455,40 @@ static int _(r_cmd_java_check_op_idx) (const ut8 *op_bytes, ut16 idx) {
/* Find stuff in the constant pool */
static RList * cpfind_double (RCore *core, RBinJavaObj *obj, const char *cmd) {
double value = cmd && *cmd ? strtod (cmd, NULL) : 0.0;
- if (value == 0.0 && !(cmd && cmd[0] == '0' && cmd[1] == '.' && cmd[2] == '0') ) return r_list_new();
+ if (value == 0.0 && !(cmd && cmd[0] == '0' && cmd[1] == '.' && cmd[2] == '0')) {
+ return r_list_new ();
+ }
return r_bin_java_find_cp_const_by_val ( obj, (const ut8 *) &value, 8, R_BIN_JAVA_CP_DOUBLE);
}
static RList * cpfind_float (RCore *core, RBinJavaObj *obj, const char *cmd) {
float value = cmd && *cmd ? atof (cmd) : 0.0;
- if (value == 0.0 && !(cmd && cmd[0] == '0' && cmd[1] == '.' && cmd[2] == '0') ) return r_list_new();
+ if (value == 0.0 && !(cmd && cmd[0] == '0' && cmd[1] == '.' && cmd[2] == '0')) {
+ return r_list_new ();
+ }
return r_bin_java_find_cp_const_by_val ( obj, (const ut8 *) &value, 4, R_BIN_JAVA_CP_FLOAT);
}
static RList * cpfind_long (RCore *core, RBinJavaObj *obj, const char *cmd) {
ut64 value = r_cmd_java_get_input_num_value (core, cmd);
- if ( !r_cmd_java_is_valid_input_num_value (core, cmd) ) return r_list_new ();
+ if (!r_cmd_java_is_valid_input_num_value (core, cmd)) {
+ return r_list_new ();
+ }
return r_bin_java_find_cp_const_by_val ( obj, (const ut8 *) &value, 8, R_BIN_JAVA_CP_LONG);
}
static RList * cpfind_int (RCore *core, RBinJavaObj *obj, const char *cmd) {
ut32 value = (ut32) r_cmd_java_get_input_num_value (core, cmd);
- if ( !r_cmd_java_is_valid_input_num_value (core, cmd) ) return r_list_new ();
+ if (!r_cmd_java_is_valid_input_num_value (core, cmd)) {
+ return r_list_new ();
+ }
return r_bin_java_find_cp_const_by_val ( obj, (const ut8 *) &value, 4, R_BIN_JAVA_CP_INTEGER);
}
static RList * cpfind_str (RCore *core, RBinJavaObj *obj, const char *cmd) {
- if (!cmd) return r_list_new();
+ if (!cmd) {
+ return r_list_new ();
+ }
IFDBG r_cons_printf ("Looking for str: %s (%d)\n", cmd, strlen (cmd));
return r_bin_java_find_cp_const_by_val ( obj, (const ut8 *) cmd, strlen (cmd), R_BIN_JAVA_CP_UTF8);
}
@@ -500,7 +532,9 @@ static int cpfind (RCore *core, const char *cmd) {
}
static int r_cmd_java_reload_bin_from_buf (RCore *core, RBinJavaObj *obj, ut8* buffer, ut64 len) {
- if (!buffer || len < 10) return false;
+ if (!buffer || len < 10) {
+ return false;
+ }
int res = r_bin_java_load_bin (obj, buffer, len);
if (res == true) {
@@ -528,7 +562,9 @@ static int r_cmd_java_get_cp_bytes_and_write (RCore *core, RBinJavaObj *obj, ut1
ut32 n_sz = 0, c_sz = obj ? r_bin_java_cp_get_size (obj, idx): -1;
ut8 * bytes = NULL;
- if (c_sz == -1) return res;
+ if (c_sz == -1) {
+ return res;
+ }
bytes = r_bin_java_cp_get_bytes (cp_obj->tag, &n_sz, buf, len);
@@ -567,7 +603,9 @@ static int r_cmd_java_get_cp_bytes_and_write (RCore *core, RBinJavaObj *obj, ut1
if (res == true) {
res = r_cmd_java_reload_bin_from_buf (
core, obj, bin_buffer, n_file_sz);
- } else eprintf ("[X] r_cmd_java_get_cp_bytes_and_write: Failed to read the file in aborted, bin reload.\n");
+ } else {
+ eprintf ("[X] r_cmd_java_get_cp_bytes_and_write: Failed to read the file in aborted, bin reload.\n");
+ }
free (bin_buffer);
}
}
@@ -730,8 +768,9 @@ static char * r_cmd_replace_name (const char *s_new, ut32 replace_len, const cha
}
IFDBG r_cons_printf ("Found last occurrence of: \"%s\", remaining: %s\n", s_old, buffer+consumed);
IFDBG r_cons_printf ("result is: \"%s\"\n", result);
- for (; consumed < buf_len; consumed++, p_result++, (*res_len)++)
- *p_result = *(buffer+consumed);
+ for (; consumed < buf_len; consumed++, p_result++, (*res_len)++) {
+ *p_result = *(buffer + consumed);
+ }
IFDBG r_cons_printf ("Old: %s\nNew: %s\n", buffer, result);
}
return result;
@@ -744,9 +783,13 @@ static int r_cmd_java_get_class_names_from_input (const char *input, char **clas
ut32 cmd_sz = input && *input ? strlen (input) : 0;
int res = false;
- if (!class_name || *class_name) return res;
- else if (!new_class_name || *new_class_name) return res;
- else if (!new_class_name_len || !class_name_len) return res;
+ if (!class_name || *class_name) {
+ return res;
+ } else if (!new_class_name || *new_class_name) {
+ return res;
+ } else if (!new_class_name_len || !class_name_len) {
+ return res;
+ }
*new_class_name = NULL;
*class_name_len = 0;
@@ -767,7 +810,9 @@ static int r_cmd_java_get_class_names_from_input (const char *input, char **clas
p = r_cmd_java_consumetok (end+1, ' ', cmd_sz);
end = p && *p ? r_cmd_java_strtok (p, ' ', -1) : NULL;
- if (!end && p && *p) end = p + cmd_sz;
+ if (!end && p && *p) {
+ end = p + cmd_sz;
+ }
if (p && end && p != end) {
*new_class_name_len = end - p + 1;
@@ -819,7 +864,9 @@ static int r_cmd_java_handle_replace_classname_value (RCore *core, const char *c
ut64 addr = cp_obj->file_offset + cp_obj->loadaddr;
buffer = r_bin_java_cp_get_idx_bytes (obj, idx, &buffer_sz);
- if (!buffer) continue;
+ if (!buffer) {
+ continue;
+ }
len = R_BIN_JAVA_USHORT ( buffer, 1);
name = malloc (len+3);
memcpy (name, buffer+3, len);
@@ -879,7 +926,9 @@ static int r_cmd_java_handle_reload_bin (RCore *core, const char *cmd) {
}
addr = r_cmd_java_is_valid_input_num_value(core, p) ? r_cmd_java_get_input_num_value (core, p) : -1;
- if (*cmd == ' ') p = r_cmd_java_consumetok (p, ' ', -1);
+ if (*cmd == ' ') {
+ p = r_cmd_java_consumetok (p, ' ', -1);
+ }
buf_size = r_cmd_java_is_valid_input_num_value(core, p) ? r_cmd_java_get_input_num_value (core, p) : -1;
// XXX this may cause problems cause the file we are looking at may not be the bin we want.
@@ -908,8 +957,11 @@ static int r_cmd_java_handle_find_cp_const (RCore *core, const char *cmd) {
ut16 idx = -1;
RList *find_list;
- if (p && *p == 'a') idx = -1;
- else idx = r_cmd_java_get_input_num_value (core, p);
+ if (p && *p == 'a') {
+ idx = -1;
+ } else {
+ idx = r_cmd_java_get_input_num_value (core, p);
+ }
IFDBG r_cons_printf ("Function call made: %s\n", cmd);
@@ -937,13 +989,17 @@ static int r_cmd_java_handle_find_cp_const (RCore *core, const char *cmd) {
case 0x12:
cp_res = (idx == (ut16) -1) || (bb->op_bytes[1] == idx) ?
R_NEW0(RCmdJavaCPResult) : NULL;
- if (cp_res) cp_res->idx = bb->op_bytes[1];
+ if (cp_res) {
+ cp_res->idx = bb->op_bytes[1];
+ }
break;
case 0x13:
case 0x14:
cp_res = (idx == (ut16) -1) || (R_BIN_JAVA_USHORT (bb->op_bytes, 1) == idx) ?
R_NEW0(RCmdJavaCPResult) : NULL;
- if (cp_res) cp_res->idx = R_BIN_JAVA_USHORT (bb->op_bytes, 1);
+ if (cp_res) {
+ cp_res->idx = R_BIN_JAVA_USHORT (bb->op_bytes, 1);
+ }
break;
}
@@ -1051,7 +1107,9 @@ static int r_cmd_java_handle_calc_class_sz (RCore *core, const char *cmd) {
buf = realloc (buf, sz);
ut64 r_sz = r_io_read_at (core->io, addr, buf, sz) ? sz : 0LL;
// check the return read on the read
- if (r_sz == 0) break;
+ if (r_sz == 0) {
+ break;
+ }
res_size = r_bin_java_calc_class_size (buf, sz);
// if the data buffer contains a class starting
// at address, then the res_size will be the size
@@ -1067,8 +1125,11 @@ static int r_cmd_java_handle_calc_class_sz (RCore *core, const char *cmd) {
sz += (1 << 16);
}
}
- if (res) r_cons_printf ("%"PFMT64d, res_size);
- else r_cons_printf ("-1\n");
+ if (res) {
+ r_cons_printf ("%" PFMT64d, res_size);
+ } else {
+ r_cons_printf ("-1\n");
+ }
//snprintf (cmd_buf, 50, fmt, num_acc_flag, addr);
//res = r_core_cmd0(core, y);
@@ -1098,7 +1159,9 @@ static int r_cmd_java_handle_isvalid (RCore *core, const char *cmd) {
buf = realloc (buf, sz);
ut64 r_sz = r_io_read_at (core->io, addr, buf, sz) ? sz : 0LL;
// check the return read on the read
- if (r_sz == 0) break;
+ if (r_sz == 0) {
+ break;
+ }
res_size = r_bin_java_calc_class_size (buf, sz);
// if the data buffer contains a class starting
// at address, then the res_size will be the size
@@ -1114,10 +1177,14 @@ static int r_cmd_java_handle_isvalid (RCore *core, const char *cmd) {
sz <<= 1;
}
}
- if (res) r_cons_printf ("True\n");
- else r_cons_printf ("False\n");
- } else
- r_cmd_java_print_cmd_help (JAVA_CMDS+ISVALID_IDX);
+ if (res) {
+ r_cons_printf ("True\n");
+ } else {
+ r_cons_printf ("False\n");
+ }
+ } else {
+ r_cmd_java_print_cmd_help (JAVA_CMDS + ISVALID_IDX);
+ }
return true;
}
@@ -1233,8 +1300,9 @@ static int r_cmd_java_handle_flags_str (RCore *core, const char *cmd) {
char * flags_str = NULL;
IFDBG r_cons_printf ("r_cmd_java_handle_flags_str: ftype = %c, idx = %s\n", f_type, p);
- if (p)
- flag_value = r_cmd_java_is_valid_input_num_value(core, p) ? r_cmd_java_get_input_num_value (core, p) : -1;
+ if (p) {
+ flag_value = r_cmd_java_is_valid_input_num_value (core, p) ? r_cmd_java_get_input_num_value (core, p) : -1;
+ }
if (p && f_type) {
switch (f_type) {
@@ -1279,7 +1347,9 @@ static int r_cmd_java_handle_flags_str_at (RCore *core, const char *cmd) {
flag_value_addr = r_cmd_java_is_valid_input_num_value(core, p) ? r_cmd_java_get_input_num_value (core, p) : -1;
r_io_read_at (core->io, flag_value_addr, (ut8 *) &flag_value, 2);
IFDBG r_cons_printf ("r_cmd_java_handle_flags_str_at: read = 0x%04x\n", flag_value);
- if (cur_offset != core->offset) r_core_seek (core, cur_offset-2, 1);
+ if (cur_offset != core->offset) {
+ r_core_seek (core, cur_offset - 2, 1);
+ }
flag_value = R_BIN_JAVA_USHORT (((ut8 *) &flag_value), 0);
}
@@ -1344,9 +1414,12 @@ static int r_cmd_java_handle_set_flags (RCore * core, const char * input) {
}
IFDBG r_cons_printf ("Converting %s to flags\n",p);
- if (p) p+=2;
- if (flag_value == -1)
- flag_value = r_cmd_java_is_valid_input_num_value(core, p) ? r_cmd_java_get_input_num_value (core, p) : -1;
+ if (p) {
+ p += 2;
+ }
+ if (flag_value == -1) {
+ flag_value = r_cmd_java_is_valid_input_num_value (core, p) ? r_cmd_java_get_input_num_value (core, p) : -1;
+ }
if (!input) {
eprintf ("[-] r_cmd_java: no address provided .\n");
@@ -1408,7 +1481,9 @@ static int r_cmd_java_call(void *user, const char *input) {
strncmp (input+5, JAVA_CMDS[i].name, JAVA_CMDS[i].name_len));
if (!strncmp (input + 5, JAVA_CMDS[i].name, JAVA_CMDS[i].name_len)) {
const char *cmd = input + 5 + JAVA_CMDS[i].name_len;
- if (*cmd && *cmd == ' ') cmd++;
+ if (*cmd && *cmd == ' ') {
+ cmd++;
+ }
//IFDBG r_cons_printf ("Executing cmd: %s (%s)\n", JAVA_CMDS[i].name, cmd+5+JAVA_CMDS[i].name_len );
res = JAVA_CMDS[i].handler (core, cmd);
break;
@@ -1473,7 +1548,9 @@ static int r_cmd_java_print_all_definitions( RAnal *anal ) {
RListIter *iter;
RBinJavaObj *obj;
- if (!obj_list) return 1;
+ if (!obj_list) {
+ return 1;
+ }
r_list_foreach (obj_list, iter, obj) {
r_cmd_java_print_class_definitions (obj);
}
@@ -1551,11 +1628,13 @@ static RBinJavaObj * r_cmd_java_get_bin_obj(RAnal *anal) {
RBin *b;
int is_java;
RBinPlugin *plugin;
- if (!anal || !anal->binb.bin)
+ if (!anal || !anal->binb.bin) {
return NULL;
+ }
b = anal->binb.bin;
- if (!b->cur || !b->cur->o)
+ if (!b->cur || !b->cur->o) {
return NULL;
+ }
plugin = b->cur->o->plugin;
is_java = (plugin && strcmp (plugin->name, "java") == 0) ? 1 : 0;
return is_java ? b->cur->o->bin_obj : NULL;
@@ -1591,10 +1670,11 @@ static int r_cmd_java_resolve_cp_idx_b64 (RBinJavaObj *obj, ut16 idx) {
static int r_cmd_java_resolve_cp_address (RBinJavaObj *obj, ut16 idx) {
if (obj && idx){
ut64 addr = r_bin_java_resolve_cp_idx_address (obj, idx) ;
- if (addr == -1)
+ if (addr == -1) {
r_cons_printf ("Unable to resolve CP Object @ index: 0x%04x\n", idx);
- else
- r_cons_printf ("0x%"PFMT64x"\n", addr);
+ } else {
+ r_cons_printf ("0x%" PFMT64x "\n", addr);
+ }
}
return true;
}
@@ -1758,7 +1838,9 @@ static char * r_cmd_java_get_descriptor (RCore *core, RBinJavaObj *bin, ut16 idx
fullname = malloc (fn_len);
snprintf (fullname, fn_len, "%s.%s", class_name, name);
}
- if (fullname) prototype = r_bin_java_unmangle_without_flags (fullname, descriptor);
+ if (fullname) {
+ prototype = r_bin_java_unmangle_without_flags (fullname, descriptor);
+ }
free (class_name);
free (name);
free (descriptor);
@@ -1790,14 +1872,18 @@ static int r_cmd_java_handle_list_code_references (RCore *core, const char *inpu
r_list_foreach (anal->fcns, fcn_iter, fcn) {
ut8 do_this_one = func_addr == -1 || r_anal_fcn_is_in_offset (fcn, func_addr);
- if (!do_this_one) continue;
+ if (!do_this_one) {
+ continue;
+ }
r_list_foreach (fcn->bbs, bb_iter, bb) {
char *operation = NULL, *type = NULL;
ut64 addr = -1;
ut16 cp_ref_idx = -1;
char *full_bird = NULL;
// if bb_type is a call
- if (bb->op_bytes[0] == 0x01) continue;
+ if (bb->op_bytes[0] == 0x01) {
+ continue;
+ }
if (bb->op_bytes[0] == 0x12) {
// loading a constant
addr = bb->addr;
@@ -1886,18 +1972,23 @@ static int r_cmd_java_handle_yara_code_extraction_refs (RCore *core, const char
ut64 addr = -1, count = -1;
int res = false;
- if (!bin) return res;
- else if (!anal || !anal->fcns || r_list_length (anal->fcns) == 0) {
+ if (!bin) {
+ return res;
+ } else if (!anal || !anal->fcns || r_list_length (anal->fcns) == 0) {
eprintf ("Unable to access the current analysis, perform 'af' for function analysis.\n");
return true;
}
- if (!p) return res;
+ if (!p) {
+ return res;
+ }
n = *p ? r_cmd_java_strtok (p, ' ', -1) : NULL;
name = n && p && p != n ? malloc (n - p + 2) : NULL;
- if (!name) return res;
+ if (!name) {
+ return res;
+ }
memset (name, 0, n-p);
memcpy (name, p, n-p);
@@ -1940,12 +2031,16 @@ static int r_cmd_java_handle_insert_method_ref (RCore *core, const char *input)
eprintf ("Unable to access the current analysis, perform 'af' for function analysis.\n");
return true;
}
- if (!p) return res;
+ if (!p) {
+ return res;
+ }
n = p && *p ? r_cmd_java_strtok (p, ' ', -1) : NULL;
classname = n && p && p != n ? malloc (n-p+1) : NULL;
cn_sz = n && p ? n-p +1 : 0;
- if (!classname) return res;
+ if (!classname) {
+ return res;
+ }
snprintf (classname, cn_sz, "%s", p);
//memset (classname, 0, cn_sz);
@@ -2000,14 +2095,18 @@ static int r_cmd_java_handle_print_exceptions (RCore *core, const char *input) {
const char *p = input? r_cmd_java_consumetok (input, ' ', -1): NULL;
func_addr = p && *p && r_cmd_java_is_valid_input_num_value(core, p) ? r_cmd_java_get_input_num_value (core, p) : -1;
- if (!bin) return false;
+ if (!bin) {
+ return false;
+ }
r_list_foreach (bin->methods_list, methods_iter, method) {
ut64 start = r_bin_java_get_method_start(bin, method),
end = r_bin_java_get_method_end(bin, method);
ut8 do_this_one = start <= func_addr && func_addr <= end; RList * exc_table = NULL;
do_this_one = func_addr == -1 ? 1 : do_this_one;
- if (!do_this_one) continue;
+ if (!do_this_one) {
+ continue;
+ }
exc_table = r_bin_java_get_method_exception_table_with_addr (bin, start);
if (r_list_length (exc_table) == 0){
diff --git a/libr/core/patch.c b/libr/core/patch.c
index d122a0acdb..db86b93fca 100644
--- a/libr/core/patch.c
+++ b/libr/core/patch.c
@@ -9,12 +9,16 @@ R_API int r_core_patch_line (RCore *core, char *str) {
return 0;
}
*p = 0;
- for (++p; *p == ' '; p++); // XXX: skipsspaces here
+ for (++p; *p == ' '; p++) {
+ ; // XXX: skipsspaces here
+ }
switch (*p) {
case '"':
q = strchr (p + 1,'"');
- if (q) *q = 0;
+ if (q) {
+ *q = 0;
+ }
r_core_cmdf (core, "s %s", str);
r_core_cmdf (core, "\"w %s\"", p+1);
break;
@@ -26,7 +30,9 @@ R_API int r_core_patch_line (RCore *core, char *str) {
q = strchr (p + 1,' ');
if (q) {
*q = 0;
- for (++q; *q == ' '; q++); // XXX: skipsspaces here
+ for (++q; *q == ' '; q++) {
+ ; // XXX: skipsspaces here
+ }
} else {
return 0;
}
@@ -60,8 +66,9 @@ static int __core_patch_bracket(RCore *core, const char *str, ut64 *noff) {
p++;
continue;
}
- if (*str == '}')
+ if (*str == '}') {
break;
+ }
if ((q = strstr (str, "${"))) {
char *end = strchr (q+2,'}');
if (end) {
diff --git a/libr/core/rtr.c b/libr/core/rtr.c
index e7cca26738..2cb19adfce 100644
--- a/libr/core/rtr.c
+++ b/libr/core/rtr.c
@@ -329,8 +329,16 @@ TODO:
case '*': free (rtrcmd (T, "b+16")); break;
case '-': free (rtrcmd (T, "b-1")); break;
case '/': free (rtrcmd (T, "b-16")); break;
- case 'p': cmdidx++; if (!cmds[cmdidx]) cmdidx = 0; break;
- case 'P': cmdidx--; if (cmdidx<0) cmdidx = 2; break;
+ case 'p': cmdidx++;
+ if (!cmds[cmdidx]) {
+ cmdidx = 0;
+ }
+ break;
+ case 'P': cmdidx--;
+ if (cmdidx < 0) {
+ cmdidx = 2;
+ }
+ break;
case 'q': return false;
}
}
@@ -368,7 +376,9 @@ static char *rtr_dir_files (const char *path) {
RList *files = r_sys_dir (path);
eprintf ("Listing directory %s\n", path);
r_list_foreach (files, iter, file) {
- if (file[0] == '.') continue;
+ if (file[0] == '.') {
+ continue;
+ }
ptr = r_str_appendf (ptr, "%s
\n",
path, file, file);
}
@@ -1374,8 +1384,9 @@ R_API void r_core_rtr_pushout(RCore *core, const char *input) {
R_API void r_core_rtr_list(RCore *core) {
int i;
for (i = 0; i < RTR_MAX_HOSTS; i++) {
- if (!rtr_host[i].fd)
+ if (!rtr_host[i].fd) {
continue;
+ }
r_cons_printf ("%i - ", rtr_host[i].fd->fd);
switch (rtr_host[i].proto) {
case RTR_PROT_HTTP: r_cons_printf ( "http://"); break;
@@ -1413,8 +1424,9 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) {
proto = RTR_PROT_RAP;
host = input;
}
- while (*host && IS_WHITECHAR (*host))
+ while (*host && IS_WHITECHAR (*host)) {
host++;
+ }
if (!(ptr = strchr (host, ':'))) {
ptr = host;
@@ -1466,8 +1478,12 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) {
for (;;) {
r_line_set_prompt (prompt);
res = r_line_readline ();
- if (!res || !*res) break;
- if (*res == 'q') break;
+ if (!res || !*res) {
+ break;
+ }
+ if (*res == 'q') {
+ break;
+ }
if (!strcmp (res, "!sh")) {
for (;;) {
r_line_set_prompt (prompt2);
@@ -1481,7 +1497,9 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) {
if (str) {
str[len] = 0;
res = strstr (str, "\n\n");
- if (res) res = strstr (res+1, "\n\n");
+ if (res) {
+ res = strstr (res + 1, "\n\n");
+ }
res = res? res + 2: str;
const char *tail = (res[strlen (res) - 1] == '\n')? "": "\n";
printf ("%s%s", res, tail);
@@ -1501,15 +1519,25 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) {
rtr_textlog_chat (core, T);
} else {
ptr = r_str_uri_encode (res);
- if (ptr) res = ptr;
+ if (ptr) {
+ res = ptr;
+ }
char *uri = r_str_newf ("http://%s:%s/%s%s", host, port, file, res);
- if (ptr == res) free (ptr);
+ if (ptr == res) {
+ free (ptr);
+ }
str = r_socket_http_get (uri, NULL, &len);
if (str && len > 0) {
str[len] = 0;
res = strstr (str, "\n\n");
- if (res) res = strstr (res+1, "\n\n");
- if (res) res += 2; else res = str;
+ if (res) {
+ res = strstr (res + 1, "\n\n");
+ }
+ if (res) {
+ res += 2;
+ } else {
+ res = str;
+ }
printf ("%s%s", res, (*res && res[strlen (res)-1] == '\n') ? "" : "\n");
r_line_hist_add (str);
}
@@ -1523,10 +1551,14 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) {
if (str) {
str[len] = 0;
res = strstr (str, "\n\n");
- if (res) res = strstr (res + 1, "\n\n");
+ if (res) {
+ res = strstr (res + 1, "\n\n");
+ }
printf ("%s", res? res + 2: str);
free (str);
- } else eprintf ("HTTP connection has failed\n");
+ } else {
+ eprintf ("HTTP connection has failed\n");
+ }
free (http_uri);
}
r_socket_free (fd);
@@ -1602,15 +1634,17 @@ R_API void r_core_rtr_remove(RCore *core, const char *input) {
if (IS_DIGIT(input[0])) {
fd = r_num_math (core->num, input);
- for (i = 0; i < RTR_MAX_HOSTS; i++)
+ for (i = 0; i < RTR_MAX_HOSTS; i++) {
if (rtr_host[i].fd && rtr_host[i].fd->fd == fd) {
r_socket_free (rtr_host[i].fd);
rtr_host[i].fd = NULL;
if (rtr_n == i) {
- for (rtr_n = 0; !rtr_host[rtr_n].fd \
- && rtr_n < RTR_MAX_HOSTS - 1; rtr_n++);
+ for (rtr_n = 0; !rtr_host[rtr_n].fd && rtr_n < RTR_MAX_HOSTS - 1; rtr_n++) {
+ ;
+ }
}
break;
+ }
}
} else {
for (i = 0; i < RTR_MAX_HOSTS; i++) {
@@ -1631,9 +1665,9 @@ R_API void r_core_rtr_session(RCore *core, const char *input) {
prompt[0] = 0;
if (IS_DIGIT (input[0])) {
fd = r_num_math (core->num, input);
- for (rtr_n = 0; rtr_host[rtr_n].fd \
- && rtr_host[rtr_n].fd->fd != fd \
- && rtr_n < RTR_MAX_HOSTS - 1; rtr_n++);
+ for (rtr_n = 0; rtr_host[rtr_n].fd && rtr_host[rtr_n].fd->fd != fd && rtr_n < RTR_MAX_HOSTS - 1; rtr_n++) {
+ ;
+ }
}
while (!r_cons_is_breaked ()) {
@@ -1836,7 +1870,9 @@ R_API char *r_core_rtr_cmds_query (RCore *core, const char *host, const char *po
//r_socket_write (s, "px\n", 3);
for (;;) {
int ret = r_socket_read (s, buf, sizeof (buf));
- if (ret < 1) break;
+ if (ret < 1) {
+ break;
+ }
buf[ret] = 0;
rbuf = r_str_append (rbuf, (const char *)buf);
}
diff --git a/libr/core/vmenus.c b/libr/core/vmenus.c
index 95eeaafd0f..072e8bc960 100644
--- a/libr/core/vmenus.c
+++ b/libr/core/vmenus.c
@@ -494,12 +494,13 @@ static int sdbforcb (void *p, const char *k, const char *v) {
vt->curfmt = strdup (v);
pre = ">";
}
- if (use_color && *pre=='>')
+ if (use_color && *pre == '>') {
r_cons_printf ("%s %s %s %s\n", color_sel,
Color_RESET, pre, k+strlen (s), v);
- else
+ } else {
r_cons_printf (" %s %s %s\n",
- pre, k+strlen (s), v);
+ pre, k + strlen (s), v);
+ }
vt->t_ctr ++;
}
free (s);
@@ -871,7 +872,9 @@ static bool r_core_visual_config_hud(RCore *core) {
RListIter *iter;
RConfigNode *bt;
RList *list = r_list_new ();
- if (!list) return false;
+ if (!list) {
+ return false;
+ }
char *res;
list->free = free;
r_list_foreach (core->config->nodes, iter, bt) {
@@ -882,15 +885,18 @@ static bool r_core_visual_config_hud(RCore *core) {
const char *oldvalue = NULL;
char cmd[512];
char *p = strchr (res, ' ');
- if (p) *p = 0;
+ if (p) {
+ *p = 0;
+ }
oldvalue = r_config_get (core->config, res);
r_cons_show_cursor (true);
r_cons_set_raw (0);
cmd[0] = '\0';
eprintf ("set new value for %s (old=%s)\n", res, oldvalue);
r_line_set_prompt (":> ");
- if (r_cons_fgets (cmd, sizeof (cmd) - 1, 0, NULL) < 0)
- cmd[0]='\0';
+ if (r_cons_fgets (cmd, sizeof (cmd) - 1, 0, NULL) < 0) {
+ cmd[0] = '\0';
+ }
r_config_set (core->config, res, cmd);
r_cons_set_raw (1);
r_cons_show_cursor (false);
@@ -1246,7 +1252,9 @@ R_API int r_core_visual_trackflags(RCore *core) {
case 3: strcpy (cmd, "f="); break;
default: format = 0; continue;
}
- if (*cmd) r_core_cmd (core, cmd, 0);
+ if (*cmd) {
+ r_core_cmd (core, cmd, 0);
+ }
} else {
r_cons_printf ("(no flags)\n");
}
@@ -1303,8 +1311,16 @@ R_API int r_core_visual_trackflags(RCore *core) {
case 'o': r_flag_sort (core->flags, 0); break;
case 'n': r_flag_sort (core->flags, 1); break;
case 'j': option++; break;
- case 'k': if (--option<0) option = 0; break;
- case 'K': option-=10; if (option<0) option = 0; break;
+ case 'k':
+ if (--option < 0) {
+ option = 0;
+ }
+ break;
+ case 'K': option-=10;
+ if (option < 0) {
+ option = 0;
+ }
+ break;
case 'h':
case 'b': // back
case 'Q':
@@ -1366,9 +1382,11 @@ R_API int r_core_visual_trackflags(RCore *core) {
r_core_block_size (core, core->blocksize-16);
break;
case '+':
- if (menu==1)
+ if (menu == 1) {
r_core_cmdf (core, "f %s=%s+1", fs2, fs2);
- else r_core_block_size (core, core->blocksize+1);
+ } else {
+ r_core_block_size (core, core->blocksize + 1);
+ }
break;
case '-':
if (menu == 1) {
@@ -1411,8 +1429,12 @@ R_API int r_core_visual_trackflags(RCore *core) {
r_cons_show_cursor (false);
}
break;
- case 'P': if (--format<0) format = MAX_FORMAT; break;
-// = (format<=0)? MAX_FORMAT: format-1; break;
+ case 'P':
+ if (--format < 0) {
+ format = MAX_FORMAT;
+ }
+ break;
+ // = (format<=0)? MAX_FORMAT: format-1; break;
case 'p': format++; break;
case 'l':
case ' ':
@@ -1739,10 +1761,11 @@ R_API void r_core_visual_config(RCore *core) {
option = i-1;
continue;
}
- if (fs2 != NULL)
+ if (fs2 != NULL) {
// TODO: Break long lines.
r_cons_printf ("\n Selected: %s (%s)\n\n",
- fs2, desc);
+ fs2, desc);
+ }
}
if (fs && !strncmp (fs, "asm.", 4)) {
@@ -1750,8 +1773,9 @@ R_API void r_core_visual_config(RCore *core) {
}
r_cons_visual_flush ();
ch = r_cons_readchar ();
- if (ch==4 || ch==-1)
+ if (ch == 4 || ch == -1) {
return;
+ }
ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char
switch (ch) {
@@ -1860,9 +1884,11 @@ R_API void r_core_visual_mounts(RCore *core) {
if (list) {
r_list_foreach (list, iter, part) {
if ((option-delta <= i) && (i <= option+delta)) {
- if (option == i)
+ if (option == i) {
r_cons_printf (" > ");
- else r_cons_printf (" ");
+ } else {
+ r_cons_printf (" ");
+ }
r_cons_printf ("%d %02x 0x%010"PFMT64x" 0x%010"PFMT64x"\n",
part->number, part->type,
part->start, part->start+part->length);
@@ -1871,12 +1897,16 @@ R_API void r_core_visual_mounts(RCore *core) {
}
r_list_free (list);
list = NULL;
- } else r_cons_printf ("Cannot read partition\n");
+ } else {
+ r_cons_printf ("Cannot read partition\n");
+ }
} else if (mode == 1) {
r_cons_printf ("Types:\n\n");
for (i=0;;i++) {
n = r_fs_partition_type_get (i);
- if (!n) break;
+ if (!n) {
+ break;
+ }
r_cons_printf ("%s%s\n", (i==partition)?" > ":" ", n);
}
} else if (mode == 3) {
@@ -1905,8 +1935,12 @@ R_API void r_core_visual_mounts(RCore *core) {
r_cons_printf ("\n");
r_list_free (list);
list = NULL;
- } else r_cons_printf ("Cannot open '%s' directory\n", root);
- } else r_cons_printf ("Root undefined\n");
+ } else {
+ r_cons_printf ("Cannot open '%s' directory\n", root);
+ }
+ } else {
+ r_cons_printf ("Root undefined\n");
+ }
}
if (mode==2) {
r_str_trim_path (path);
@@ -1914,8 +1948,9 @@ R_API void r_core_visual_mounts(RCore *core) {
strncat (path, "/", sizeof (path)-strlen (path)-1);
list = r_fs_dir (core->fs, path);
file = r_list_get_n (list, dir);
- if (file && file->type != 'd')
- r_core_cmdf (core, "px @ 0x%"PFMT64x"!64", file->off);
+ if (file && file->type != 'd') {
+ r_core_cmdf (core, "px @ 0x%" PFMT64x "!64", file->off);
+ }
r_list_free (list);
list = NULL;
*str='\0';
@@ -1984,8 +2019,9 @@ R_API void r_core_visual_mounts(RCore *core) {
if (file->type == 'd') {
strncat (path, file->name, sizeof (path)-strlen (path)-1);
r_str_trim_path (path);
- if (root && strncmp (root, path, strlen (root)-1))
- strncpy (path, root, sizeof (path)-1);
+ if (root && strncmp (root, path, strlen (root) - 1)) {
+ strncpy (path, root, sizeof (path) - 1);
+ }
} else {
r_core_cmdf (core, "s 0x%"PFMT64x, file->off);
r_fs_umount (core->fs, root);
@@ -2010,32 +2046,39 @@ R_API void r_core_visual_mounts(RCore *core) {
break;
case 'k':
if (mode == 0 || mode == 3) {
- if (option > 0)
+ if (option > 0) {
option--;
+ }
} else if (mode == 1) {
- if (partition > 0)
+ if (partition > 0) {
partition--;
+ }
} else {
- if (dir>0)
+ if (dir > 0) {
dir--;
+ }
}
break;
case 'j':
if (mode == 0) {
n = r_fs_partition_type_get (partition);
list = r_fs_partitions (core->fs, n, 0);
- if (option < r_list_length (list)-1)
+ if (option < r_list_length (list) - 1) {
option++;
+ }
} else if (mode == 1) {
- if (partition < r_fs_partition_get_size ()-1)
+ if (partition < r_fs_partition_get_size () - 1) {
partition++;
+ }
} else if (mode == 3) {
- if (option < r_list_length (core->fs->roots)-1)
+ if (option < r_list_length (core->fs->roots) - 1) {
option++;
+ }
} else {
list = r_fs_dir (core->fs, path);
- if (dir < r_list_length (list)-1)
+ if (dir < r_list_length (list) - 1) {
dir++;
+ }
}
break;
case 't':
@@ -2078,8 +2121,9 @@ R_API void r_core_visual_mounts(RCore *core) {
if (file && root) {
strncat (path, file->name, sizeof (path)-strlen (path)-1);
r_str_trim_path (path);
- if (strncmp (root, path, strlen (root)-1))
- strncpy (path, root, sizeof (path)-1);
+ if (strncmp (root, path, strlen (root) - 1)) {
+ strncpy (path, root, sizeof (path) - 1);
+ }
file = r_fs_open (core->fs, path);
if (file) {
r_fs_read (core->fs, file, 0, file->size);
@@ -2092,8 +2136,12 @@ R_API void r_core_visual_mounts(RCore *core) {
r_file_dump (buf, file->data, file->size, 0);
r_fs_close (core->fs, file);
r_cons_printf ("Done\n");
- } else r_cons_printf ("Cannot dump file\n");
- } else r_cons_printf ("Cannot dump file\n");
+ } else {
+ r_cons_printf ("Cannot dump file\n");
+ }
+ } else {
+ r_cons_printf ("Cannot dump file\n");
+ }
r_cons_flush ();
r_cons_any_key (NULL);
*str='\0';
@@ -2582,7 +2630,9 @@ R_API void r_core_visual_anal(RCore *core) {
break;
default:
option++;
- if (option >= nfcns) --option;
+ if (option >= nfcns) {
+ --option;
+ }
break;
}
}
@@ -2718,27 +2768,32 @@ R_API void r_core_seek_previous (RCore *core, const char *type) {
if (strstr (type, "fun")) {
RAnalFunction *fcni;
r_list_foreach (core->anal->fcns, iter, fcni) {
- if (fcni->addr > next && fcni->addr < core->offset)
+ if (fcni->addr > next && fcni->addr < core->offset) {
next = fcni->addr;
+ }
}
} else
if (strstr (type, "hit")) {
RFlagItem *flag;
const char *pfx = r_config_get (core->config, "search.prefix");
r_list_foreach (core->flags->flags, iter, flag) {
- if (!strncmp (flag->name, pfx, strlen (pfx)))
- if (flag->offset > next && flag->offset< core->offset)
+ if (!strncmp (flag->name, pfx, strlen (pfx))) {
+ if (flag->offset > next && flag->offset < core->offset) {
next = flag->offset;
+ }
+ }
}
} else { // flags
RFlagItem *flag;
r_list_foreach (core->flags->flags, iter, flag) {
- if (flag->offset > next && flag->offset < core->offset)
+ if (flag->offset > next && flag->offset < core->offset) {
next = flag->offset;
+ }
}
}
- if (next!=0)
+ if (next != 0) {
r_core_seek (core, next, 1);
+ }
}
//define the data at offset according to the type (byte, word...) n times
@@ -2923,15 +2978,18 @@ repeat:
RFlagItem *item = r_flag_get_i (core->flags, op->jump);
if (item) {
const char *ptr = r_str_lchr (item->name, '.');
- if (ptr)
- man = strdup (ptr+1);
+ if (ptr) {
+ man = strdup (ptr + 1);
+ }
}
}
r_anal_op_free (op);
}
if (man) {
char *p = strstr (man, "INODE");
- if (p) *p = 0;
+ if (p) {
+ *p = 0;
+ }
r_cons_clear ();
r_cons_flush ();
r_sys_cmdf ("man %s", man);
@@ -3080,7 +3138,9 @@ repeat:
do {
n = r_str_nlen_w ((const char *)p + ntotal,
plen - ntotal) + 1;
- if (n < 2) break;
+ if (n < 2) {
+ break;
+ }
name = malloc (n + 10);
strcpy (name, "str.");
for (i = 0, j = 0; i < n; i++, j++) {
diff --git a/libr/crypto/p/crypto_aes_algo.c b/libr/crypto/p/crypto_aes_algo.c
index 6c91995e06..3c16ca9929 100644
--- a/libr/crypto/p/crypto_aes_algo.c
+++ b/libr/crypto/p/crypto_aes_algo.c
@@ -85,17 +85,20 @@ void aes_expkey (const struct aes_state *st, ut32 expkey[2][Nr_AES256 + 1][Nb])
Sbox[(ut8)tt] << 8 ^ Sbox[(ut8)(tt >> 24)] ^ Rcon[idx++] << 24;
if (st->columns != 8) {
- for (i = 1, j = 0; i < st->columns;)
+ for (i = 1, j = 0; i < st->columns;) {
tk[i++] ^= tk[j++];
+ }
} else {
- for (i = 1, j = 0; i < st->columns / 2;)
+ for (i = 1, j = 0; i < st->columns / 2;) {
tk[i++] ^= tk[j++];
+ }
tt = tk[st->columns / 2 - 1];
tk[st->columns / 2] ^= Sbox[(ut8)tt] ^ Sbox[(ut8)(tt >> 8)] << 8 ^
Sbox[(ut8)(tt >> 16)] << 16 ^
Sbox[(ut8)(tt >> 24)] << 24;
- for (j = st->columns / 2, i = j + 1; i < st->columns;)
+ for (j = st->columns / 2, i = j + 1; i < st->columns;) {
tk[i++] ^= tk[j++];
+ }
}
// Copy values into round key arrays
diff --git a/libr/crypto/p/crypto_aes_cbc.c b/libr/crypto/p/crypto_aes_cbc.c
index 0f279303e5..65632d687b 100644
--- a/libr/crypto/p/crypto_aes_cbc.c
+++ b/libr/crypto/p/crypto_aes_cbc.c
@@ -49,7 +49,9 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) {
const int blocks = size / BLOCK_SIZE;
ut8 *const obuf = calloc (1, size);
- if (!obuf) return false;
+ if (!obuf) {
+ return false;
+ }
ut8 *const ibuf = calloc (1, size);
if (!ibuf) {
diff --git a/libr/crypto/p/crypto_blowfish.c b/libr/crypto/p/crypto_blowfish.c
index c62b2b5fe6..a17a13e15b 100644
--- a/libr/crypto/p/crypto_blowfish.c
+++ b/libr/crypto/p/crypto_blowfish.c
@@ -177,7 +177,9 @@ static void blowfish_crypt(struct blowfish_state *const state, const ut8 *inbuf,
if (!state || !inbuf || !outbuf || buflen < 0 || buflen%8 != 0) {
//let user deal with padding
- if (buflen%8 != 0) eprintf("Invalid input length %d. Expected length is multiple of 8 bytes.\n", buflen);
+ if (buflen % 8 != 0) {
+ eprintf ("Invalid input length %d. Expected length is multiple of 8 bytes.\n", buflen);
+ }
return;
}
diff --git a/libr/crypto/p/crypto_cps2.c b/libr/crypto/p/crypto_cps2.c
index 7bcd40d145..2ee60c84ab 100644
--- a/libr/crypto/p/crypto_cps2.c
+++ b/libr/crypto/p/crypto_cps2.c
@@ -478,8 +478,9 @@ static void expand_1st_key(ut32 *dstkey, const ut32 *srckey) {
dstkey[2] = 0;
dstkey[3] = 0;
- for (i = 0; i < 96; ++i)
- dstkey[i / 24] |= BIT(srckey[bits[i] / 32], bits[i] % 32) << (i % 24);
+ for (i = 0; i < 96; ++i) {
+ dstkey[i / 24] |= BIT (srckey[bits[i] / 32], bits[i] % 32) << (i % 24);
+ }
}
// srckey is the 64-bit master key (2x32 bits) XORed with the subkey
diff --git a/libr/crypto/p/crypto_des.c b/libr/crypto/p/crypto_des.c
index c0ed287e96..c8922ff67f 100644
--- a/libr/crypto/p/crypto_des.c
+++ b/libr/crypto/p/crypto_des.c
@@ -57,7 +57,9 @@ static int des_encrypt (struct des_state *st, const ut8 *input, ut8 *output) {
}
static int des_decrypt (struct des_state *st, const ut8 *input, ut8 *output) {
- if (!st || !input || !output) return false;
+ if (!st || !input || !output) {
+ return false;
+ }
st->buflo = be32 (input + 0);
st->bufhi = be32 (input + 4);
//first permutation
diff --git a/libr/crypto/p/crypto_rc2.c b/libr/crypto/p/crypto_rc2.c
index 388dcb8332..7190ef8603 100644
--- a/libr/crypto/p/crypto_rc2.c
+++ b/libr/crypto/p/crypto_rc2.c
@@ -34,7 +34,9 @@ struct rc2_state {
static bool rc2_expandKey(struct rc2_state *state, const ut8 *key, int key_len) {
int i;
- if (key_len < 1 || key_len > 128) return false;
+ if (key_len < 1 || key_len > 128) {
+ return false;
+ }
memcpy(state->ekey, key, key_len);
// first loop
@@ -184,7 +186,9 @@ static void rc2_crypt(struct rc2_state *state, const ut8 *inbuf, ut8 *outbuf, in
}
if (idx % 8) {
- while(idx % 8) data_block[idx++] = 0;
+ while (idx % 8) {
+ data_block[idx++] = 0;
+ }
rc2_crypt8(state, (const ut8 *) data_block, (ut8 *) crypted_block);
strncpy(ptr, crypted_block, 8);
}
@@ -211,7 +215,9 @@ static bool rc2_use(const char *algo) {
static bool update(RCrypto *cry, const ut8 *buf, int len) {
ut8 *obuf = calloc (1, len);
- if (!obuf) return false;
+ if (!obuf) {
+ return false;
+ }
if (flag == 0) {
rc2_crypt (&state, buf, obuf, len);
} else if (flag == 1) {
diff --git a/libr/crypto/p/crypto_rc4.c b/libr/crypto/p/crypto_rc4.c
index 8a475be4ba..4f1f1f0790 100644
--- a/libr/crypto/p/crypto_rc4.c
+++ b/libr/crypto/p/crypto_rc4.c
@@ -33,8 +33,9 @@ static bool rc4_init(struct rc4_state *const state, const ut8 *key, int keylen)
}
state->key_size = keylen;
/* Initialize state with identity permutation */
- for (i = 0; i < 256; i++)
- state->perm[i] = (ut8)i;
+ for (i = 0; i < 256; i++) {
+ state->perm[i] = (ut8)i;
+ }
state->index1 = 0;
state->index2 = 0;
diff --git a/libr/crypto/p/crypto_rc6.c b/libr/crypto/p/crypto_rc6.c
index 62d3d4b6e3..444f9d5f70 100644
--- a/libr/crypto/p/crypto_rc6.c
+++ b/libr/crypto/p/crypto_rc6.c
@@ -177,7 +177,9 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) {
const int blocks = len / BLOCK_SIZE;
ut8 *obuf = calloc (1, len);
- if (!obuf) return false;
+ if (!obuf) {
+ return false;
+ }
int i;
if (flag) {
diff --git a/libr/crypto/p/crypto_rol.c b/libr/crypto/p/crypto_rol.c
index 5acfe84ca1..de7ee25363 100644
--- a/libr/crypto/p/crypto_rol.c
+++ b/libr/crypto/p/crypto_rol.c
@@ -51,7 +51,9 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) {
return false;
}
ut8 *obuf = calloc (1, len);
- if (!obuf) return false;
+ if (!obuf) {
+ return false;
+ }
rol_crypt (&st, buf, obuf, len);
r_crypto_append (cry, obuf, len);
free (obuf);
diff --git a/libr/crypto/p/crypto_rot.c b/libr/crypto/p/crypto_rot.c
index deda2c140c..70fd45dd23 100644
--- a/libr/crypto/p/crypto_rot.c
+++ b/libr/crypto/p/crypto_rot.c
@@ -71,7 +71,9 @@ static bool rot_use(const char *algo) {
static bool update(RCrypto *cry, const ut8 *buf, int len) {
ut8 *obuf = calloc (1, len);
- if (!obuf) return false;
+ if (!obuf) {
+ return false;
+ }
if (flag == 0) {
rot_crypt (rot_key, buf, obuf, len);
} else if (flag == 1) {
diff --git a/libr/debug/ddesc.c b/libr/debug/ddesc.c
index dc26aef54b..3c4c3194e1 100644
--- a/libr/debug/ddesc.c
+++ b/libr/debug/ddesc.c
@@ -18,45 +18,52 @@ R_API RDebugDesc *r_debug_desc_new (int fd, char* path, int perm, int type, int
R_API void r_debug_desc_free (RDebugDesc *p) {
if (p) {
- if (p->path)
+ if (p->path) {
free (p->path);
+ }
free (p);
}
}
R_API int r_debug_desc_open(RDebug *dbg, const char *path) {
- if (dbg && dbg->h && dbg->h->desc.open)
+ if (dbg && dbg->h && dbg->h->desc.open) {
return dbg->h->desc.open (path);
+ }
return false;
}
R_API int r_debug_desc_close(RDebug *dbg, int fd) {
- if (dbg && dbg->h && dbg->h->desc.close)
+ if (dbg && dbg->h && dbg->h->desc.close) {
return dbg->h->desc.close (fd);
+ }
return false;
}
R_API int r_debug_desc_dup(RDebug *dbg, int fd, int newfd) {
- if (dbg && dbg->h && dbg->h->desc.dup)
+ if (dbg && dbg->h && dbg->h->desc.dup) {
return dbg->h->desc.dup (fd, newfd);
+ }
return false;
}
R_API int r_debug_desc_read(RDebug *dbg, int fd, ut64 addr, int len) {
- if (dbg && dbg->h && dbg->h->desc.read)
+ if (dbg && dbg->h && dbg->h->desc.read) {
return dbg->h->desc.read (fd, addr, len);
+ }
return false;
}
R_API int r_debug_desc_seek(RDebug *dbg, int fd, ut64 addr) {
- if (dbg && dbg->h && dbg->h->desc.seek)
+ if (dbg && dbg->h && dbg->h->desc.seek) {
return dbg->h->desc.seek (fd, addr);
+ }
return false;
}
R_API int r_debug_desc_write(RDebug *dbg, int fd, ut64 addr, int len) {
- if (dbg && dbg->h && dbg->h->desc.write)
+ if (dbg && dbg->h && dbg->h->desc.write) {
return dbg->h->desc.write (fd, addr, len);
+ }
return false;
}
@@ -67,8 +74,9 @@ R_API int r_debug_desc_list(RDebug *dbg, int rad) {
RDebugDesc *p;
if (rad) {
- if (dbg && dbg->cb_printf)
+ if (dbg && dbg->cb_printf) {
dbg->cb_printf ("TODO \n");
+ }
} else {
if (dbg && dbg->h && dbg->h->desc.list) {
list = dbg->h->desc.list (dbg->pid);
diff --git a/libr/debug/debug.c b/libr/debug/debug.c
index c711d74c98..03778a0edc 100644
--- a/libr/debug/debug.c
+++ b/libr/debug/debug.c
@@ -276,7 +276,9 @@ R_API RBreakpointItem *r_debug_bp_add(RDebug *dbg, ut64 addr, int hw, bool watch
} else {
//module holds the address
addr = (ut64)r_num_math (dbg->num, module);
- if (!addr) return NULL;
+ if (!addr) {
+ return NULL;
+ }
detect_module = true;
}
r_debug_map_sync (dbg);
@@ -543,7 +545,9 @@ R_API ut64 r_debug_execute(RDebug *dbg, const ut8 *buf, int len, int restore) {
free (backup);
free (orig);
eprintf ("ra0=0x%08"PFMT64x"\n", ra0);
- } else eprintf ("r_debug_execute: Cannot get program counter\n");
+ } else {
+ eprintf ("r_debug_execute: Cannot get program counter\n");
+ }
return (ra0);
}
@@ -585,8 +589,9 @@ R_API bool r_debug_select(RDebug *dbg, int pid, int tid) {
return false;
}
- if (dbg->h && dbg->h->select && !dbg->h->select (pid, tid))
+ if (dbg->h && dbg->h->select && !dbg->h->select (pid, tid)) {
return false;
+ }
r_io_system (dbg->iob.io, sdb_fmt ("pid %d", pid));
@@ -925,14 +930,17 @@ R_API int r_debug_step_over(RDebug *dbg, int steps) {
}
if (dbg->h && dbg->h->step_over) {
- for (; steps_taken < steps; steps_taken++)
- if (!dbg->h->step_over (dbg))
+ for (; steps_taken < steps; steps_taken++) {
+ if (!dbg->h->step_over (dbg)) {
return steps_taken;
+ }
+ }
return steps_taken;
}
- if (!dbg->anal || !dbg->reg)
+ if (!dbg->anal || !dbg->reg) {
return steps_taken;
+ }
// Initial refill
buf_pc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]);
@@ -1266,8 +1274,9 @@ R_API int r_debug_continue_until_optype(RDebug *dbg, int type, int over) {
// step first, we dont want to check current optype
for (;;) {
- if (!r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false))
+ if (!r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false)) {
break;
+ }
pc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]);
// Try to keep the buffer full
@@ -1280,8 +1289,9 @@ R_API int r_debug_continue_until_optype(RDebug *dbg, int type, int over) {
eprintf ("Decode error at %"PFMT64x"\n", pc);
return false;
}
- if (op.type == type)
+ if (op.type == type) {
break;
+ }
// Step over and repeat
ret = over
? r_debug_step_over (dbg, 1)
@@ -1466,8 +1476,9 @@ R_API int r_debug_continue_syscalls(RDebug *dbg, int *sc, int n_sc) {
for (;;) {
RDebugReasonType reason;
- if (r_cons_singleton ()->context->breaked)
+ if (r_cons_singleton ()->context->breaked) {
break;
+ }
#if __linux__
// step is needed to avoid dupped contsc results
/* XXX(jjd): actually one stop is before the syscall, the other is
diff --git a/libr/debug/dreg.c b/libr/debug/dreg.c
index ee2a53168e..746b170e5f 100644
--- a/libr/debug/dreg.c
+++ b/libr/debug/dreg.c
@@ -242,7 +242,9 @@ R_API int r_debug_reg_list(RDebug *dbg, int type, int size, int rad, const char
snprintf (content, sizeof (content),
fmt2, "", item->name, "", strvalue, "");
len = colwidth - strlen (content);
- if (len < 0) len = 0;
+ if (len < 0) {
+ len = 0;
+ }
memset (whites, ' ', sizeof (whites));
whites[len] = 0;
dbg->cb_printf (fmt2, a, item->name, b, strvalue,
@@ -314,9 +316,13 @@ R_API ut64 r_debug_reg_get_err(RDebug *dbg, const char *name, int *err, utX *val
ut64 ret = 0LL;
int role = r_reg_get_name_idx (name);
const char *pname = name;
- if (err) *err = 0;
+ if (err) {
+ *err = 0;
+ }
if (!dbg || !dbg->reg) {
- if (err) *err = 1;
+ if (err) {
+ *err = 1;
+ }
return UT64_MAX;
}
if (role != -1) {
diff --git a/libr/debug/esil.c b/libr/debug/esil.c
index 460ea7e1cd..e1db26a363 100644
--- a/libr/debug/esil.c
+++ b/libr/debug/esil.c
@@ -36,7 +36,9 @@ RList *esil_watchpoints = NULL;
static int exprmatch (RDebug *dbg, ut64 addr, const char *expr) {
char *e = strdup (expr);
- if (!e) return 0;
+ if (!e) {
+ return 0;
+ }
char *p = strstr (e, "..");
ut64 a,b;
int ret = 0;
@@ -46,16 +48,19 @@ static int exprmatch (RDebug *dbg, ut64 addr, const char *expr) {
a = r_num_math (dbg->num, e);
b = r_num_math (dbg->num, p);
if (a=a && addr <= b)
+ if (addr >= a && addr <= b) {
ret = 1;
+ }
} else {
- if (addr >=b && addr <= a)
+ if (addr >= b && addr <= a) {
ret = 1;
+ }
}
} else {
a = r_num_math (dbg->num, e);
- if (addr == a)
+ if (addr == a) {
ret = 1;
+ }
}
has_match = ret;
free (e);
@@ -65,12 +70,14 @@ static int exprmatch (RDebug *dbg, ut64 addr, const char *expr) {
static int esilbreak_check_pc (RDebug *dbg, ut64 pc) {
EsilBreak *ew;
RListIter *iter;
- if (!pc)
- pc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]);
+ if (!pc) {
+ pc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]);
+ }
r_list_foreach (EWPS, iter, ew) {
if (ew->rwx & R_IO_EXEC) {
- if (exprmatch (dbg, pc, ew->expr))
+ if (exprmatch (dbg, pc, ew->expr)) {
return 1;
+ }
}
}
return 0;
@@ -309,7 +316,9 @@ R_API int r_debug_esil_watch_empty(RDebug *dbg) {
R_API void r_debug_esil_watch(RDebug *dbg, int rwx, int dev, const char *expr) {
if (!EWPS) {
EWPS = r_list_new ();
- if (!EWPS) return;
+ if (!EWPS) {
+ return;
+ }
EWPS->free = (RListFree)ewps_free;
}
EsilBreak *ew = R_NEW0 (EsilBreak);
diff --git a/libr/debug/p/bfvm.c b/libr/debug/p/bfvm.c
index 9e44fd4f28..3f0ea2ac85 100644
--- a/libr/debug/p/bfvm.c
+++ b/libr/debug/p/bfvm.c
@@ -8,8 +8,9 @@
static ut8 bfvm_op(BfvmCPU *c) {
// XXX: this is slow :(
ut8 buf[4] = {0};
- if (c && c->iob.read_at && !c->iob.read_at (c->iob.io, c->eip, buf, 4))
+ if (c && c->iob.read_at && !c->iob.read_at (c->iob.io, c->eip, buf, 4)) {
return 0xff;
+ }
return buf[0];
}
@@ -42,8 +43,9 @@ R_API int bfvm_init(BfvmCPU *c, ut32 size, int circular) {
/* data */
c->mem = (ut8 *)malloc (size);
- if (!c->mem)
+ if (!c->mem) {
return 0;
+ }
memset (c->mem, '\0', size);
/* setup */
@@ -101,26 +103,30 @@ R_API ut8 bfvm_get(BfvmCPU *c) {
R_API void bfvm_inc(BfvmCPU *c) {
ut8 *mem = bfvm_get_ptr (c);
- if (mem != NULL)
+ if (mem != NULL) {
mem[0]++;
+ }
}
R_API void bfvm_dec(BfvmCPU *c) {
ut8 *mem = bfvm_get_ptr (c);
- if (mem != NULL)
+ if (mem != NULL) {
mem[0]--;
+ }
}
R_API int bfvm_reg_set(BfvmCPU *c, const char *str) {
char *ptr = strchr (str, ' ');
- if (!ptr)
+ if (!ptr) {
return 0;
- if (strstr (str, "eip"))
+ }
+ if (strstr (str, "eip")) {
c->eip = r_num_math (NULL, ptr+1);
- else if (strstr (str, "esp"))
+ } else if (strstr (str, "esp")) {
c->esp = r_num_math (NULL, ptr+1);
- else if (strstr (str, "ptr"))
- c->ptr = r_num_math (NULL, ptr+1);
+ } else if (strstr (str, "ptr")) {
+ c->ptr = r_num_math (NULL, ptr + 1);
+ }
return 1;
}
@@ -129,8 +135,9 @@ R_API void bfvm_peek(BfvmCPU *c) {
int idx = c->input_idx;
ut8 *ptr = bfvm_get_ptr (c);
- if (idx >= c->input_size)
+ if (idx >= c->input_size) {
idx = 0;
+ }
if (ptr) {
*ptr = c->input_buf[idx];
@@ -161,8 +168,9 @@ R_API int bfvm_trace_op(BfvmCPU *c, ut8 op) {
case ']':
g = bfvm_get (c);
eprintf ("%c ; [ptr] = %d\n", op, g);
- if (g!= 0)
+ if (g != 0) {
eprintf ("[");
+ }
break;
}
return 0;
diff --git a/libr/debug/p/debug_bf.c b/libr/debug/p/debug_bf.c
index 9ea4ed20d8..bfb95a4847 100644
--- a/libr/debug/p/debug_bf.c
+++ b/libr/debug/p/debug_bf.c
@@ -29,9 +29,11 @@ static struct bfvm_regs r;
static int is_io_bf(RDebug *dbg) {
RIODesc *d = dbg->iob.io->desc;
- if (d && d->plugin && d->plugin->name)
- if (!strcmp ("bdescbg", d->plugin->name))
+ if (d && d->plugin && d->plugin->name) {
+ if (!strcmp ("bdescbg", d->plugin->name)) {
return true;
+ }
+ }
return false;
}
@@ -40,10 +42,12 @@ static int r_debug_bf_step_over(RDebug *dbg) {
int op, oop = 0;
for (;;) {
op = bfvm_op (o->bfvm);
- if (oop != 0 && op != oop)
+ if (oop != 0 && op != oop) {
break;
- if (bfvm_in_trap (o->bfvm))
+ }
+ if (bfvm_in_trap (o->bfvm)) {
break;
+ }
bfvm_step (o->bfvm, 0);
oop = op;
}
@@ -58,12 +62,15 @@ static int r_debug_bf_step(RDebug *dbg) {
static int r_debug_bf_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {
RIOBdescbg *o;
- if (!dbg)
+ if (!dbg) {
return false;
- if (!is_io_bf (dbg))
+ }
+ if (!is_io_bf (dbg)) {
return 0;
- if (!(dbg->iob.io) || !(dbg->iob.io->desc) || !(dbg->iob.io->desc->data))
+ }
+ if (!(dbg->iob.io) || !(dbg->iob.io->desc) || !(dbg->iob.io->desc->data)) {
return 0;
+ }
o = dbg->iob.io->desc->data;
r.pc = o->bfvm->eip;
r.ptr = o->bfvm->ptr;
@@ -81,12 +88,15 @@ static int r_debug_bf_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {
static int r_debug_bf_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) {
RIOBdescbg *o;
- if (!dbg)
+ if (!dbg) {
return false;
- if (!is_io_bf (dbg))
+ }
+ if (!is_io_bf (dbg)) {
return 0;
- if (!(dbg->iob.io) || !(dbg->iob.io->desc) || !(dbg->iob.io->desc->data))
+ }
+ if (!(dbg->iob.io) || !(dbg->iob.io->desc) || !(dbg->iob.io->desc->data)) {
return 0;
+ }
o = dbg->iob.io->desc->data;
memcpy (&r, buf, sizeof (r));
o->bfvm->eip = r.pc;
@@ -119,8 +129,9 @@ static int r_debug_bf_wait(RDebug *dbg, int pid) {
}
static int r_debug_bf_attach(RDebug *dbg, int pid) {
- if (!is_io_bf (dbg))
+ if (!is_io_bf (dbg)) {
return false;
+ }
#if 0
RIOBdescbg *o;
o = dbg->iob.io->desc->data;
@@ -168,7 +179,9 @@ static RList *r_debug_native_map_get(RDebug *dbg) {
RIOBdescbg *o = dbg->iob.io->desc->data;
BfvmCPU *c = o->bfvm;
RList *list = r_list_newf ((RListFree)r_debug_map_free);
- if (!list) return NULL;
+ if (!list) {
+ return NULL;
+ }
r_list_append (list, r_debug_map_new (
"code", 0, 4096, 6, 0));
r_list_append (list, r_debug_map_new (
diff --git a/libr/debug/p/debug_bochs.c b/libr/debug/p/debug_bochs.c
index 203cc43b22..d0e93a23d7 100644
--- a/libr/debug/p/debug_bochs.c
+++ b/libr/debug/p/debug_bochs.c
@@ -110,7 +110,9 @@ static int r_debug_bochs_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {
}
pos+= 8;
- } else i++;
+ } else {
+ i++;
+ }
}
bochs_send_cmd (desc, "info cpu", true);
@@ -123,8 +125,10 @@ static int r_debug_bochs_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {
} else if (strstr (desc->data,"PC_64")) {
bAjusta = false;
//eprintf("[modo PC_64]\n");
- } else eprintf ("[unknown mode]\n%s\n",desc->data);
- /*
+ } else {
+ eprintf ("[unknown mode]\n%s\n", desc->data);
+ }
+ /*
es:0x0000, dh=0x00009300, dl=0x0000ffff, valid=7
Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
cs:0xf000, dh=0xff0093ff, dl=0x0000ffff, valid=7
@@ -205,7 +209,9 @@ static RList *r_debug_bochs_map_get(RDebug* dbg) { //TODO
//eprintf("bochs_map_getdebug:\n");
RDebugMap *mr;
RList *list = r_list_newf ((RListFree)map_free);
- if (!list) return NULL;
+ if (!list) {
+ return NULL;
+ }
mr = R_NEW0 (RDebugMap);
if (!mr) {
r_list_free (list);
diff --git a/libr/debug/p/debug_gdb.c b/libr/debug/p/debug_gdb.c
index 74e824e4f0..c44229e065 100644
--- a/libr/debug/p/debug_gdb.c
+++ b/libr/debug/p/debug_gdb.c
@@ -274,8 +274,9 @@ static int r_debug_gdb_reg_write(RDebug *dbg, int type, const ut8 *buf, int size
const char *pcname = r_reg_get_name (dbg->anal->reg, R_REG_NAME_PC);
RRegItem *reg = r_reg_get (dbg->anal->reg, pcname, 0);
if (reg) {
- if (dbg->anal->bits != reg->size)
+ if (dbg->anal->bits != reg->size) {
bits = reg->size;
+ }
}
free (r_reg_get_bytes (dbg->reg, type, &buflen));
// some implementations of the gdb protocol are acting weird.
@@ -296,7 +297,9 @@ static int r_debug_gdb_reg_write(RDebug *dbg, int type, const ut8 *buf, int size
RRegItem* current = NULL;
for (;;) {
current = r_reg_next_diff (dbg->reg, type, reg_buf, buflen, current, bits);
- if (!current) break;
+ if (!current) {
+ break;
+ }
ut64 val = r_reg_get_value (dbg->reg, current);
int bytes = bits / 8;
gdbr_write_reg (desc, current->name, (char*)&val, bytes);
@@ -980,36 +983,38 @@ static int r_debug_gdb_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set
// TODO handle conditions
switch (b->rwx){
case R_BP_PROT_EXEC : {
- if (set)
+ if (set) {
ret = b->hw?
gdbr_set_hwbp (desc, b->addr, "", bpsize):
gdbr_set_bp (desc, b->addr, "", bpsize);
- else
- ret = b->hw?
- gdbr_remove_hwbp (desc, b->addr, bpsize):
- gdbr_remove_bp (desc, b->addr, bpsize);
+ } else {
+ ret = b->hw ? gdbr_remove_hwbp (desc, b->addr, bpsize) : gdbr_remove_bp (desc, b->addr, bpsize);
+ }
break;
}
// TODO handle size (area of watch in upper layer and then bpsize. For the moment watches are set on exact on byte
case R_BP_PROT_WRITE : {
- if (set)
+ if (set) {
gdbr_set_hww (desc, b->addr, "", 1);
- else
+ } else {
gdbr_remove_hww (desc, b->addr, 1);
+ }
break;
}
case R_BP_PROT_READ : {
- if (set)
+ if (set) {
gdbr_set_hwr (desc, b->addr, "", 1);
- else
+ } else {
gdbr_remove_hwr (desc, b->addr, 1);
+ }
break;
}
case R_BP_PROT_ACCESS : {
- if (set)
+ if (set) {
gdbr_set_hwa (desc, b->addr, "", 1);
- else
+ } else {
gdbr_remove_hwa (desc, b->addr, 1);
+ }
break;
}
}
diff --git a/libr/debug/p/debug_native.c b/libr/debug/p/debug_native.c
index 1a23320836..b1bd6b1773 100644
--- a/libr/debug/p/debug_native.c
+++ b/libr/debug/p/debug_native.c
@@ -1123,7 +1123,9 @@ static int r_debug_native_map_dealloc (RDebug *dbg, ut64 addr, int size) {
#if !__WINDOWS__ && !__APPLE__
static void _map_free(RDebugMap *map) {
- if (!map) return;
+ if (!map) {
+ return;
+ }
free (map->name);
free (map->file);
free (map);
@@ -1331,7 +1333,9 @@ static RList *r_debug_native_modules_get (RDebug *dbg) {
static bool r_debug_native_kill (RDebug *dbg, int pid, int tid, int sig) {
bool ret = false;
- if (pid == 0) pid = dbg->pid;
+ if (pid == 0) {
+ pid = dbg->pid;
+ }
#if __WINDOWS__ && !__CYGWIN__
if (sig==0)
ret = true;
diff --git a/libr/debug/p/debug_qnx.c b/libr/debug/p/debug_qnx.c
index a8561106af..fcff84a136 100644
--- a/libr/debug/p/debug_qnx.c
+++ b/libr/debug/p/debug_qnx.c
@@ -7,7 +7,9 @@
/* HACK_FOR_PLUGIN_LINKAGE */
R_API RDebugPid *__r_debug_pid_new(const char *path, int pid, char status, ut64 pc) {
RDebugPid *p = R_NEW0 (RDebugPid);
- if (!p) return NULL;
+ if (!p) {
+ return NULL;
+ }
p->path = strdup (path);
p->pid = pid;
p->status = status;
@@ -47,7 +49,9 @@ static RList *r_debug_qnx_tids (RDebug *dbg, int pid) {
static RList *r_debug_qnx_pids (RDebug *dbg, int pid) {
RList *list = r_list_new ();
- if (!list) return NULL;
+ if (!list) {
+ return NULL;
+ }
list->free = (RListFree)&__r_debug_pid_free;
/* TODO */
@@ -67,7 +71,9 @@ static int r_debug_qnx_reg_read (RDebug *dbg, int type, ut8 *buf, int size) {
return -1;
}
int len = qnxr_read_registers (desc);
- if (len <= 0) return -1;
+ if (len <= 0) {
+ return -1;
+ }
// read the len of the current area
free (r_reg_get_bytes (dbg->reg, type, &buflen));
if (size < len) {
@@ -79,16 +85,18 @@ static int r_debug_qnx_reg_read (RDebug *dbg, int type, ut8 *buf, int size) {
if (reg_buf) {
if (buf_size < copy_size) {
ut8 *new_buf = realloc (reg_buf, copy_size);
- if (!new_buf)
+ if (!new_buf) {
return -1;
+ }
reg_buf = new_buf;
buflen = copy_size;
buf_size = len;
}
} else {
reg_buf = calloc (buflen, 1);
- if (!reg_buf)
+ if (!reg_buf) {
return -1;
+ }
buf_size = buflen;
}
memset ((void *)(volatile void *) buf, 0, size);
@@ -113,8 +121,9 @@ static int r_debug_qnx_reg_write (RDebug *dbg, int type, const ut8 *buf, int siz
return -1;
}
if (reg) {
- if (dbg->anal->bits != reg->size)
+ if (dbg->anal->bits != reg->size) {
bits = reg->size;
+ }
}
free (r_reg_get_bytes (dbg->reg, type, &buflen));
// some implementations of the gdb protocol are acting weird.
@@ -135,7 +144,9 @@ static int r_debug_qnx_reg_write (RDebug *dbg, int type, const ut8 *buf, int siz
RRegItem *current = NULL;
for (;;) {
current = r_reg_next_diff (dbg->reg, type, reg_buf, buflen, current, bits);
- if (!current) break;
+ if (!current) {
+ break;
+ }
ut64 val = r_reg_get_value (dbg->reg, current);
int bytes = bits / 8;
qnxr_write_reg (desc, current->name, (char *)&val, bytes);
@@ -176,7 +187,7 @@ static int r_debug_qnx_attach (RDebug *dbg, int pid) {
RIOQnx *g = d->data;
int arch = r_sys_arch_id (dbg->arch);
int bits = dbg->anal->bits;
- if ((desc = &g->desc))
+ if ((desc = &g->desc)) {
switch (arch) {
case R_SYS_ARCH_X86:
if (bits == 16 || bits == 32) {
@@ -195,8 +206,10 @@ static int r_debug_qnx_attach (RDebug *dbg, int pid) {
}
break;
}
- if (pid)
+ }
+ if (pid) {
qnxr_attach (desc, pid);
+ }
} else {
eprintf ("%s: error: underlying IO descriptor isn't a QNX one\n", __func__);
return false;
@@ -246,7 +259,7 @@ static const char *r_debug_qnx_reg_profile (RDebug *dbg) {
#endif
);
case R_SYS_ARCH_ARM:
- if (bits == 32)
+ if (bits == 32) {
return strdup (
"=PC r15\n"
"=SP r14\n" // XXX
@@ -307,7 +320,8 @@ static const char *r_debug_qnx_reg_profile (RDebug *dbg) {
"mmx d30 .64 308 0\n" // neon
"mmx d31 .64 316 0\n" // neon
"mmx fpscr .32 324 0\n" // neon
- );
+ );
+ }
}
return NULL;
}
diff --git a/libr/debug/p/debug_windbg.c b/libr/debug/p/debug_windbg.c
index 0d004f18b2..720d92f265 100644
--- a/libr/debug/p/debug_windbg.c
+++ b/libr/debug/p/debug_windbg.c
@@ -134,8 +134,12 @@ static int r_debug_windbg_detach(RDebug *dbg, int pid) {
}
static char *r_debug_windbg_reg_profile(RDebug *dbg) {
- if (!dbg) return NULL;
- if (dbg->arch && strcmp (dbg->arch, "x86")) return NULL;
+ if (!dbg) {
+ return NULL;
+ }
+ if (dbg->arch && strcmp (dbg->arch, "x86")) {
+ return NULL;
+ }
if (dbg->bits == R_SYS_BITS_32) {
#include "native/reg/windows-x86.h"
} else if (dbg->bits == R_SYS_BITS_64) {
@@ -146,7 +150,9 @@ static char *r_debug_windbg_reg_profile(RDebug *dbg) {
static int r_debug_windbg_breakpoint(RBreakpoint *bp, RBreakpointItem *b, bool set) {
int *tag;
- if (!b) return false;
+ if (!b) {
+ return false;
+ }
// Use a 32 bit word here to keep this compatible with 32 bit hosts
tag = (int *)&b->data;
return windbg_bkpt (wctx, b->addr, set, b->hw, tag);
diff --git a/libr/debug/p/native/linux/linux_debug.c b/libr/debug/p/native/linux/linux_debug.c
index 93ab4a4e11..715618bf54 100644
--- a/libr/debug/p/native/linux/linux_debug.c
+++ b/libr/debug/p/native/linux/linux_debug.c
@@ -637,8 +637,9 @@ RList *linux_thread_list(int pid, RList *list) {
int tgid = atoi (ptr + 5);
/* if it is not in our thread group, we don't want it */
- if (tgid != pid)
+ if (tgid != pid) {
continue;
+ }
if (procfs_pid_slurp (i, "comm", buf, sizeof(buf)) == -1) {
/* fall back to auto-id */
@@ -780,7 +781,9 @@ int linux_reg_read (RDebug *dbg, int type, ut8 *buf, int size) {
{
int i;
for (i = 0; i < 8; i++) { //DR0-DR7
- if (i == 4 || i == 5) continue;
+ if (i == 4 || i == 5) {
+ continue;
+ }
long ret = ptrace (PTRACE_PEEKUSER, pid,
r_offsetof (struct user, u_debugreg[i]), 0);
if ((i+1) * sizeof (ret) > size) {
@@ -811,9 +814,15 @@ int linux_reg_read (RDebug *dbg, int type, ut8 *buf, int size) {
#if __x86_64__
#if !__ANDROID__
ret1 = ptrace (PTRACE_GETFPREGS, pid, NULL, &fpregs);
- if (showfpu) print_fpu ((void *)&fpregs, 0);
- if (ret1 != 0) return false;
- if (sizeof(fpregs) < size) size = sizeof(fpregs);
+ if (showfpu) {
+ print_fpu ((void *)&fpregs, 0);
+ }
+ if (ret1 != 0) {
+ return false;
+ }
+ if (sizeof (fpregs) < size) {
+ size = sizeof (fpregs);
+ }
memcpy (buf, &fpregs, size);
return sizeof(fpregs);
#else
@@ -883,8 +892,12 @@ int linux_reg_read (RDebug *dbg, int type, ut8 *buf, int size) {
* to 'wait'. and the process is not yet available to accept
* more ptrace queries.
*/
- if (ret != 0) return false;
- if (sizeof (regs) < size) size = sizeof(regs);
+ if (ret != 0) {
+ return false;
+ }
+ if (sizeof (regs) < size) {
+ size = sizeof (regs);
+ }
memcpy (buf, ®s, size);
return sizeof (regs);
}
@@ -900,7 +913,9 @@ int linux_reg_write (RDebug *dbg, int type, const ut8 *buf, int size) {
int i;
long *val = (long*)buf;
for (i = 0; i < 8; i++) { // DR0-DR7
- if (i == 4 || i == 5) continue;
+ if (i == 4 || i == 5) {
+ continue;
+ }
if (ptrace (PTRACE_POKEUSER, dbg->pid, r_offsetof (
struct user, u_debugreg[i]), val[i])) {
eprintf ("ptrace error for dr %d\n", i);
@@ -956,7 +971,9 @@ RList *linux_desc_list (int pid) {
}
ret->free = (RListFree)r_debug_desc_free;
while ((de = (struct dirent *)readdir(dd))) {
- if (de->d_name[0] == '.') continue;
+ if (de->d_name[0] == '.') {
+ continue;
+ }
len = strlen (path);
len2 = strlen (de->d_name);
if (len + len2 + 1 >= sizeof(file)) {
@@ -979,12 +996,18 @@ RList *linux_desc_list (int pid) {
st.st_mode & S_IFCHR ? 'C':'-';
}
if (lstat(path, &st) != -1) {
- if (st.st_mode & S_IRUSR) perm |= R_IO_READ;
- if (st.st_mode & S_IWUSR) perm |= R_IO_WRITE;
+ if (st.st_mode & S_IRUSR) {
+ perm |= R_IO_READ;
+ }
+ if (st.st_mode & S_IWUSR) {
+ perm |= R_IO_WRITE;
+ }
}
//TODO: Offset
desc = r_debug_desc_new (atoi (de->d_name), buf, perm, type, 0);
- if (!desc) break;
+ if (!desc) {
+ break;
+ }
r_list_append (ret, desc);
}
closedir (dd);
diff --git a/libr/debug/pid.c b/libr/debug/pid.c
index 21df585a63..428f729569 100644
--- a/libr/debug/pid.c
+++ b/libr/debug/pid.c
@@ -76,7 +76,9 @@ R_API int r_debug_thread_list(RDebug *dbg, int pid) {
}
if (dbg && dbg->h && dbg->h->threads) {
list = dbg->h->threads (dbg, pid);
- if (!list) return false;
+ if (!list) {
+ return false;
+ }
if (pid == -'j') {
dbg->cb_printf ("[");
r_list_foreach (list, iter, p) {
diff --git a/libr/debug/signal.c b/libr/debug/signal.c
index 6df38282fd..7a9e7f8134 100644
--- a/libr/debug/signal.c
+++ b/libr/debug/signal.c
@@ -69,10 +69,12 @@ static int siglistcb (void *p, const char *k, const char *v) {
opt = sdb_num_get (DB, key, 0);
if (opt) {
r_cons_printf ("%s %s", k, v);
- if (opt & R_DBG_SIGNAL_CONT)
+ if (opt & R_DBG_SIGNAL_CONT) {
r_cons_strcat (" cont");
- if (opt & R_DBG_SIGNAL_SKIP)
+ }
+ if (opt & R_DBG_SIGNAL_SKIP) {
r_cons_strcat (" skip");
+ }
r_cons_newline ();
} else {
if (mode == 0) {
@@ -147,8 +149,9 @@ R_API int r_debug_signal_set(RDebug *dbg, int num, ut64 addr) {
/* TODO rename to _kill_ -> _signal_ */
R_API RList *r_debug_kill_list(RDebug *dbg) {
- if (dbg->h->kill_list)
+ if (dbg->h->kill_list) {
return dbg->h->kill_list (dbg);
+ }
return NULL;
}
diff --git a/libr/debug/trace.c b/libr/debug/trace.c
index 8bed98ad5a..7d026b1a47 100644
--- a/libr/debug/trace.c
+++ b/libr/debug/trace.c
@@ -8,7 +8,9 @@
R_API RDebugTrace *r_debug_trace_new () {
RDebugTrace *t = R_NEW0 (RDebugTrace);
- if (!t) return NULL;
+ if (!t) {
+ return NULL;
+ }
t->tag = 1; // UT32_MAX;
t->addresses = NULL;
t->enabled = false;
@@ -27,7 +29,9 @@ R_API RDebugTrace *r_debug_trace_new () {
}
R_API void r_debug_trace_free (RDebugTrace *trace) {
- if (!trace) return;
+ if (!trace) {
+ return;
+ }
r_list_purge (trace->traces);
free (trace->traces);
sdb_free (trace->db);
@@ -120,8 +124,9 @@ static int r_debug_trace_is_traceable(RDebug *dbg, ut64 addr) {
if (dbg->trace->addresses) {
char addr_str[32];
snprintf (addr_str, sizeof (addr_str), "0x%08"PFMT64x, addr);
- if (!strstr (dbg->trace->addresses, addr_str))
+ if (!strstr (dbg->trace->addresses, addr_str)) {
return false;
+ }
}
return true;
}
@@ -129,13 +134,16 @@ static int r_debug_trace_is_traceable(RDebug *dbg, ut64 addr) {
R_API RDebugTracepoint *r_debug_trace_add (RDebug *dbg, ut64 addr, int size) {
RDebugTracepoint *tp;
int tag = dbg->trace->tag;
- if (!r_debug_trace_is_traceable (dbg, addr))
+ if (!r_debug_trace_is_traceable (dbg, addr)) {
return NULL;
+ }
r_anal_trace_bb (dbg->anal, addr);
tp = r_debug_trace_get (dbg, addr);
if (!tp) {
tp = R_NEW0 (RDebugTracepoint);
- if (!tp) return NULL;
+ if (!tp) {
+ return NULL;
+ }
tp->stamp = r_sys_now ();
tp->addr = addr;
tp->tags = tag;
diff --git a/libr/egg/egg.c b/libr/egg/egg.c
index 640aa5c0ff..f793a5af06 100644
--- a/libr/egg/egg.c
+++ b/libr/egg/egg.c
@@ -21,22 +21,36 @@ R_API REgg *r_egg_new () {
return NULL;
}
egg->src = r_buf_new ();
- if (!egg->src) goto beach;
+ if (!egg->src) {
+ goto beach;
+ }
egg->buf = r_buf_new ();
- if (!egg->buf) goto beach;
+ if (!egg->buf) {
+ goto beach;
+ }
egg->bin = r_buf_new ();
- if (!egg->bin) goto beach;
+ if (!egg->bin) {
+ goto beach;
+ }
egg->remit = &emit_x86;
egg->syscall = r_syscall_new ();
- if (!egg->syscall) goto beach;
+ if (!egg->syscall) {
+ goto beach;
+ }
egg->rasm = r_asm_new ();
- if (!egg->rasm) goto beach;
+ if (!egg->rasm) {
+ goto beach;
+ }
egg->bits = 0;
egg->endian = 0;
egg->db = sdb_new (NULL, NULL, 0);
- if (!egg->db) goto beach;
+ if (!egg->db) {
+ goto beach;
+ }
egg->patches = r_list_new ();
- if (!egg->patches) goto beach;
+ if (!egg->patches) {
+ goto beach;
+ }
egg->patches->free = (RListFree)r_buf_free;
egg->plugins = r_list_new ();
for (i=0; egg_static_plugins[i]; i++) {
@@ -143,9 +157,10 @@ R_API int r_egg_setup(REgg *egg, const char *arch, int bits, int endian, const c
R_API int r_egg_include(REgg *egg, const char *file, int format) {
int sz;
const ut8 *foo = (const ut8*)r_file_slurp (file, &sz);
- if (!foo)
+ if (!foo) {
return 0;
-// XXX: format breaks compiler layers
+ }
+ // XXX: format breaks compiler layers
switch (format) {
case 'r': // raw
r_egg_raw (egg, foo, sz);
@@ -177,8 +192,9 @@ R_API void r_egg_syscall(REgg *egg, const char *arg, ...) {
if (!strcmp (arg, "close")) {
//egg->remit->syscall_args ();
}
- if (!item)
+ if (!item) {
return;
+ }
egg->remit->syscall (egg, item->num);
}
@@ -199,7 +215,9 @@ R_API int r_egg_raw(REgg *egg, const ut8 *b, int len) {
char *out;
int outlen = len*2; // two hexadecimal digits per byte
out = malloc (outlen+1);
- if (!out) return false;
+ if (!out) {
+ return false;
+ }
r_hex_bin2str (b, len, out);
r_buf_append_bytes (egg->buf, (const ut8*)".hex ", 5);
r_buf_append_bytes (egg->buf, (const ut8*)out, outlen);
@@ -212,7 +230,9 @@ static int r_egg_raw_prepend(REgg *egg, const ut8 *b, int len) {
char *out;
int outlen = len*2; // two hexadecimal digits per byte
out = malloc (outlen+1);
- if (!out) return false;
+ if (!out) {
+ return false;
+ }
r_hex_bin2str (b, len, out);
r_buf_prepend_bytes (egg->buf, (const ut8*)"\n", 1);
r_buf_prepend_bytes (egg->buf, (const ut8*)out, outlen);
@@ -232,11 +252,13 @@ static int r_egg_prepend_bytes(REgg *egg, const ut8 *b, int len) {
}
static int r_egg_append_bytes(REgg *egg, const ut8 *b, int len) {
- if (!r_egg_raw(egg, b, len))
+ if (!r_egg_raw (egg, b, len)) {
return false;
+ }
- if (!r_buf_append_bytes (egg->bin, b, len))
+ if (!r_buf_append_bytes (egg->bin, b, len)) {
return false;
+ }
return true;
}
@@ -364,7 +386,9 @@ R_API int r_egg_run(REgg *egg) {
#define R_EGG_FILL_TYPE_SEQ
static inline char *eon(char *n) {
- while (*n && (*n>='0' && *n<='9')) n++;
+ while (*n && (*n >= '0' && *n <= '9')) {
+ n++;
+ }
return n;
}
@@ -459,7 +483,9 @@ R_API int r_egg_encode(REgg *egg, const char *name) {
r_list_foreach (egg->plugins, iter, p) {
if (p->type == R_EGG_PLUGIN_ENCODER && !strcmp (name, p->name)) {
b = p->build (egg);
- if (!b) return false;
+ if (!b) {
+ return false;
+ }
r_buf_free (egg->bin);
egg->bin = b;
return true;
@@ -470,7 +496,9 @@ R_API int r_egg_encode(REgg *egg, const char *name) {
R_API int r_egg_patch(REgg *egg, int off, const ut8 *buf, int len) {
RBuffer *b = r_buf_new ();
- if (!b) return false;
+ if (!b) {
+ return false;
+ }
if (!r_buf_set_bytes (b, buf, len)) {
r_buf_free (b);
return false;
@@ -505,5 +533,7 @@ R_API void r_egg_pattern(REgg *egg, int size) {
if (ret) {
r_egg_prepend_bytes (egg, (const ut8*)ret, strlen(ret));
free (ret);
- } else eprintf ("Invalid debruijn pattern length.\n");
+ } else {
+ eprintf ("Invalid debruijn pattern length.\n");
+ }
}
diff --git a/libr/egg/egg_lang.c b/libr/egg/egg_lang.c
index 45b24c81d3..0cbe715ed2 100644
--- a/libr/egg/egg_lang.c
+++ b/libr/egg/egg_lang.c
@@ -37,7 +37,9 @@ static inline int is_op(char x) {
}
static inline int get_op(char **pos){
- while (**pos && !(is_op (**pos) && !is_var (*pos))) (*pos)++;
+ while (**pos && !(is_op (**pos) && !is_var (*pos))) {
+ (*pos)++;
+ }
return (**pos)? ((is_op (**pos)) + 1): 0;
}
@@ -223,7 +225,9 @@ static const char *find_alias(REgg *egg, const char *str) {
return strdup (str);
}
// strings could not means aliases
- while (*p && !is_space (*p)) p++;
+ while (*p && !is_space (*p)) {
+ p++;
+ }
*p = '\x00';
for (i = 0; i < egg->lang.nalias; i++) {
if (!strcmp (str, egg->lang.aliases[i].name)) {
@@ -243,7 +247,9 @@ static void rcc_internal_mathop(REgg *egg, const char *ptr, char *ep, char op) {
*q = '\x00';
}
REggEmit *e = egg->remit;
- while (*p && is_space (*p)) p++;
+ while (*p && is_space (*p)) {
+ p++;
+ }
if (is_var (p)) {
p = r_egg_mkvar (egg, buf, p, 0);
if (egg->lang.varxs == '*') {
@@ -281,7 +287,9 @@ static void rcc_mathop(REgg *egg, char **pos, int level) {
int op_ret = level;
char op, *next_pos;
- while (**pos && is_space (**pos)) (*pos)++;
+ while (**pos && is_space (**pos)) {
+ (*pos)++;
+ }
next_pos = *pos + 1;
do {
@@ -664,7 +672,9 @@ static void rcc_fun(REgg *egg, const char *str) {
} else if (strstr (ptr, "alias")) {
egg->lang.mode = ALIAS;
ptr2 = egg->lang.dstvar = strdup (skipspaces (str));
- while (*ptr2 && !is_space (*ptr2)) ptr2++;
+ while (*ptr2 && !is_space (*ptr2)) {
+ ptr2++;
+ }
*ptr2 = '\x00';
// for aliases must be valid and accurate strings
} else if (strstr (ptr, "data")) {
@@ -1397,7 +1407,9 @@ R_API int r_egg_lang_parsechar(REgg *egg, char c) {
if (egg->lang.elem_n) {
ptr = egg->lang.elem;
egg->lang.elem[egg->lang.elem_n] = '\0';
- while (is_space (*ptr)) ptr++;
+ while (is_space (*ptr)) {
+ ptr++;
+ }
rcc_fun (egg, ptr);
}
egg->lang.elem_n = 0;
diff --git a/libr/egg/emit_trace.c b/libr/egg/emit_trace.c
index 15c59c9e8d..b90a652cce 100644
--- a/libr/egg/emit_trace.c
+++ b/libr/egg/emit_trace.c
@@ -57,13 +57,19 @@ static void emit_set_string(REgg *egg, const char *dstvar, const char *str, int
}
static void emit_call(REgg *egg, const char *str, int atr) {
- if (atr) r_egg_printf (egg, "call ([%s])\n", str);
- else r_egg_printf (egg, "call (%s)\n", str);
+ if (atr) {
+ r_egg_printf (egg, "call ([%s])\n", str);
+ } else {
+ r_egg_printf (egg, "call (%s)\n", str);
+ }
}
static void emit_jmp(REgg *egg, const char *str, int atr) {
- if (atr) r_egg_printf (egg, "goto ([%s])\n", str);
- else r_egg_printf (egg, "goto (%s)\n", str);
+ if (atr) {
+ r_egg_printf (egg, "goto ([%s])\n", str);
+ } else {
+ r_egg_printf (egg, "goto (%s)\n", str);
+ }
}
static void emit_arg (REgg *egg, int xs, int num, const char *str) {
@@ -131,7 +137,9 @@ static void emit_branch(REgg *egg, char *b, char *g, char *e, char *n, int sz, c
}
}
- if (*arg=='=') arg++; /* for <=, >=, ... */
+ if (*arg == '=') {
+ arg++; /* for <=, >=, ... */
+ }
p = r_egg_mkvar (egg, str, arg, 0);
r_egg_printf (egg, "%s (%s) => (%s)\n", op, p, dst);
free (p);
@@ -154,17 +162,23 @@ static void emit_mathop(REgg *egg, int ch, int vs, int type, const char *eq, con
case '/': op = "div"; break;
default: op = "mov"; break;
}
- if (!eq) eq = R_AX;
- if (!p) p = R_AX;
+ if (!eq) {
+ eq = R_AX;
+ }
+ if (!p) {
+ p = R_AX;
+ }
#if 0
// TODO:
eprintf ("TYPE = %c\n", type);
eprintf (" %s%c %c%s, %s\n", op, vs, type, eq, p);
eprintf (" %s %s, [%s]\n", op, p, eq);
#endif
- if (type == '*')
+ if (type == '*') {
r_egg_printf (egg, "%s (%s, [%s])\n", op, p, eq);
- else r_egg_printf (egg, "%s (%s, %s)\n", op, p, eq);
+ } else {
+ r_egg_printf (egg, "%s (%s, %s)\n", op, p, eq);
+ }
}
static const char* emit_regs(REgg *egg, int idx) {
diff --git a/libr/egg/emit_x86.c b/libr/egg/emit_x86.c
index 4db85bca72..364a326c00 100644
--- a/libr/egg/emit_x86.c
+++ b/libr/egg/emit_x86.c
@@ -34,14 +34,18 @@ static char *regs[] = { "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp" };
static void emit_init (REgg *egg) {
// TODO: add 'andb rsp, 0xf0'
- if (attsyntax) r_egg_printf (egg, "mov %%"R_SP", %%"R_BP"\n");
- else r_egg_printf (egg, "mov "R_BP", "R_SP"\n");
+if (attsyntax) {
+ r_egg_printf (egg, "mov %%" R_SP ", %%" R_BP "\n");
+} else {
+ r_egg_printf (egg, "mov " R_BP ", " R_SP "\n");
+}
}
static char *emit_syscall (REgg *egg, int nargs) {
char p[512];
- if (attsyntax)
- return strdup (": mov $`.arg`, %"R_AX"\n: "SYSCALL_ATT"\n");
+ if (attsyntax) {
+ return strdup (": mov $`.arg`, %" R_AX "\n: " SYSCALL_ATT "\n");
+ }
switch (egg->os) {
case R_EGG_OS_LINUX:
strcpy (p, "\n : mov "R_AX", `.arg`\n : "SYSCALL_INTEL "\n");
@@ -69,17 +73,21 @@ static char *emit_syscall (REgg *egg, int nargs) {
}
static void emit_frame (REgg *egg, int sz) {
- if (sz<1)
+ if (sz < 1) {
return;
- if (attsyntax)
+ }
+ if (attsyntax) {
r_egg_printf (egg,
" push %%"R_BP"\n"
" mov %%"R_SP", %%"R_BP"\n"
" sub $%d, %%"R_SP"\n", sz);
- else r_egg_printf (egg,
- " push "R_BP"\n"
- " mov "R_BP", "R_SP"\n"
- " sub "R_SP", %d\n", sz);
+ } else {
+ r_egg_printf (egg,
+ " push " R_BP "\n"
+ " mov " R_BP ", " R_SP "\n"
+ " sub " R_SP ", %d\n",
+ sz);
+ }
}
static void emit_frame_end (REgg *egg, int sz, int ctx) {
@@ -92,8 +100,9 @@ static void emit_frame_end (REgg *egg, int sz, int ctx) {
r_egg_printf (egg, " pop "R_BP"\n");
}
}
- if (ctx>0)
+ if (ctx > 0) {
r_egg_printf (egg, " ret\n");
+ }
}
static void emit_comment(REgg *egg, const char *fmt, ...) {
@@ -101,8 +110,11 @@ static void emit_comment(REgg *egg, const char *fmt, ...) {
char buf[1024];
va_start (ap, fmt);
vsnprintf (buf, sizeof (buf), fmt, ap);
- if (attsyntax) r_egg_printf (egg, " /* %s */\n", buf);
- else r_egg_printf (egg, "# %s\n", buf);
+ if (attsyntax) {
+ r_egg_printf (egg, " /* %s */\n", buf);
+ } else {
+ r_egg_printf (egg, "# %s\n", buf);
+ }
va_end (ap);
}
@@ -160,8 +172,11 @@ static void emit_string(REgg *egg, const char *dstvar, const char *str, int j) {
/* XXX endian issues (non-portable asm) */
ut32 *n = (ut32 *)(s+i-4);
p = r_egg_mkvar (egg, str2, dstvar, i+BPOFF);
- if (attsyntax) r_egg_printf (egg, " movl $0x%x, %s\n", M32(*n), p);
- else r_egg_printf (egg, " mov dword %s, 0x%x\n", p, M32(*n));
+ if (attsyntax) {
+ r_egg_printf (egg, " movl $0x%x, %s\n", M32 (*n), p);
+ } else {
+ r_egg_printf (egg, " mov dword %s, 0x%x\n", p, M32 (*n));
+ }
free (p);
j -= 4;
}
@@ -169,19 +184,28 @@ static void emit_string(REgg *egg, const char *dstvar, const char *str, int j) {
/* zero */
p = r_egg_mkvar (egg, str2, dstvar, i+BPOFF);
- if (attsyntax) r_egg_printf (egg, " movl $0, %s\n", p);
- else r_egg_printf (egg, " mov dword %s, 0\n", p);
+ if (attsyntax) {
+ r_egg_printf (egg, " movl $0, %s\n", p);
+ } else {
+ r_egg_printf (egg, " mov dword %s, 0\n", p);
+ }
free (p);
/* store pointer */
p = r_egg_mkvar (egg, str2, dstvar, j+4+BPOFF);
- if (attsyntax) r_egg_printf (egg, " lea %s, %%"R_AX"\n", p);
- else r_egg_printf (egg, " lea "R_AX", %s\n", p);
+ if (attsyntax) {
+ r_egg_printf (egg, " lea %s, %%" R_AX "\n", p);
+ } else {
+ r_egg_printf (egg, " lea " R_AX ", %s\n", p);
+ }
free (p);
p = r_egg_mkvar (egg, str2, dstvar, 0);
- if (attsyntax) r_egg_printf (egg, " mov %%"R_AX", %s\n", p);
- else r_egg_printf (egg, " mov %s, "R_AX"\n", p);
+ if (attsyntax) {
+ r_egg_printf (egg, " mov %%" R_AX ", %s\n", p);
+ } else {
+ r_egg_printf (egg, " mov %s, " R_AX "\n", p);
+ }
free (p);
#undef BPOFF
@@ -208,16 +232,24 @@ static void emit_string(REgg *egg, const char *dstvar, const char *str, int j) {
static void emit_call(REgg *egg, const char *str, int atr) {
if (atr) {
- if (attsyntax) r_egg_printf (egg, " call *%s\n", str);
- else r_egg_printf (egg, " call [%s]\n", str);
- } else r_egg_printf (egg, " call %s\n", str);
+ if (attsyntax) {
+ r_egg_printf (egg, " call *%s\n", str);
+ } else {
+ r_egg_printf (egg, " call [%s]\n", str);
+ }
+ } else {
+ r_egg_printf (egg, " call %s\n", str);
+ }
}
static void emit_jmp(REgg *egg, const char *str, int atr) {
if (str) {
if (atr) {
- if (attsyntax) r_egg_printf (egg, " jmp *%s\n", str);
- else r_egg_printf (egg, " jmp [%s]\n", str);
+ if (attsyntax) {
+ r_egg_printf (egg, " jmp *%s\n", str);
+ } else {
+ r_egg_printf (egg, " jmp [%s]\n", str);
+ }
} else {
r_egg_printf (egg, " jmp %s\n", str);
}
@@ -228,8 +260,9 @@ static void emit_jmp(REgg *egg, const char *str, int atr) {
static void emit_arg (REgg *egg, int xs, int num, const char *str) {
int d = atoi (str);
- if (!attsyntax && (*str=='$'))
- str = str +1;
+ if (!attsyntax && (*str == '$')) {
+ str = str + 1;
+ }
switch (xs) {
case 0:
#ifdef ARCH_X86_64
@@ -249,31 +282,48 @@ static void emit_arg (REgg *egg, int xs, int num, const char *str) {
#endif
break;
case '*':
- if (attsyntax) r_egg_printf (egg, " push (%s)\n", str);
- else r_egg_printf (egg, " push [%s]\n", str);
+ if (attsyntax) {
+ r_egg_printf (egg, " push (%s)\n", str);
+ } else {
+ r_egg_printf (egg, " push [%s]\n", str);
+ }
break;
case '&':
if (attsyntax) {
- if (d != 0) r_egg_printf (egg, " addl $%d, %%"R_BP"\n", d);
+ if (d != 0) {
+ r_egg_printf (egg, " addl $%d, %%" R_BP "\n", d);
+ }
r_egg_printf (egg, " pushl %%"R_BP"\n");
- if (d != 0) r_egg_printf (egg, " subl $%d, %%"R_BP"\n", d);
+ if (d != 0) {
+ r_egg_printf (egg, " subl $%d, %%" R_BP "\n", d);
+ }
} else {
- if (d != 0) r_egg_printf (egg, " add "R_BP", %d\n", d);
+ if (d != 0) {
+ r_egg_printf (egg, " add " R_BP ", %d\n", d);
+ }
r_egg_printf (egg, " push "R_BP"\n");
- if (d != 0) r_egg_printf (egg, " sub "R_BP", %d\n", d);
+ if (d != 0) {
+ r_egg_printf (egg, " sub " R_BP ", %d\n", d);
+ }
}
break;
}
}
static void emit_get_result(REgg *egg, const char *ocn) {
- if (attsyntax) r_egg_printf (egg, " mov %%"R_AX", %s\n", ocn);
- else r_egg_printf (egg, " mov %s, "R_AX"\n", ocn);
+ if (attsyntax) {
+ r_egg_printf (egg, " mov %%" R_AX ", %s\n", ocn);
+ } else {
+ r_egg_printf (egg, " mov %s, " R_AX "\n", ocn);
+ }
}
static void emit_restore_stack (REgg *egg, int size) {
- if (attsyntax) r_egg_printf (egg, " add $%d, %%"R_SP" /* args */\n", size);
- else r_egg_printf (egg, " add "R_SP", %d\n", size);
+ if (attsyntax) {
+ r_egg_printf (egg, " add $%d, %%" R_SP " /* args */\n", size);
+ } else {
+ r_egg_printf (egg, " add " R_SP ", %d\n", size);
+ }
}
static void emit_get_while_end (REgg *egg, char *str, const char *ctxpush, const char *label) {
@@ -298,22 +348,34 @@ static void emit_while_end (REgg *egg, const char *labelback) {
static void emit_get_var (REgg *egg, int type, char *out, int idx) {
switch (type) {
case 0: /* variable */
- if (idx>0) sprintf (out, "["R_BP"+%d]", idx);
- else if (idx<0) sprintf (out, "["R_BP"%d]", idx);
- else strcpy (out, "["R_BP"]");
+ if (idx > 0) {
+ sprintf (out, "[" R_BP "+%d]", idx);
+ } else if (idx < 0) {
+ sprintf (out, "[" R_BP "%d]", idx);
+ } else {
+ strcpy (out, "[" R_BP "]");
+ }
break;
case 1: /* argument */
// OMG WE CANT stuff found in relative address in stack in the stack
eprintf ("WARNING: Using stack vars in naked functions\n");
idx = 8; // HACK to make arg0, arg4, ... work
- if (idx>0) sprintf (out, "["R_SP"+%d]", idx);
- else if (idx<0) sprintf (out, "["R_SP"%d]", idx);
- else strcpy (out, "["R_SP"]");
+ if (idx > 0) {
+ sprintf (out, "[" R_SP "+%d]", idx);
+ } else if (idx < 0) {
+ sprintf (out, "[" R_SP "%d]", idx);
+ } else {
+ strcpy (out, "[" R_SP "]");
+ }
break;
case 2:
- if (idx>0) sprintf (out, "["R_BP"+%d]", idx);
- else if (idx<0) sprintf (out, "["R_BP"%d]", idx);
- else strcpy (out, "["R_BP"]");
+ if (idx > 0) {
+ sprintf (out, "[" R_BP "+%d]", idx);
+ } else if (idx < 0) {
+ sprintf (out, "[" R_BP "%d]", idx);
+ } else {
+ strcpy (out, "[" R_BP "]");
+ }
break;
}
}
@@ -326,7 +388,9 @@ static void emit_load_ptr(REgg *egg, const char *dst) {
int d = atoi (dst);
if (d == 0) { // hack to handle stackvarptrz
char *p = strchr (dst, '+');
- if (p) d = atoi (p+1);
+ if (p) {
+ d = atoi (p + 1);
+ }
}
//eprintf ("emit_load_ptr: HACK\n");
// XXX: 32/64bit care
@@ -370,12 +434,17 @@ static void emit_branch(REgg *egg, char *b, char *g, char *e, char *n, int sz, c
op = "jne";
} else {
arg = attsyntax? "$0": "0";
- if (n) op = "jnz";
- else op ="jz";
+ if (n) {
+ op = "jnz";
+ } else {
+ op = "jz";
+ }
}
}
- if (*arg=='=') arg++; /* for <=, >=, ... */
+ if (*arg == '=') {
+ arg++; /* for <=, >=, ... */
+ }
p = r_egg_mkvar (egg, str, arg, 0);
if (attsyntax) {
r_egg_printf (egg, " pop %%"R_AX"\n"); /* TODO: add support for more than one arg get arg0 */
@@ -436,20 +505,31 @@ static void emit_mathop(REgg *egg, int ch, int vs, int type, const char *eq, con
default: op = "mov"; break;
}
if (attsyntax) {
- if (!eq) eq = "%"R_AX;
- if (!p) p = "%"R_AX;
+ if (!eq) {
+ eq = "%" R_AX;
+ }
+ if (!p) {
+ p = "%" R_AX;
+ }
r_egg_printf (egg, " %s%c %c%s, %s\n", op, vs, type, eq, p);
} else {
- if (!eq) eq = R_AX;
- if (!p) p = R_AX;
- // TODO:
+ if (!eq) {
+ eq = R_AX;
+ }
+ if (!p) {
+ p = R_AX;
+ }
+ // TODO:
#if 0
eprintf ("TYPE = %c\n", type);
eprintf (" %s%c %c%s, %s\n", op, vs, type, eq, p);
eprintf (" %s %s, [%s]\n", op, p, eq);
#endif
- if (type == '*') r_egg_printf (egg, " %s %s, [%s]\n", op, p, eq);
- else r_egg_printf (egg, " %s %s, %s\n", op, p, eq);
+ if (type == '*') {
+ r_egg_printf (egg, " %s %s, [%s]\n", op, p, eq);
+ } else {
+ r_egg_printf (egg, " %s %s, %s\n", op, p, eq);
+ }
}
}
@@ -460,7 +540,9 @@ static const char* emit_regs(REgg *egg, int idx) {
static void emit_get_ar (REgg *egg, char *out, int idx) {
const char *reg = emit_regs (egg, R_REG_AR_OFF + idx);
- if (reg) strcpy (out, reg);
+ if (reg) {
+ strcpy (out, reg);
+ }
}
REggEmit EMIT_NAME = {
diff --git a/libr/egg/p/egg_exec.c b/libr/egg/p/egg_exec.c
index 95cbe94f5c..a45580511b 100644
--- a/libr/egg/p/egg_exec.c
+++ b/libr/egg/p/egg_exec.c
@@ -84,7 +84,9 @@ static RBuffer *build (REgg *egg) {
}
break;
case R_EGG_OS_LINUX:
- if (suid) eprintf ("no suid for this platform\n");
+ if (suid) {
+ eprintf ("no suid for this platform\n");
+ }
suid = 0;
switch (egg->arch) {
case R_SYS_ARCH_X86:
@@ -121,8 +123,11 @@ static RBuffer *build (REgg *egg) {
if (sc) {
r_buf_set_bytes (buf, sc, strlen ((const char *)sc));
if (shell && *shell) {
- if (cd) r_buf_write_at (buf, cd, (const ut8*)shell, strlen (shell)+1);
- else eprintf ("Cannot set shell\n");
+ if (cd) {
+ r_buf_write_at (buf, cd, (const ut8 *)shell, strlen (shell) + 1);
+ } else {
+ eprintf ("Cannot set shell\n");
+ }
}
}
free (suid);
diff --git a/libr/flag/flag.c b/libr/flag/flag.c
index 94f078deef..9f68863a94 100644
--- a/libr/flag/flag.c
+++ b/libr/flag/flag.c
@@ -117,7 +117,9 @@ static int set_name(RFlagItem *item, const char *name) {
R_API RFlag * r_flag_new() {
int i;
RFlag *f = R_NEW0 (RFlag);
- if (!f) return NULL;
+ if (!f) {
+ return NULL;
+ }
f->num = r_num_new (&num_callback, &str_callback, f);
if (!f->num) {
r_flag_free (f);
@@ -263,9 +265,11 @@ R_API void r_flag_list(RFlag *f, int rad, const char *pfx) {
} else {
f->cb_printf ("\"offset\":%"PFMT64d, flag->offset);
}
- if (flag->comment)
+ if (flag->comment) {
f->cb_printf (",\"comment\":\"}");
- else f->cb_printf ("}");
+ } else {
+ f->cb_printf ("}");
+ }
first = 0;
}
f->cb_printf ("]\n");
@@ -284,15 +288,17 @@ R_API void r_flag_list(RFlag *f, int rad, const char *pfx) {
const char *flagspace;
fs = flag->space;
flagspace = r_flag_space_get_i (f, fs);
- if (!flagspace || !*flagspace)
+ if (!flagspace || !*flagspace) {
flagspace = "*";
+ }
f->cb_printf ("fs %s\n", flagspace);
}
if (flag->alias) {
f->cb_printf ("fa %s %s\n", flag->name, flag->alias);
- if (flag->comment && *flag->comment)
+ if (flag->comment && *flag->comment) {
f->cb_printf ("\"fC %s %s\"\n",
flag->name, flag->comment);
+ }
} else {
f->cb_printf ("f %s %"PFMT64d" 0x%08"PFMT64x"%s%s %s\n",
flag->name, flag->size, flag->offset,
@@ -420,7 +426,9 @@ R_API RFlagItem *r_flag_get_i2(RFlag *f, ut64 off) {
break;
}
oitem = item;
- if (strlen (item->name) < 5 || item->name[3]!='.') continue;
+ if (strlen (item->name) < 5 || item->name[3] != '.') {
+ continue;
+ }
oitem = item;
}
return evalFlag (f, oitem);
@@ -736,8 +744,12 @@ int main () {
#endif
R_API const char *r_flag_color(RFlag *f, RFlagItem *it, const char *color) {
- if (!f || !it) return NULL;
- if (!color) return it->color;
+ if (!f || !it) {
+ return NULL;
+ }
+ if (!color) {
+ return it->color;
+ }
free (it->color);
it->color = *color ? strdup (color) : NULL;
return it->color;
@@ -759,8 +771,9 @@ R_API int r_flag_count(RFlag *f, const char *glob) {
RFlagItem *flag;
RListIter *iter;
r_list_foreach (f->flags, iter, flag) {
- if (r_str_glob (flag->name, glob))
- count ++;
+ if (r_str_glob (flag->name, glob)) {
+ count++;
+ }
}
return count;
}
diff --git a/libr/flag/sort.c b/libr/flag/sort.c
index faae4f9af4..529df4b0e6 100644
--- a/libr/flag/sort.c
+++ b/libr/flag/sort.c
@@ -13,8 +13,11 @@ static int ncmp(const void *a, const void *b) {
static int cmp(const void *a, const void *b) {
RFlagItem *fa = (RFlagItem *)a;
RFlagItem *fb = (RFlagItem *)b;
- if (fa->offset > fb->offset) return 1;
- else if (fa->offset < fb->offset) return -1;
+ if (fa->offset > fb->offset) {
+ return 1;
+ } else if (fa->offset < fb->offset) {
+ return -1;
+ }
return 0;
}
diff --git a/libr/flag/spaces.c b/libr/flag/spaces.c
index d6ec044ab4..43d8af87aa 100644
--- a/libr/flag/spaces.c
+++ b/libr/flag/spaces.c
@@ -149,7 +149,9 @@ R_API int r_flag_space_list(RFlag *f, int mode) {
(allSelected || i == f->space_idx)? "true":"false");
} else if (mode=='*') {
f->cb_printf ("fs %s\n", f->spaces[i]);
- if (i==f->space_idx) defspace = f->spaces[i];
+ if (i == f->space_idx) {
+ defspace = f->spaces[i];
+ }
} else {
#define INDENT 5
char num0[64], num1[64], spaces[32];
@@ -188,8 +190,12 @@ R_API int r_flag_space_rename (RFlag *f, const char *oname, const char *nname) {
if (!nname) {
return false;
}
- while (*oname==' ') oname++;
- while (*nname==' ') nname++;
+ while (*oname == ' ') {
+ oname++;
+ }
+ while (*nname == ' ') {
+ nname++;
+ }
for (i = 0; i < R_FLAG_SPACES_MAX; i++) {
if (f->spaces[i] && !strcmp (oname, f->spaces[i])) {
free (f->spaces[i]);
diff --git a/libr/fs/p/fs_posix.c b/libr/fs/p/fs_posix.c
index 9f94ad4b01..bb6d6f7940 100644
--- a/libr/fs/p/fs_posix.c
+++ b/libr/fs/p/fs_posix.c
@@ -11,7 +11,9 @@
static RFSFile* fs_posix_open(RFSRoot *root, const char *path) {
FILE *fd;
RFSFile *file = r_fs_file_new (root, path);
- if (!file) return NULL;
+ if (!file) {
+ return NULL;
+ }
file->ptr = NULL;
file->p = root->p;
fd = r_sandbox_fopen (path, "r");
diff --git a/libr/fs/shell.c b/libr/fs/shell.c
index 1e1931a1b0..a0aa0425e4 100644
--- a/libr/fs/shell.c
+++ b/libr/fs/shell.c
@@ -157,8 +157,9 @@ R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) {
}
} else if (!memcmp (buf, "cat ", 4)) {
input = buf + 3;
- while (input[0] == ' ')
+ while (input[0] == ' ') {
input++;
+ }
if (input[0] == '/') {
if (root) {
strncpy (str, root, sizeof (str) - 1);
@@ -187,8 +188,9 @@ R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) {
} else if (!memcmp (buf, "get ", 4)) {
char* s = 0;
input = buf + 3;
- while (input[0] == ' ')
+ while (input[0] == ' ') {
input++;
+ }
if (input[0] == '/') {
if (root) {
s = malloc (strlen (root) + strlen (input) + 2);
diff --git a/libr/io/p/io_bfdbg.c b/libr/io/p/io_bfdbg.c
index 1bcbd8c38a..a34200a8a8 100644
--- a/libr/io/p/io_bfdbg.c
+++ b/libr/io/p/io_bfdbg.c
@@ -36,39 +36,45 @@ static inline int is_in_base(ut64 off, BfvmCPU *c) {
static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
RIOBfdbg *riom;
int sz;
- if (!fd || !fd->data)
+ if (!fd || !fd->data) {
return -1;
+ }
riom = fd->data;
/* data base buffer */
if (is_in_base (io->off, riom->bfvm)) {
int n = io->off-riom->bfvm->base;
- if (n>count)
+ if (n > count) {
count = n;
+ }
memcpy (riom->bfvm->mem+n, buf, count);
return count;
}
/* screen buffer */
if (is_in_screen (io->off, riom->bfvm)) {
int n = io->off-riom->bfvm->screen;
- if (n>count)
- count = riom->bfvm->screen_size-n;
+ if (n > count) {
+ count = riom->bfvm->screen_size - n;
+ }
memcpy (riom->bfvm->screen_buf+n, buf, count);
return count;
}
/* input buffer */
if (is_in_input (io->off, riom->bfvm)) {
int n = io->off-riom->bfvm->input;
- if (n>count)
- count = riom->bfvm->input_size-n;
+ if (n > count) {
+ count = riom->bfvm->input_size - n;
+ }
memcpy (riom->bfvm->input_buf+n, buf, count);
return count;
}
/* read from file */
sz = RIOBFDBG_SZ (fd);
- if (io->off+count >= sz)
- count = sz-io->off;
- if (io->off >= sz)
+ if (io->off + count >= sz) {
+ count = sz - io->off;
+ }
+ if (io->off >= sz) {
return -1;
+ }
memcpy (RIOBFDBG_BUF (fd)+io->off, buf, count);
return count;
}
@@ -76,47 +82,54 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
RIOBfdbg *riom;
int sz;
- if (!fd || !fd->data)
+ if (!fd || !fd->data) {
return -1;
+ }
riom = fd->data;
/* data base buffer */
if (is_in_base (io->off, riom->bfvm)) {
int n = io->off-riom->bfvm->base;
- if (n>count)
+ if (n > count) {
count = n;
+ }
memcpy (buf, riom->bfvm->mem+n, count);
return count;
}
/* screen buffer */
if (is_in_screen (io->off, riom->bfvm)) {
int n = io->off-riom->bfvm->screen;
- if (n>count)
- count = riom->bfvm->screen_size-n;
+ if (n > count) {
+ count = riom->bfvm->screen_size - n;
+ }
memcpy (buf, riom->bfvm->screen_buf+n, count);
return count;
}
/* input buffer */
if (is_in_input (io->off, riom->bfvm)) {
int n = io->off-riom->bfvm->input;
- if (n>count)
- count = riom->bfvm->input_size-n;
+ if (n > count) {
+ count = riom->bfvm->input_size - n;
+ }
memcpy (buf, riom->bfvm->input_buf+n, count);
return count;
}
/* read from file */
sz = RIOBFDBG_SZ (fd);
- if (io->off+count >= sz)
- count = sz-io->off;
- if (io->off >= sz)
+ if (io->off + count >= sz) {
+ count = sz - io->off;
+ }
+ if (io->off >= sz) {
return -1;
+ }
memcpy (buf, RIOBFDBG_BUF (fd)+io->off, count);
return count;
}
static int __close(RIODesc *fd) {
RIOBfdbg *riom;
- if (!fd || !fd->data)
+ if (!fd || !fd->data) {
return -1;
+ }
riom = fd->data;
bfvm_free (riom->bfvm);
free (riom->buf);
@@ -149,7 +162,9 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
if (__plugin_open (io, pathname, 0)) {
RIOBind iob;
RIOBfdbg *mal = R_NEW0 (RIOBfdbg);
- if (!mal) return NULL;
+ if (!mal) {
+ return NULL;
+ }
r_io_bind (io, &iob);
mal->fd = getmalfd (mal);
mal->bfvm = bfvm_new (&iob);
diff --git a/libr/io/p/io_bochs.c b/libr/io/p/io_bochs.c
index 64eb87d3ff..ac540acdb7 100644
--- a/libr/io/p/io_bochs.c
+++ b/libr/io/p/io_bochs.c
@@ -77,9 +77,10 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
memset (buf, 0xff, count);
ut64 addr = io->off;
- if (!desc || !desc->data)
+ if (!desc || !desc->data) {
return -1;
- lprintf ("io_read ofs= %016"PFMT64x" count= %x\n", io->off, count);
+ }
+ lprintf ("io_read ofs= %016"PFMT64x" count= %x\n", io->off, count);
bochs_read (desc,addr,count,buf);
return count;
}
diff --git a/libr/io/p/io_debug.c b/libr/io/p/io_debug.c
index aa0623a6e1..cbbd131e1e 100644
--- a/libr/io/p/io_debug.c
+++ b/libr/io/p/io_debug.c
@@ -529,7 +529,9 @@ static int fork_and_ptraceme(RIO *io, int bits, const char *cmd) {
/* XXX: clean this dirty code */
do {
ret = wait (&status);
- if (ret == -1) return -1;
+ if (ret == -1) {
+ return -1;
+ }
if (ret != child_pid) {
eprintf ("Wait event received by "
"different pid %d\n", ret);
diff --git a/libr/io/p/io_default.c b/libr/io/p/io_default.c
index 665214d917..253d34dabc 100644
--- a/libr/io/p/io_default.c
+++ b/libr/io/p/io_default.c
@@ -288,7 +288,9 @@ static int r_io_def_mmap_write(RIO *io, RIODesc *fd, const ut8 *buf, int count)
}
if (mmo && mmo->buf) {
- if (!(mmo->flags & R_IO_WRITE)) return -1;
+ if (!(mmo->flags & R_IO_WRITE)) {
+ return -1;
+ }
if ( (count + addr > mmo->buf->length) || mmo->buf->empty) {
ut64 sz = count + addr;
r_file_truncate (mmo->filename, sz);
diff --git a/libr/io/p/io_gprobe.c b/libr/io/p/io_gprobe.c
index 26657a76aa..3bb6504395 100644
--- a/libr/io/p/io_gprobe.c
+++ b/libr/io/p/io_gprobe.c
@@ -80,8 +80,9 @@ static ut8 gprobe_checksum_i2c (const ut8 *p, unsigned int size, ut8 initial) {
ut8 res = initial;
unsigned int k;
- for (k = 0; k < size; ++k)
+ for (k = 0; k < size; ++k) {
res ^= p[k];
+ }
return res;
}
diff --git a/libr/io/p/io_http.c b/libr/io/p/io_http.c
index e54c0bfcf6..c4797094a7 100644
--- a/libr/io/p/io_http.c
+++ b/libr/io/p/io_http.c
@@ -80,7 +80,9 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
out = r_socket_http_get (pathname, &code, &rlen);
if (out && rlen>0) {
RIOMalloc *mal = R_NEW0 (RIOMalloc);
- if (!mal) return NULL;
+ if (!mal) {
+ return NULL;
+ }
mal->size = rlen;
mal->buf = malloc (mal->size+1);
if (!mal->buf) {
diff --git a/libr/io/p/io_ihex.c b/libr/io/p/io_ihex.c
index 55b4525717..f88f2bf146 100644
--- a/libr/io/p/io_ihex.c
+++ b/libr/io/p/io_ihex.c
@@ -123,8 +123,9 @@ static int fwblock(FILE *fd, ut8 *b, ut32 start_addr, ut16 size) {
int j;
ut32 i; //has to be bigger than size !
- if (size <1 || !fd || !b)
+ if (size < 1 || !fd || !b) {
return -1;
+ }
for (i = 0; (i + 0x10) < size; i += 0x10) {
cks = 0x10;
@@ -135,16 +136,19 @@ static int fwblock(FILE *fd, ut8 *b, ut32 start_addr, ut16 size) {
}
cks = 0 - cks;
if (fprintf (fd, ":10%04x00%02x%02x%02x%02x%02x%02x%02x"
- "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
- (i+start_addr)&0xffff, b[0], b[1], b[2], b[3], b[4], b[5], b[6],
- b[7], b[8], b[9], b[10], b[11], b[12], b[13],
- b[14], b[15], cks) < 0) return -1;
+ "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
+ (i + start_addr) & 0xffff, b[0], b[1], b[2], b[3], b[4], b[5], b[6],
+ b[7], b[8], b[9], b[10], b[11], b[12], b[13],
+ b[14], b[15], cks) < 0) {
+ return -1;
+ }
start_addr += 0x10;
b += 0x10;
if ((start_addr & 0xffff) < 0x10) {
//addr rollover: write ext address record
- if (fw04b (fd, start_addr >> 16) < 0)
+ if (fw04b (fd, start_addr >> 16) < 0) {
return -1;
+ }
}
}
if (i == size) {
@@ -160,8 +164,9 @@ static int fwblock(FILE *fd, ut8 *b, ut32 start_addr, ut16 size) {
}
cks -= j;
- if (fprintf (fd, ":%02X%04X00%.*s%02X\n", j, last_addr, 2*j, linebuf,cks) < 0)
+ if (fprintf (fd, ":%02X%04X00%.*s%02X\n", j, last_addr, 2 * j, linebuf, cks) < 0) {
return -1;
+ }
return 0;
}
@@ -314,7 +319,9 @@ static bool ihex_parse(RBuffer *rbuf, char *str) {
sec_size = 0;
eol = strchr (str + 1, ':');
- if (eol) *eol = 0;
+ if (eol) {
+ *eol = 0;
+ }
cksum = bc;
cksum += addr_tmp>>8;
cksum += addr_tmp;
@@ -342,7 +349,9 @@ static bool ihex_parse(RBuffer *rbuf, char *str) {
if (eol) {
// checksum
byte=0; //break checksum if sscanf failed
- if (sscanf (str+9+ 4, "%02x", &byte) !=1) cksum=1;
+ if (sscanf (str + 9 + 4, "%02x", &byte) != 1) {
+ cksum = 1;
+ }
cksum += byte;
if (cksum != 0) {
ut8 fixedcksum = 0-(cksum-byte);
diff --git a/libr/io/p/io_ptrace.c b/libr/io/p/io_ptrace.c
index 8b7c723f44..9c743a7b1e 100644
--- a/libr/io/p/io_ptrace.c
+++ b/libr/io/p/io_ptrace.c
@@ -59,10 +59,12 @@ static int debug_os_read_at(int pid, ut32 *buf, int sz, ut64 addr) {
ut32 words = sz / sizeof (ut32);
ut32 last = sz % sizeof (ut32);
ut32 x, lr, *at = (ut32*)(size_t)addr;
- if (sz<1 || addr==UT64_MAX)
+ if (sz < 1 || addr == UT64_MAX) {
return -1;
- for (x=0; xoff;
- if (!desc || !desc->data)
+ if (!desc || !desc->data) {
return -1;
+ }
memset (buf, '\xff', len); // TODO: only memset the non-readed bytes
/* reopen procpidmem if necessary */
#if USE_PROC_PID_MEM
@@ -173,9 +176,9 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
if (__plugin_open (io, file,0)) {
int pid = atoi (file+9);
ret = ptrace (PTRACE_ATTACH, pid, 0, 0);
- if (file[0] == 'p') //ptrace
+ if (file[0] == 'p') { //ptrace
ret = 0;
- else if (ret == -1) {
+ } else if (ret == -1) {
#ifdef __ANDROID__
eprintf ("ptrace_attach: Operation not permitted\n");
#else
@@ -192,7 +195,9 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
#endif
} else if (__waitpid (pid)) {
ret = pid;
- } else eprintf ("Error in waitpid\n");
+ } else {
+ eprintf ("Error in waitpid\n");
+ }
if (ret != -1) {
RIOPtrace *riop = R_NEW0 (RIOPtrace);
if (!riop) {
diff --git a/libr/io/p/io_qnx.c b/libr/io/p/io_qnx.c
index 82ec446fff..d36a8988ea 100644
--- a/libr/io/p/io_qnx.c
+++ b/libr/io/p/io_qnx.c
@@ -34,7 +34,9 @@ static int debug_qnx_read_at (ut8 *buf, int sz, ut64 addr) {
memcpy (buf, c_buff, sz);
return sz;
}
- if (sz < 1 || addr >= UT64_MAX) return -1;
+ if (sz < 1 || addr >= UT64_MAX) {
+ return -1;
+ }
for (x = 0; x < packets; x++) {
qnxr_read_memory (desc, addr + x * size_max, (buf + x * size_max), size_max);
}
@@ -78,8 +80,9 @@ static RIODesc *__open (RIO *io, const char *file, int rw, int mode) {
RIOQnx *rioq;
char host[128], *port, *p;
- if (!__plugin_open (io, file, 0))
+ if (!__plugin_open (io, file, 0)) {
return NULL;
+ }
if (rioqnx) {
// FIX: Don't allocate more than one RIODesc
return rioqnx;
@@ -94,7 +97,9 @@ static RIODesc *__open (RIO *io, const char *file, int rw, int mode) {
*port = '\0';
port++;
p = strchr (port, '/');
- if (p) *p = 0;
+ if (p) {
+ *p = 0;
+ }
if (r_sandbox_enable (0)) {
eprintf ("sandbox: Cannot use network\n");
@@ -115,7 +120,9 @@ static RIODesc *__open (RIO *io, const char *file, int rw, int mode) {
static int __write (RIO *io, RIODesc *fd, const ut8 *buf, int count) {
ut64 addr = io->off;
- if (!desc) return -1;
+ if (!desc) {
+ return -1;
+ }
return debug_qnx_write_at (buf, count, addr);
}
@@ -126,7 +133,9 @@ static ut64 __lseek (RIO *io, RIODesc *fd, ut64 offset, int whence) {
static int __read (RIO *io, RIODesc *fd, ut8 *buf, int count) {
memset (buf, 0xff, count);
ut64 addr = io->off;
- if (!desc) return -1;
+ if (!desc) {
+ return -1;
+ }
return debug_qnx_read_at (buf, count, addr);
}
diff --git a/libr/io/p/io_r2pipe.c b/libr/io/p/io_r2pipe.c
index 903c03976b..2739cb2c70 100644
--- a/libr/io/p/io_r2pipe.c
+++ b/libr/io/p/io_r2pipe.c
@@ -17,8 +17,9 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
char *bufn, bufnum[4096];
int i, rv, rescount = -1;
char *res, *r;
- if (!fd || !fd->data)
+ if (!fd || !fd->data) {
return -1;
+ }
bufn = bufnum;
*bufn = 0;
for (i=0; idata)
+ if (!fd || !fd->data) {
return -1;
+ }
r2p_free (fd->data);
fd->data = NULL;
return 0;
diff --git a/libr/io/p/io_r2web.c b/libr/io/p/io_r2web.c
index dcd6454231..85742abfad 100644
--- a/libr/io/p/io_r2web.c
+++ b/libr/io/p/io_r2web.c
@@ -17,11 +17,16 @@ typedef struct {
static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
int code, rlen;
char *out, *url, *hexbuf;
- if (!fd || !fd->data)
+ if (!fd || !fd->data) {
return -1;
- if (count * 3 < count) return -1;
+ }
+ if (count * 3 < count) {
+ return -1;
+ }
hexbuf = malloc (count * 3);
- if (!hexbuf) return -1;
+ if (!hexbuf) {
+ return -1;
+ }
hexbuf[0] = 0;
r_hex_bin2str (buf, count, hexbuf);
url = r_str_newf ("%s/wx%%20%s@%"PFMT64d,
@@ -37,18 +42,23 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
int code, rlen;
char *out, *url;
int ret = 0;
- if (!fd || !fd->data)
+ if (!fd || !fd->data) {
return -1;
+ }
url = r_str_newf ("%s/p8%%20%d@%"PFMT64d,
rURL(fd), count, io->off);
out = r_socket_http_get (url, &code, &rlen);
if (out && rlen>0) {
ut8 *tmp = malloc (rlen+1);
- if (!tmp) goto beach;
+ if (!tmp) {
+ goto beach;
+ }
ret = r_hex_str2bin (out, tmp);
memcpy (buf, tmp, R_MIN (count, rlen));
free (tmp);
- if (ret<0) ret = -ret;
+ if (ret < 0) {
+ ret = -ret;
+ }
}
beach:
@@ -59,8 +69,9 @@ beach:
static int __close(RIODesc *fd) {
RIOR2Web *riom;
- if (!fd || !fd->data)
+ if (!fd || !fd->data) {
return -1;
+ }
riom = fd->data;
free (riom->url);
riom->url = NULL;
@@ -92,7 +103,9 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
int rlen, code;
if (__plugin_open (io, pathname, 0)) {
RIOR2Web *mal = R_NEW0 (RIOR2Web);
- if (!mal) return NULL;
+ if (!mal) {
+ return NULL;
+ }
char *url = r_str_newf ("http://%s/?V", pathname+8);
//eprintf ("URL:(%s)\n", url);
out = r_socket_http_get (url, &code, &rlen);
diff --git a/libr/io/p/io_rap.c b/libr/io/p/io_rap.c
index d60bcebc57..fac1dd0a10 100644
--- a/libr/io/p/io_rap.c
+++ b/libr/io/p/io_rap.c
@@ -97,7 +97,9 @@ static int rap__close(RIODesc *fd) {
free (fd->data);
fd->data = NULL;
}
- } else eprintf ("rap__close: fdesc is not a r_io_rap plugin\n");
+ } else {
+ eprintf ("rap__close: fdesc is not a r_io_rap plugin\n");
+ }
return ret;
}
@@ -334,7 +336,9 @@ static char *rap__system(RIO *io, RIODesc *fd, const char *command) {
int ir, tr = 0;
do {
ir = r_socket_read_block (s, (ut8*)ptr + tr, i - tr);
- if (ir < 1) break;
+ if (ir < 1) {
+ break;
+ }
tr += ir;
} while (tr < i);
// TODO: use io->cb_printf() with support for \x00
diff --git a/libr/io/p/io_self.c b/libr/io/p/io_self.c
index 3337723230..49e6adadad 100644
--- a/libr/io/p/io_self.c
+++ b/libr/io/p/io_self.c
@@ -73,8 +73,9 @@ static int update_self_regions(RIO *io, int pid) {
char region[100], region2[100], perms[5];
snprintf (path, sizeof (path) - 1, "/proc/%d/maps", pid);
FILE *fd = fopen (path, "r");
- if (!fd)
+ if (!fd) {
return false;
+ }
while (!feof (fd)) {
line[0]='\0';
@@ -129,8 +130,9 @@ static bool __plugin_open(RIO *io, const char *file, bool many) {
static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
int ret, pid = getpid ();
- if (r_sandbox_enable (0))
+ if (r_sandbox_enable (0)) {
return NULL;
+ }
io->va = true; // nop
ret = update_self_regions (io, pid);
if (ret) {
diff --git a/libr/io/p/io_shm.c b/libr/io/p/io_shm.c
index 1f5fa1f808..252f921e22 100644
--- a/libr/io/p/io_shm.c
+++ b/libr/io/p/io_shm.c
@@ -25,8 +25,9 @@ typedef struct {
static int shm__write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
RIOShm *shm;
- if (!fd || !fd->data)
+ if (!fd || !fd->data) {
return -1;
+ }
shm = fd->data;
if (shm->buf != NULL) {
(void)memcpy (shm->buf+io->off, buf, count);
@@ -37,24 +38,28 @@ static int shm__write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
static int shm__read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
RIOShm *shm;
- if (!fd || !fd->data)
+ if (!fd || !fd->data) {
return -1;
+ }
shm = fd->data;
if (io->off+count >= shm->size) {
- if (io->off > shm->size)
+ if (io->off > shm->size) {
return -1;
+ }
count = shm->size - io->off;
}
- if (count>32)
+ if (count > 32) {
count = 32;
+ }
memcpy (buf, shm->buf+io->off , count);
return count;
}
static int shm__close(RIODesc *fd) {
int ret;
- if (!fd || !fd->data)
+ if (!fd || !fd->data) {
return -1;
+ }
ret = shmdt (((RIOShm*)(fd->data))->buf);
free (fd->data);
fd->data = NULL;
@@ -63,15 +68,17 @@ static int shm__close(RIODesc *fd) {
static ut64 shm__lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
RIOShm *shm;
- if (!fd || !fd->data)
+ if (!fd || !fd->data) {
return -1;
+ }
shm = fd->data;
switch (whence) {
case SEEK_SET:
return offset;
case SEEK_CUR:
- if (io->off+offset>shm->size)
+ if (io->off + offset > shm->size) {
return shm->size;
+ }
return io->off + offset;
case SEEK_END:
return 0xffffffff;
@@ -94,7 +101,9 @@ static inline int getshmfd (RIOShm *shm) {
static RIODesc *shm__open(RIO *io, const char *pathname, int rw, int mode) {
if (!strncmp (pathname, "shm://", 6)) {
RIOShm *shm = R_NEW0 (RIOShm);
- if (!shm) return NULL;
+ if (!shm) {
+ return NULL;
+ }
const char *ptr = pathname+6;
shm->id = getshmid (ptr);
shm->buf = shmat (shm->id, 0, 0);
diff --git a/libr/io/p/io_sparse.c b/libr/io/p/io_sparse.c
index ea1a3a986c..2ef61917d6 100644
--- a/libr/io/p/io_sparse.c
+++ b/libr/io/p/io_sparse.c
@@ -20,8 +20,9 @@ typedef struct {
static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
ut64 o;
RBuffer *b;
- if (!fd || !fd->data)
+ if (!fd || !fd->data) {
return -1;
+ }
b = RIOSPARSE_BUF(fd);
o = RIOSPARSE_OFF(fd);
return r_buf_write_at (b, o, buf, count);
@@ -30,8 +31,9 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
ut64 o;
RBuffer *b;
- if (!fd || !fd->data)
+ if (!fd || !fd->data) {
return -1;
+ }
b = RIOSPARSE_BUF(fd);
o = RIOSPARSE_OFF(fd);
(void)r_buf_read_at (b, o, buf, count);
@@ -40,8 +42,9 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
static int __close(RIODesc *fd) {
RIOSparse *riom;
- if (!fd || !fd->data)
+ if (!fd || !fd->data) {
return -1;
+ }
riom = fd->data;
free (riom->buf);
riom->buf = NULL;
@@ -53,8 +56,9 @@ static int __close(RIODesc *fd) {
static ut64 __lseek(RIO* io, RIODesc *fd, ut64 offset, int whence) {
RBuffer *b;
ut64 r_offset = offset;
- if (!fd->data)
+ if (!fd->data) {
return offset;
+ }
b = RIOSPARSE_BUF(fd);
r_offset = r_buf_seek (b, offset, whence);
//if (r_offset != UT64_MAX)
diff --git a/libr/io/p/io_windbg.c b/libr/io/p/io_windbg.c
index 176c473c65..8b6dd86fd9 100644
--- a/libr/io/p/io_windbg.c
+++ b/libr/io/p/io_windbg.c
@@ -83,8 +83,9 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
if (windbg_get_target (fd->data)) {
ut64 va;
- if (!windbg_va_to_pa (fd->data, io->off, &va))
+ if (!windbg_va_to_pa (fd->data, io->off, &va)) {
return -1;
+ }
return windbg_read_at_phys (fd->data, buf, va, count);
}
diff --git a/libr/io/p/io_zip.c b/libr/io/p/io_zip.c
index d4a5c52b8c..9317829abb 100644
--- a/libr/io/p/io_zip.c
+++ b/libr/io/p/io_zip.c
@@ -186,12 +186,15 @@ int r_io_zip_flush_file(RIOZipFileObj *zfo) {
int res = false;
struct zip * zipArch;
- if (!zfo) return res;
+ if (!zfo) {
+ return res;
+ }
zipArch = r_io_zip_open_archive (
zfo->archivename, zfo->flags, zfo->mode, zfo->rw);
- if (!zipArch)
+ if (!zipArch) {
return res;
+ }
struct zip_source *s = zip_source_buffer (zipArch, zfo->b->buf, zfo->b->length, 0);
if (s && zfo->entry != -1) {
@@ -206,12 +209,16 @@ int r_io_zip_flush_file(RIOZipFileObj *zfo) {
}
// s (zip_source) is freed when the archive is closed, i think - dso
zip_close (zipArch);
- if (s) zip_source_free (s);
+ if (s) {
+ zip_source_free (s);
+ }
return res;
}
static void r_io_zip_free_zipfileobj(RIOZipFileObj *zfo) {
- if (!zfo) return;
+ if (!zfo) {
+ return;
+ }
if (zfo->modified) {
r_io_zip_flush_file (zfo);
}
@@ -242,7 +249,9 @@ RIOZipFileObj* r_io_zip_alloc_zipfileobj(const char *archivename, const char *fi
ut64 i, num_entries;
struct zip_stat sb;
struct zip *zipArch = r_io_zip_open_archive (archivename, flags, mode, rw);
- if (!zipArch) return NULL;
+ if (!zipArch) {
+ return NULL;
+ }
num_entries = zip_get_num_files (zipArch);
for (i = 0; i < num_entries; i++) {
@@ -280,7 +289,9 @@ static RList *r_io_zip_open_many(RIO *io, const char *file, int rw, int mode) {
}
zip_uri = strdup (file);
- if (!zip_uri) return NULL;
+ if (!zip_uri) {
+ return NULL;
+ }
// 1) Tokenize to the '//' and find the base file directory ('/')
zip_filename = strstr(zip_uri, "//");
if (zip_filename && zip_filename[2]) {
@@ -305,14 +316,16 @@ static RList *r_io_zip_open_many(RIO *io, const char *file, int rw, int mode) {
r_list_foreach (filenames, iter, filename_in_zipfile) {
size_t v = strlen (filename_in_zipfile);
- if (filename_in_zipfile[v-1] == '/') continue;
+ if (filename_in_zipfile[v - 1] == '/') {
+ continue;
+ }
zfo = r_io_zip_alloc_zipfileobj (zip_filename,
filename_in_zipfile, ZIP_CREATE, mode, rw);
-
- if (zfo && zfo->entry == -1)
+ if (zfo && zfo->entry == -1) {
eprintf ("Warning: File did not exist, creating a new one.\n");
+ }
if (zfo) {
zfo->io_backref = io;
@@ -532,11 +545,13 @@ static ut64 r_io_zip_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
static int r_io_zip_read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
RIOZipFileObj *zfo = NULL;
- if (!fd || !fd->data || !buf)
+ if (!fd || !fd->data || !buf) {
return -1;
+ }
zfo = fd->data;
- if (zfo->b->length < io->off)
+ if (zfo->b->length < io->off) {
io->off = zfo->b->length;
+ }
return r_buf_read_at (zfo->b, io->off, buf, count);
}
diff --git a/libr/io/undo.c b/libr/io/undo.c
index 5e5ef43908..1b8c95c8a3 100644
--- a/libr/io/undo.c
+++ b/libr/io/undo.c
@@ -194,8 +194,9 @@ R_API RList *r_io_sundo_list(RIO *io, int mode) {
R_API void r_io_wundo_new(RIO *io, ut64 off, const ut8 *data, int len) {
RIOUndoWrite *uw;
- if (!io->undo.w_enable)
+ if (!io->undo.w_enable) {
return;
+ }
/* undo write changes */
uw = R_NEW0 (RIOUndoWrite);
if (!uw) {
@@ -237,17 +238,26 @@ R_API void r_io_wundo_list(RIO *io) {
RIOUndoWrite *u;
int i = 0, j, len;
- if (io->undo.w_init)
- r_list_foreach (io->undo.w_list, iter, u) {
- io->cb_printf ("%02d %c %d %08"PFMT64x": ", i, u->set?'+':'-', u->len, u->off);
- len = (u->len>BW)?BW:u->len;
- for (j=0;jcb_printf ("%02x ", u->o[j]);
- if (len == BW) io->cb_printf (".. ");
- io->cb_printf ("=> ");
- for (j=0;jcb_printf ("%02x ", u->n[j]);
- if (len == BW) io->cb_printf (".. ");
- io->cb_printf ("\n");
- i++;
+ if (io->undo.w_init) {
+ r_list_foreach (io->undo.w_list, iter, u) {
+ io->cb_printf ("%02d %c %d %08" PFMT64x ": ", i, u->set ? '+' : '-', u->len, u->off);
+ len = (u->len > BW) ? BW : u->len;
+ for (j = 0; j < len; j++) {
+ io->cb_printf ("%02x ", u->o[j]);
+ }
+ if (len == BW) {
+ io->cb_printf (".. ");
+ }
+ io->cb_printf ("=> ");
+ for (j = 0; j < len; j++) {
+ io->cb_printf ("%02x ", u->n[j]);
+ }
+ if (len == BW) {
+ io->cb_printf (".. ");
+ }
+ io->cb_printf ("\n");
+ i++;
+ }
}
}
diff --git a/libr/lang/lang.c b/libr/lang/lang.c
index 7379fe069b..26a8268af2 100644
--- a/libr/lang/lang.c
+++ b/libr/lang/lang.c
@@ -157,7 +157,9 @@ R_API RLangPlugin *r_lang_get_by_extension (RLang *lang, const char *ext) {
RListIter *iter;
RLangPlugin *h;
const char *p = r_str_lchr (ext, '.');
- if (p) ext = p + 1;
+ if (p) {
+ ext = p + 1;
+ }
r_list_foreach (lang->langs, iter, h) {
if (!r_str_casecmp (h->ext, ext)) {
return h;
@@ -301,14 +303,18 @@ R_API int r_lang_prompt(RLang *lang) {
" . file - interpret file\n"
" q - quit prompt\n");
eprintf ("%s example:\n", lang->cur->name);
- if (lang->cur->help)
+ if (lang->cur->help) {
eprintf ("%s", *lang->cur->help);
- if (!r_list_empty (lang->defs))
+ }
+ if (!r_list_empty (lang->defs)) {
eprintf ("variables:\n");
+ }
r_list_foreach (lang->defs, iter, def) {
eprintf (" %s %s\n", def->type, def->name);
}
- } else r_lang_run (lang, buf, strlen (buf));
+ } else {
+ r_lang_run (lang, buf, strlen (buf));
+ }
}
// XXX: leaking history
r_line_set_prompt (prompt);
diff --git a/libr/magic/apprentice.c b/libr/magic/apprentice.c
index 9ebe8666dd..da7ed84558 100644
--- a/libr/magic/apprentice.c
+++ b/libr/magic/apprentice.c
@@ -153,7 +153,9 @@ static int get_type(const char *l, const char **t) {
for (p = type_tbl; p->len; p++) {
if (strncmp (l, p->name, p->len) == 0) {
- if (t) *t = l + p->len;
+ if (t) {
+ *t = l + p->len;
+ }
break;
}
}
@@ -186,7 +188,9 @@ static int apprentice_1(RMagic *ms, const char *fn, int action, struct mlist *ml
int rv = -1;
int mapped;
- if (!ms) return -1;
+ if (!ms) {
+ return -1;
+ }
ms->haderr = 0;
if (magicsize != FILE_MAGICSIZE) {
file_error(ms, 0, "magic element size %lu != %lu",
@@ -198,8 +202,9 @@ static int apprentice_1(RMagic *ms, const char *fn, int action, struct mlist *ml
ms->file = fn; // fix use of ms->file before being initialized
if (action == FILE_COMPILE) {
rv = apprentice_load (ms, &magic, &nmagic, fn, action);
- if (rv != 0)
+ if (rv != 0) {
return -1;
+ }
rv = apprentice_compile (ms, &magic, &nmagic, fn);
free (magic);
return rv;
@@ -209,8 +214,9 @@ static int apprentice_1(RMagic *ms, const char *fn, int action, struct mlist *ml
//if (ms->flags & R_MAGIC_CHECK)
// file_magwarn(ms, "using regular magic file `%s'", fn);
rv = apprentice_load (ms, &magic, &nmagic, fn, action);
- if (rv != 0)
+ if (rv != 0) {
return -1;
+ }
}
mapped = rv;
@@ -238,8 +244,8 @@ static int apprentice_1(RMagic *ms, const char *fn, int action, struct mlist *ml
}
void file_delmagic(struct r_magic *p, int type, size_t entries) {
- if (p)
- switch (type) {
+ if (p) {
+ switch (type) {
#ifdef QUICK
case 2:
p--;
@@ -256,6 +262,7 @@ void file_delmagic(struct r_magic *p, int type, size_t entries) {
default:
abort ();
}
+ }
}
/* const char *fn: list of magic files and directories */
@@ -266,8 +273,12 @@ struct mlist * file_apprentice(RMagic *ms, const char *fn, int action) {
init_file_tables ();
- if (!fn) fn = getenv ("MAGIC");
- if (!fn) fn = MAGICFILE;
+ if (!fn) {
+ fn = getenv ("MAGIC");
+ }
+ if (!fn) {
+ fn = MAGICFILE;
+ }
if (!(mfn = strdup (fn))) {
file_oomem (ms, strlen (fn));
@@ -284,8 +295,12 @@ struct mlist * file_apprentice(RMagic *ms, const char *fn, int action) {
while (fn) {
p = strchr (fn, PATHSEP);
- if (p) *p++ = '\0';
- if (*fn == '\0') break;
+ if (p) {
+ *p++ = '\0';
+ }
+ if (*fn == '\0') {
+ break;
+ }
file_err = apprentice_1 (ms, fn, action, mlist);
errs = R_MAX (errs, file_err);
fn = p;
@@ -401,8 +416,12 @@ static int apprentice_sort(const void *a, const void *b) {
const struct r_magic_entry *mb = b;
size_t sa = apprentice_r_magic_strength (ma->mp);
size_t sb = apprentice_r_magic_strength (mb->mp);
- if (sa == sb) return 0;
- if (sa > sb) return -1;
+ if (sa == sb) {
+ return 0;
+ }
+ if (sa > sb) {
+ return -1;
+ }
return 1;
}
@@ -449,8 +468,9 @@ static void set_test_type(struct r_magic *mstart, struct r_magic *m) {
case FILE_REGEX:
case FILE_SEARCH:
/* binary test if pattern is not text */
- if (file_looks_utf8 ((const ut8 *)m->value.s, m->vallen, NULL, NULL) == 0)
+ if (file_looks_utf8 ((const ut8 *)m->value.s, m->vallen, NULL, NULL) == 0) {
mstart->flag |= BINTEST;
+ }
break;
case FILE_DEFAULT:
/* can't deduce anything; we shouldn't see this at the
@@ -471,33 +491,39 @@ static void load_1(RMagic *ms, int action, const char *file, int *errs, struct r
size_t lineno = 0;
FILE *f = r_sandbox_fopen (ms->file = file, "r");
if (!f) {
- if (errno != ENOENT)
+ if (errno != ENOENT) {
file_error (ms, errno, "cannot read magic file `%s'", file);
+ }
(*errs)++;
} else {
/* read and parse this file */
for (ms->line = 1; fgets (line, sizeof (line), f) != NULL; ms->line++) {
size_t len = strlen (line);
- if (len == 0) /* null line, garbage, etc */
+ if (len == 0) { /* null line, garbage, etc */
continue;
+ }
if (line[len - 1] == '\n') {
lineno++;
line[len - 1] = '\0'; /* delete newline */
}
- if (line[0] == '\0') /* empty, do not parse */
+ if (line[0] == '\0') { /* empty, do not parse */
continue;
- if (line[0] == '#') /* comment, do not parse */
+ }
+ if (line[0] == '#') { /* comment, do not parse */
continue;
+ }
if (len > mime_marker_len &&
memcmp (line, mime_marker, mime_marker_len) == 0) {
/* MIME type */
if (parse_mime (ms, marray, marraycount,
- line + mime_marker_len) != 0)
+ line + mime_marker_len) != 0) {
(*errs)++;
+ }
continue;
}
- if (parse (ms, marray, marraycount, line, lineno, action) != 0)
+ if (parse (ms, marray, marraycount, line, lineno, action) != 0) {
(*errs)++;
+ }
}
fclose (f);
}
@@ -534,8 +560,9 @@ static int apprentice_load(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, c
marraycount = 0;
/* print silly verbose header for USG compat. */
- if (action == FILE_CHECK)
+ if (action == FILE_CHECK) {
eprintf ("%s\n", usg_hdr);
+ }
/* load directory or file */
if (stat (fn, &st) == 0 && S_ISDIR (st.st_mode)) {
@@ -568,10 +595,13 @@ static int apprentice_load(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, c
dir = opendir (fn);
if (dir) {
while ((d = readdir (dir))) {
- if (*d->d_name=='.') continue;
+ if (*d->d_name == '.') {
+ continue;
+ }
snprintf (subfn, sizeof (subfn), "%s/%s", fn, d->d_name);
- if (stat (subfn, &st) == 0 && S_ISREG (st.st_mode))
+ if (stat (subfn, &st) == 0 && S_ISREG (st.st_mode)) {
load_1 (ms, action, subfn, &errs, &marray, &marraycount);
+ }
//else perror (subfn);
}
closedir (dir);
@@ -579,9 +609,12 @@ static int apprentice_load(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, c
errs++;
}
#endif
- } else load_1 (ms, action, fn, &errs, &marray, &marraycount);
- if (errs)
+ } else {
+ load_1 (ms, action, fn, &errs, &marray, &marraycount);
+ }
+ if (errs) {
goto out;
+ }
/* Set types of tests */
for (i = 0; i < marraycount; ) {
@@ -624,9 +657,11 @@ static int apprentice_load(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, c
for (i = 0; i < marraycount; i++) {
if (marray[i].mp->cont_level == 0 &&
marray[i].mp->type == FILE_DEFAULT) {
- while (++i < marraycount)
- if (marray[i].mp->cont_level == 0)
+ while (++i < marraycount) {
+ if (marray[i].mp->cont_level == 0) {
break;
+ }
+ }
if (i != marraycount) {
ms->line = marray[i].mp->lineno; /* XXX - Ugh! */
file_magwarn (ms, "level 0 \"default\" did not sort last");
@@ -635,8 +670,9 @@ static int apprentice_load(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, c
}
}
- for (i = 0; i < marraycount; i++)
+ for (i = 0; i < marraycount; i++) {
mentrycount += marray[i].cont_count;
+ }
if (!(*magicp = malloc (1 + (sizeof (**magicp) * mentrycount)))) {
file_oomem (ms, sizeof (**magicp) * mentrycount);
@@ -651,8 +687,9 @@ static int apprentice_load(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, c
mentrycount += marray[i].cont_count;
}
out:
- for (i = 0; i < marraycount; i++)
- free(marray[i].mp);
+ for (i = 0; i < marraycount; i++) {
+ free (marray[i].mp);
+ }
free (marray);
if (errs) {
*magicp = NULL;
@@ -722,9 +759,10 @@ ut64 file_signextend(RMagic *ms, struct r_magic *m, ut64 v) {
case FILE_DEFAULT:
break;
default:
- if (ms->flags & R_MAGIC_CHECK)
- file_magwarn(ms, "cannot happen: m->type=%d\n",
- m->type);
+ if (ms->flags & R_MAGIC_CHECK) {
+ file_magwarn (ms, "cannot happen: m->type=%d\n",
+ m->type);
+ }
return ~0U;
}
}
@@ -732,8 +770,9 @@ ut64 file_signextend(RMagic *ms, struct r_magic *m, ut64 v) {
}
static int string_modifier_check(RMagic *ms, struct r_magic *m) {
- if ((ms->flags & R_MAGIC_CHECK) == 0)
+ if ((ms->flags & R_MAGIC_CHECK) == 0) {
return 0;
+ }
switch (m->type) {
case FILE_BESTRING16:
@@ -812,7 +851,9 @@ static int get_cond(const char *l, const char **t) {
for (p = cond_tbl; p->len; p++) {
if (strncmp (l, p->name, p->len) == 0 &&
isspace ((ut8)l[p->len])) {
- if (t) *t = l + p->len;
+ if (t) {
+ *t = l + p->len;
+ }
break;
}
}
@@ -826,24 +867,27 @@ static int check_cond(RMagic *ms, int cond, ut32 cont_level) {
switch (cond) {
case COND_IF:
if (last_cond != COND_NONE && last_cond != COND_ELIF) {
- if (ms->flags & R_MAGIC_CHECK)
- file_magwarn(ms, "syntax error: `if'");
+ if (ms->flags & R_MAGIC_CHECK) {
+ file_magwarn (ms, "syntax error: `if'");
+ }
return -1;
}
last_cond = COND_IF;
break;
case COND_ELIF:
if (last_cond != COND_IF && last_cond != COND_ELIF) {
- if (ms->flags & R_MAGIC_CHECK)
- file_magwarn(ms, "syntax error: `elif'");
+ if (ms->flags & R_MAGIC_CHECK) {
+ file_magwarn (ms, "syntax error: `elif'");
+ }
return -1;
}
last_cond = COND_ELIF;
break;
case COND_ELSE:
if (last_cond != COND_IF && last_cond != COND_ELIF) {
- if (ms->flags & R_MAGIC_CHECK)
- file_magwarn(ms, "syntax error: `else'");
+ if (ms->flags & R_MAGIC_CHECK) {
+ file_magwarn (ms, "syntax error: `else'");
+ }
return -1;
}
last_cond = COND_NONE;
@@ -870,10 +914,14 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
int op;
ut32 cont_level = 0;
- for (; *l == '>'; l++, cont_level++);
- if (cont_level == 0 || cont_level > last_cont_level)
- if (file_check_mem (ms, cont_level) == -1)
+ for (; *l == '>'; l++, cont_level++) {
+ ;
+ }
+ if (cont_level == 0 || cont_level > last_cont_level) {
+ if (file_check_mem (ms, cont_level) == -1) {
return -1;
+ }
+ }
last_cont_level = cont_level;
#define ALLOC_CHUNK (size_t)10
#define ALLOC_INCR (size_t)200
@@ -917,8 +965,9 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
}
me->mp = m;
me->max_count = ALLOC_CHUNK;
- } else
+ } else {
m = me->mp;
+ }
(void)memset(m, 0, sizeof (*m));
m->cont_level = 0;
me->cont_count = 1;
@@ -932,8 +981,9 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
if (*l == '(') {
++l; /* step over */
m->flag |= INDIR;
- if (m->flag & OFFADD)
+ if (m->flag & OFFADD) {
m->flag = (m->flag & ~OFFADD) | INDIROFFADD;
+ }
if (*l == '&') { /* m->cont_level == 0 checked below */
++l; /* step over */
@@ -941,15 +991,18 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
}
}
/* Indirect offsets are not valid at level 0. */
- if (m->cont_level == 0 && (m->flag & (OFFADD | INDIROFFADD)))
- if (ms->flags & R_MAGIC_CHECK)
- file_magwarn(ms, "relative offset at level 0");
+ if (m->cont_level == 0 && (m->flag & (OFFADD | INDIROFFADD))) {
+ if (ms->flags & R_MAGIC_CHECK) {
+ file_magwarn (ms, "relative offset at level 0");
+ }
+ }
/* get offset, then skip over it */
m->offset = (ut32)strtoul(l, &t, 0);
- if ((l == t) && (ms->flags & R_MAGIC_CHECK))
- file_magwarn(ms, "offset `%s' invalid", l);
- l = t;
+ if ((l == t) && (ms->flags & R_MAGIC_CHECK)) {
+ file_magwarn (ms, "offset `%s' invalid", l);
+ }
+ l = t;
if (m->flag & INDIR) {
m->in_type = FILE_LONG;
@@ -994,10 +1047,11 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
m->in_type = FILE_BEDOUBLE;
break;
default:
- if (ms->flags & R_MAGIC_CHECK)
- file_magwarn(ms,
- "indirect offset type `%c' invalid",
- *l);
+ if (ms->flags & R_MAGIC_CHECK) {
+ file_magwarn (ms,
+ "indirect offset type `%c' invalid",
+ *l);
+ }
break;
}
l++;
@@ -1018,23 +1072,28 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
}
if (isdigit((ut8)*l) || *l == '-') {
m->in_offset = (int32_t)strtol(l, &t, 0);
- if (l == t)
- if (ms->flags & R_MAGIC_CHECK)
- file_magwarn(ms,
- "in_offset `%s' invalid", l);
+ if (l == t) {
+ if (ms->flags & R_MAGIC_CHECK) {
+ file_magwarn (ms,
+ "in_offset `%s' invalid", l);
+ }
+ }
l = t;
}
if (*l++ != ')' ||
- ((m->in_op & FILE_OPINDIRECT) && *l++ != ')'))
- if (ms->flags & R_MAGIC_CHECK)
- file_magwarn(ms,
- "missing ')' in indirect offset");
+ ((m->in_op & FILE_OPINDIRECT) && *l++ != ')')) {
+ if (ms->flags & R_MAGIC_CHECK) {
+ file_magwarn (ms,
+ "missing ')' in indirect offset");
+ }
+ }
}
EATAB;
m->cond = get_cond(l, &l);
- if (check_cond(ms, m->cond, cont_level) == -1)
+ if (check_cond (ms, m->cond, cont_level) == -1) {
return -1;
+ }
EATAB;
if (*l == 'u') {
@@ -1044,8 +1103,9 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
m->type = get_type(l, &l);
if (m->type == FILE_INVALID) {
- if (ms->flags & R_MAGIC_CHECK)
- file_magwarn(ms, "type `%s' invalid", l);
+ if (ms->flags & R_MAGIC_CHECK) {
+ file_magwarn (ms, "type `%s' invalid", l);
+ }
return -1;
}
@@ -1054,10 +1114,11 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
m->mask_op = 0;
if (*l == '~') {
- if (!MAGIC_IS_STRING (m->type))
+ if (!MAGIC_IS_STRING (m->type)) {
m->mask_op |= FILE_OPINVERSE;
- else if (ms->flags & R_MAGIC_CHECK)
+ } else if (ms->flags & R_MAGIC_CHECK) {
file_magwarn (ms, "'~' invalid for string types");
+ }
++l;
}
m->str_range = 0;
@@ -1082,14 +1143,16 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
case '6': case '7': case '8':
case '9':
if (have_range &&
- (ms->flags & R_MAGIC_CHECK))
- file_magwarn(ms,
- "multiple ranges");
+ (ms->flags & R_MAGIC_CHECK)) {
+ file_magwarn (ms,
+ "multiple ranges");
+ }
have_range = 1;
m->str_range = strtoul(l, &t, 0);
- if (m->str_range == 0)
- file_magwarn(ms,
- "zero range");
+ if (m->str_range == 0) {
+ file_magwarn (ms,
+ "zero range");
+ }
l = t - 1;
break;
case CHAR_COMPACT_BLANK:
@@ -1109,21 +1172,25 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
m->str_flags |= REGEX_OFFSET_START;
break;
default:
- if (ms->flags & R_MAGIC_CHECK)
- file_magwarn(ms,
- "string extension `%c' invalid",
- *l);
+ if (ms->flags & R_MAGIC_CHECK) {
+ file_magwarn (ms,
+ "string extension `%c' invalid",
+ *l);
+ }
return -1;
}
/* allow multiple '/' for readability */
- if (l[1] == '/' && !isspace ((ut8)l[2]))
+ if (l[1] == '/' && !isspace ((ut8)l[2])) {
l++;
+ }
}
- if (string_modifier_check(ms, m) == -1)
+ if (string_modifier_check (ms, m) == -1) {
return -1;
+ }
} else {
- if (ms->flags & R_MAGIC_CHECK)
- file_magwarn(ms, "invalid string op: %c", *t);
+ if (ms->flags & R_MAGIC_CHECK) {
+ file_magwarn (ms, "invalid string op: %c", *t);
+ }
return -1;
}
}
@@ -1163,8 +1230,9 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
/*
* Grab the value part, except for an 'x' reln.
*/
- if (m->reln != 'x' && getvalue (ms, m, &l, action))
+ if (m->reln != 'x' && getvalue (ms, m, &l, action)) {
return -1;
+ }
/*
* TODO finish this macro and start using it!
@@ -1184,26 +1252,32 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con
++l;
m->flag |= NOSPACE;
}
- for (i = 0; (m->desc[i++] = *l++) != '\0' && i < sizeof (m->desc); )
+ for (i = 0; (m->desc[i++] = *l++) != '\0' && i < sizeof (m->desc);) {
continue;
+ }
if (i == sizeof (m->desc)) {
m->desc[sizeof (m->desc) - 1] = '\0';
- if (ms->flags & R_MAGIC_CHECK)
- file_magwarn(ms, "description `%s' truncated", m->desc);
+ if (ms->flags & R_MAGIC_CHECK) {
+ file_magwarn (ms, "description `%s' truncated", m->desc);
+ }
}
/*
* We only do this check while compiling, or if any of the magic
* files were not compiled.
*/
- if (ms->flags & R_MAGIC_CHECK)
- if (check_format (ms, m) == -1)
+ if (ms->flags & R_MAGIC_CHECK) {
+ if (check_format (ms, m) == -1) {
return -1;
- if (action == FILE_CHECK)
+ }
+ }
+ if (action == FILE_CHECK) {
file_mdump (m);
+ }
m->mimetype[0] = '\0'; /* initialise MIME type to none */
- if (m->cont_level == 0)
- ++(*nmentryp); /* make room for next */
+ if (m->cont_level == 0) {
+ ++(*nmentryp); /* make room for next */
+ }
return 0;
}
@@ -1233,16 +1307,19 @@ static int parse_mime(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp
EATAB;
for (i = 0;
- *l && ((isascii((ut8)*l) && isalnum((ut8)*l))
- || strchr("-+/.", *l)) && i < sizeof (m->mimetype);
- m->mimetype[i++] = *l++)
+ *l && ((isascii ((ut8)*l) && isalnum ((ut8)*l)) || strchr ("-+/.", *l)) && i < sizeof (m->mimetype);
+ m->mimetype[i++] = *l++) {
continue;
+ }
if (i == sizeof (m->mimetype)) {
m->desc[sizeof (m->mimetype) - 1] = '\0';
- if (ms->flags & R_MAGIC_CHECK)
- file_magwarn(ms, "MIME type `%s' truncated %zu",
- m->mimetype, i);
- } else m->mimetype[i] = '\0';
+ if (ms->flags & R_MAGIC_CHECK) {
+ file_magwarn (ms, "MIME type `%s' truncated %zu",
+ m->mimetype, i);
+ }
+ } else {
+ m->mimetype[i] = '\0';
+ }
return (i>0)? 0: -1;
}
@@ -1259,17 +1336,28 @@ static int check_format_type(const char *ptr, int type) {
quad = 1;
/*FALLTHROUGH*/
case FILE_FMT_NUM:
- if (*ptr == '-')
+ if (*ptr == '-') {
ptr++;
- if (*ptr == '.')
+ }
+ if (*ptr == '.') {
ptr++;
- while (isdigit((ut8)*ptr)) ptr++;
- if (*ptr == '.')
+ }
+ while (isdigit ((ut8)*ptr)) {
ptr++;
- while (isdigit((ut8)*ptr)) ptr++;
+ }
+ if (*ptr == '.') {
+ ptr++;
+ }
+ while (isdigit ((ut8)*ptr)) {
+ ptr++;
+ }
if (quad) {
- if (*ptr++ != 'l') return -1;
- if (*ptr++ != 'l') return -1;
+ if (*ptr++ != 'l') {
+ return -1;
+ }
+ if (*ptr++ != 'l') {
+ return -1;
+ }
}
switch (*ptr++) {
case 'l':
@@ -1313,14 +1401,21 @@ static int check_format_type(const char *ptr, int type) {
}
case FILE_FMT_FLOAT:
case FILE_FMT_DOUBLE:
- if (*ptr == '-')
+ if (*ptr == '-') {
ptr++;
- if (*ptr == '.')
+ }
+ if (*ptr == '.') {
ptr++;
- while (isdigit ((ut8)*ptr)) ptr++;
- if (*ptr == '.')
+ }
+ while (isdigit ((ut8)*ptr)) {
ptr++;
- while (isdigit ((ut8)*ptr)) ptr++;
+ }
+ if (*ptr == '.') {
+ ptr++;
+ }
+ while (isdigit ((ut8)*ptr)) {
+ ptr++;
+ }
switch (*ptr++) {
case 'e':
@@ -1335,18 +1430,22 @@ static int check_format_type(const char *ptr, int type) {
return -1;
}
case FILE_FMT_STR:
- if (*ptr == '-')
+ if (*ptr == '-') {
ptr++;
- while (isdigit ((ut8 )*ptr))
+ }
+ while (isdigit ((ut8)*ptr)) {
ptr++;
+ }
if (*ptr == '.') {
ptr++;
- while (isdigit ((ut8 )*ptr))
+ while (isdigit ((ut8)*ptr)) {
ptr++;
+ }
}
- if (*ptr++=='s')
+ if (*ptr++ == 's') {
return 0;
+ }
return -1;
default:
/* internal error */
@@ -1363,9 +1462,11 @@ static int check_format_type(const char *ptr, int type) {
static int check_format(RMagic *ms, struct r_magic *m) {
char *ptr;
- for (ptr = m->desc; *ptr; ptr++)
- if (*ptr == '%')
+ for (ptr = m->desc; *ptr; ptr++) {
+ if (*ptr == '%') {
break;
+ }
+ }
if (*ptr == '\0') {
/* No format string; ok */
return 1;
@@ -1428,14 +1529,16 @@ static int getvalue(RMagic *ms, struct r_magic *m, const char **p, int action) {
case FILE_SEARCH:
*p = getstr(ms, *p, m->value.s, sizeof (m->value.s), &slen, action);
if (!*p) {
- if (ms->flags & R_MAGIC_CHECK)
- file_magwarn(ms, "cannot get string from `%s'",
- m->value.s);
+ if (ms->flags & R_MAGIC_CHECK) {
+ file_magwarn (ms, "cannot get string from `%s'",
+ m->value.s);
+ }
return -1;
}
m->vallen = slen;
- if (m->type == FILE_PSTRING)
+ if (m->type == FILE_PSTRING) {
m->vallen++;
+ }
return 0;
case FILE_FLOAT:
case FILE_BEFLOAT:
@@ -1484,8 +1587,9 @@ static const char * getstr(RMagic *ms, const char *s, char *p, int plen, int *sl
int c, val;
while ((c = *s++) != '\0') {
- if (isspace ((ut8) c))
+ if (isspace ((ut8)c)) {
break;
+ }
if (p >= pmax) {
file_error(ms, 0, "string too long: `%s'", origs);
return NULL;
@@ -1493,8 +1597,9 @@ static const char * getstr(RMagic *ms, const char *s, char *p, int plen, int *sl
if (c == '\\') {
switch ((c = *s++)) {
case '\0':
- if (action == FILE_COMPILE)
- file_magwarn(ms, "incomplete escape");
+ if (action == FILE_COMPILE) {
+ file_magwarn (ms, "incomplete escape");
+ }
goto out;
case '\t':
if (action == FILE_COMPILE) {
@@ -1505,12 +1610,13 @@ static const char * getstr(RMagic *ms, const char *s, char *p, int plen, int *sl
/*FALLTHROUGH*/
default:
if (action == FILE_COMPILE) {
- if (isprint((ut8)c))
- file_magwarn(ms,
- "no need to escape `%c'", c);
- else
- file_magwarn(ms,
- "unknown escape sequence: \\%03o", c);
+ if (isprint ((ut8)c)) {
+ file_magwarn (ms,
+ "no need to escape `%c'", c);
+ } else {
+ file_magwarn (ms,
+ "unknown escape sequence: \\%03o", c);
+ }
}
/*FALLTHROUGH*/
/* space, perhaps force people to use \040? */
@@ -1556,10 +1662,14 @@ static const char * getstr(RMagic *ms, const char *s, char *p, int plen, int *sl
if (c >= '0' && c <= '7') {
val = (val << 3) | (c - '0');
c = *s++; /* try for 3 */
- if (c >= '0' && c <= '7')
+ if (c >= '0' && c <= '7') {
val = (val << 3) | (c-'0');
- else --s;
- } else --s;
+ } else {
+ --s;
+ }
+ } else {
+ --s;
+ }
*p++ = (char)val;
break;
@@ -1570,14 +1680,20 @@ static const char * getstr(RMagic *ms, const char *s, char *p, int plen, int *sl
if (c >= 0) {
val = c;
c = hextoint(*s++);
- if (c >= 0)
+ if (c >= 0) {
val = (val << 4) + c;
- else --s;
- } else --s;
+ } else {
+ --s;
+ }
+ } else {
+ --s;
+ }
*p++ = (char)val;
break;
}
- } else *p++ = (char)c;
+ } else {
+ *p++ = (char)c;
+ }
}
out:
*p = '\0';
@@ -1588,14 +1704,18 @@ out:
/* Single hex char to int; -1 if not a hex char. */
static int hextoint(int c) {
- if (!isascii ((ut8) c))
+ if (!isascii ((ut8)c)) {
return -1;
- if (isdigit ((ut8) c))
+ }
+ if (isdigit ((ut8)c)) {
return c - '0';
- if ((c >= 'a') && (c <= 'f'))
+ }
+ if ((c >= 'a') && (c <= 'f')) {
return c + 10 - 'a';
- if (( c>= 'A') && (c <= 'F'))
+ }
+ if ((c >= 'A') && (c <= 'F')) {
return c + 10 - 'A';
+ }
return -1;
}
@@ -1607,15 +1727,17 @@ void file_showstr(FILE *fp, const char *s, size_t len) {
for (;;) {
char c = *s++;
if (len == ~0U) {
- if (c == '\0')
+ if (c == '\0') {
break;
+ }
} else {
- if (len-- == 0)
+ if (len-- == 0) {
break;
+ }
}
- if (c >= 040 && c <= 0176) /* TODO isprint && !iscntrl */
+ if (c >= 040 && c <= 0176) { /* TODO isprint && !iscntrl */
fputc (c, fp);
- else {
+ } else {
fputc ('\\', fp);
switch (c) {
case '\a': fputc('a', fp); break;
@@ -1637,8 +1759,9 @@ void file_showstr(FILE *fp, const char *s, size_t len) {
static void eatsize(const char **p) {
const char *l = *p;
- if (LOWCASE (*l) == 'u')
+ if (LOWCASE (*l) == 'u') {
l++;
+ }
switch (LOWCASE (*l)) {
case 'l': /* long */
@@ -1668,11 +1791,13 @@ static int apprentice_map(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, co
void *mm = NULL;
dbname = mkdbname (fn, 0);
- if (!dbname)
+ if (!dbname) {
goto error2;
+ }
- if ((fd = r_sandbox_open (dbname, O_RDONLY|O_BINARY, 0)) == -1)
+ if ((fd = r_sandbox_open (dbname, O_RDONLY | O_BINARY, 0)) == -1) {
goto error2;
+ }
if (fstat(fd, &st) == -1) {
file_error (ms, errno, "cannot stat `%s'", dbname);
@@ -1713,7 +1838,9 @@ static int apprentice_map(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, co
goto error1;
}
needsbyteswap = 1;
- } else needsbyteswap = 0;
+ } else {
+ needsbyteswap = 0;
+ }
version = needsbyteswap? swap4(ptr[1]): ptr[1];
if (version != VERSIONNO) {
@@ -1723,17 +1850,20 @@ static int apprentice_map(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, co
goto error1;
}
*nmagicp = (ut32)(st.st_size / sizeof (struct r_magic));
- if (*nmagicp > 0)
+ if (*nmagicp > 0) {
(*nmagicp)--;
+ }
(*magicp)++;
- if (needsbyteswap)
+ if (needsbyteswap) {
byteswap (*magicp, *nmagicp);
+ }
free (dbname);
return RET;
error1:
- if (fd != -1)
+ if (fd != -1) {
(void)close (fd);
+ }
if (mm) {
#ifdef QUICK
(void)munmap((void *)mm, (size_t)st.st_size);
@@ -1763,8 +1893,9 @@ static int apprentice_compile(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp
dbname = mkdbname(fn, 1);
- if (!dbname)
+ if (!dbname) {
goto out;
+ }
if ((fd = r_sandbox_open(dbname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644)) == -1) {
file_error(ms, errno, "cannot open `%s'", dbname);
@@ -1805,8 +1936,9 @@ static char *mkdbname(const char *fn, int strip) {
int fnlen, extlen;
if (strip) {
const char *p;
- if ((p = strrchr(fn, '/')) != NULL)
+ if ((p = strrchr (fn, '/')) != NULL) {
fn = ++p;
+ }
}
fnlen = strlen (fn);
extlen = strlen (ext);
@@ -1827,8 +1959,9 @@ static char *mkdbname(const char *fn, int strip) {
*/
static void byteswap(struct r_magic *magic, ut32 nmagic) {
ut32 i;
- for (i = 0; i < nmagic; i++)
+ for (i = 0; i < nmagic; i++) {
bs1 (&magic[i]);
+ }
}
/*
diff --git a/libr/magic/ascmagic.c b/libr/magic/ascmagic.c
index 6f27192c69..f8be96dc1c 100644
--- a/libr/magic/ascmagic.c
+++ b/libr/magic/ascmagic.c
@@ -98,13 +98,16 @@ return 0;
* Undo the NUL-termination kindly provided by process()
* but leave at least one byte to look at
*/
- while (nbytes > 1 && buf[nbytes - 1] == '\0')
+ while (nbytes > 1 && buf[nbytes - 1] == '\0') {
nbytes--;
+ }
- if (!(nbuf = calloc(1, (nbytes + 1) * sizeof(nbuf[0]))))
+ if (!(nbuf = calloc (1, (nbytes + 1) * sizeof (nbuf[0])))) {
goto done;
- if (!(ubuf = calloc(1, (nbytes + 1) * sizeof(ubuf[0]))))
+ }
+ if (!(ubuf = calloc (1, (nbytes + 1) * sizeof (ubuf[0])))) {
goto done;
+ }
/*
* Then try to determine whether it's any character code we can
@@ -125,10 +128,11 @@ return 0;
code_mime = "utf-8";
type = "text";
} else if ((i = looks_ucs16(buf, nbytes, ubuf, &ulen)) != 0) {
- if (i == 1)
+ if (i == 1) {
code = "Little-endian UTF-16 Unicode";
- else
+ } else {
code = "Big-endian UTF-16 Unicode";
+ }
type = "character data";
code_mime = "utf-16"; /* is this defined? */
@@ -177,31 +181,37 @@ return 0;
file_oomem(ms, mlen);
goto done;
}
- if (!(utf8_end = encode_utf8(utf8_buf, mlen, ubuf, ulen)))
+ if (!(utf8_end = encode_utf8 (utf8_buf, mlen, ubuf, ulen))) {
goto done;
+ }
if (file_softmagic(ms, utf8_buf, utf8_end - utf8_buf, TEXTTEST) != 0) {
rv = 1;
goto done;
}
/* look for tokens from names.h - this is expensive! */
- if ((ms->flags & R_MAGIC_NO_CHECK_TOKENS) != 0)
+ if ((ms->flags & R_MAGIC_NO_CHECK_TOKENS) != 0) {
goto subtype_identified;
+ }
i = 0;
while (i < ulen) {
size_t end;
/* skip past any leading space */
- while (i < ulen && ISSPC(ubuf[i]))
+ while (i < ulen && ISSPC (ubuf[i])) {
i++;
- if (i >= ulen)
+ }
+ if (i >= ulen) {
break;
+ }
/* find the next whitespace */
- for (end = i + 1; end < nbytes; end++)
- if (ISSPC(ubuf[end]))
+ for (end = i + 1; end < nbytes; end++) {
+ if (ISSPC (ubuf[end])) {
break;
+ }
+ }
/* compare the word thus isolated against the token list */
for (p = names; p < names + NNAMES; p++) {
@@ -221,82 +231,101 @@ subtype_identified:
/* Now try to discover other details about the file. */
for (i = 0; i < ulen; i++) {
if (ubuf[i] == '\n') {
- if (seen_cr)
+ if (seen_cr) {
n_crlf++;
- else
+ } else {
n_lf++;
+ }
last_line_end = i;
- } else if (seen_cr)
+ } else if (seen_cr) {
n_cr++;
+ }
seen_cr = (ubuf[i] == '\r');
- if (seen_cr)
+ if (seen_cr) {
last_line_end = i;
+ }
if (ubuf[i] == 0x85) { /* X3.64/ECMA-43 "next line" character */
n_nel++;
last_line_end = i;
}
/* If this line is _longer_ than MAXLINELEN, remember it. */
- if (i > last_line_end + MAXLINELEN)
+ if (i > last_line_end + MAXLINELEN) {
has_long_lines = 1;
+ }
- if (ubuf[i] == '\033')
+ if (ubuf[i] == '\033') {
has_escapes = 1;
- if (ubuf[i] == '\b')
+ }
+ if (ubuf[i] == '\b') {
has_backspace = 1;
+ }
}
/* Beware, if the data has been truncated, the final CR could have
been followed by a LF. If we have HOWMANY bytes, it indicates
that the data might have been truncated, probably even before
this function was called. */
- if (seen_cr && nbytes < HOWMANY)
+ if (seen_cr && nbytes < HOWMANY) {
n_cr++;
+ }
if (mime) {
if (mime & R_MAGIC_MIME_TYPE) {
if (subtype_mime) {
- if (file_printf(ms, subtype_mime) == -1)
+ if (file_printf (ms, subtype_mime) == -1) {
goto done;
+ }
} else {
- if (file_printf(ms, "text/plain") == -1)
+ if (file_printf (ms, "text/plain") == -1) {
goto done;
+ }
}
}
if ((mime == 0 || mime == R_MAGIC_MIME) && code_mime) {
if ((mime & R_MAGIC_MIME_TYPE) &&
- file_printf(ms, " charset=") == -1)
+ file_printf (ms, " charset=") == -1) {
goto done;
- if (file_printf(ms, code_mime) == -1)
+ }
+ if (file_printf (ms, code_mime) == -1) {
goto done;
+ }
}
- if (mime == R_MAGIC_MIME_ENCODING)
- if (file_printf(ms, "binary") == -1){
- rv = 1;
- goto done;
- }
+ if (mime == R_MAGIC_MIME_ENCODING) {
+ if (file_printf (ms, "binary") == -1) {
+ rv = 1;
+ goto done;
+ }
+ }
} else {
- if (file_printf(ms, code) == -1)
+ if (file_printf (ms, code) == -1) {
goto done;
+ }
if (subtype) {
- if (file_printf(ms, " ") == -1)
+ if (file_printf (ms, " ") == -1) {
goto done;
- if (file_printf(ms, subtype) == -1)
+ }
+ if (file_printf (ms, subtype) == -1) {
goto done;
+ }
}
- if (file_printf(ms, " ") == -1)
+ if (file_printf (ms, " ") == -1) {
goto done;
- if (file_printf(ms, type) == -1)
+ }
+ if (file_printf (ms, type) == -1) {
goto done;
+ }
- if (has_long_lines)
- if (file_printf(ms, ", with very long lines") == -1)
+ if (has_long_lines) {
+ if (file_printf (ms, ", with very long lines") == -1) {
goto done;
+ }
+ }
/*
* Only report line terminators if we find one other than LF,
@@ -304,49 +333,67 @@ subtype_identified:
*/
if ((n_crlf == 0 && n_cr == 0 && n_nel == 0 && n_lf == 0) ||
(n_crlf != 0 || n_cr != 0 || n_nel != 0)) {
- if (file_printf(ms, ", with") == -1)
+ if (file_printf (ms, ", with") == -1) {
goto done;
-
- if (n_crlf == 0 && n_cr == 0 && n_nel == 0 && n_lf == 0) {
- if (file_printf(ms, " no") == -1)
- goto done;
- } else {
- if (n_crlf) {
- if (file_printf(ms, " CRLF") == -1)
- goto done;
- if (n_cr || n_lf || n_nel)
- if (file_printf(ms, ",") == -1)
- goto done;
- }
- if (n_cr) {
- if (file_printf(ms, " CR") == -1)
- goto done;
- if (n_lf || n_nel)
- if (file_printf(ms, ",") == -1)
- goto done;
- }
- if (n_lf) {
- if (file_printf(ms, " LF") == -1)
- goto done;
- if (n_nel)
- if (file_printf(ms, ",") == -1)
- goto done;
- }
- if (n_nel)
- if (file_printf(ms, " NEL") == -1)
- goto done;
}
- if (file_printf(ms, " line terminators") == -1)
+ if (n_crlf == 0 && n_cr == 0 && n_nel == 0 && n_lf == 0) {
+ if (file_printf (ms, " no") == -1) {
+ goto done;
+ }
+ } else {
+ if (n_crlf) {
+ if (file_printf (ms, " CRLF") == -1) {
+ goto done;
+ }
+ if (n_cr || n_lf || n_nel) {
+ if (file_printf (ms, ",") == -1) {
+ goto done;
+ }
+ }
+ }
+ if (n_cr) {
+ if (file_printf (ms, " CR") == -1) {
+ goto done;
+ }
+ if (n_lf || n_nel) {
+ if (file_printf (ms, ",") == -1) {
+ goto done;
+ }
+ }
+ }
+ if (n_lf) {
+ if (file_printf (ms, " LF") == -1) {
+ goto done;
+ }
+ if (n_nel) {
+ if (file_printf (ms, ",") == -1) {
+ goto done;
+ }
+ }
+ }
+ if (n_nel) {
+ if (file_printf (ms, " NEL") == -1) {
+ goto done;
+ }
+ }
+ }
+
+ if (file_printf (ms, " line terminators") == -1) {
goto done;
+ }
}
- if (has_escapes)
- if (file_printf(ms, ", with escape sequences") == -1)
+ if (has_escapes) {
+ if (file_printf (ms, ", with escape sequences") == -1) {
goto done;
- if (has_backspace)
- if (file_printf(ms, ", with overstriking") == -1)
+ }
+ }
+ if (has_backspace) {
+ if (file_printf (ms, ", with overstriking") == -1) {
goto done;
+ }
+ }
}
rv = 1;
done:
@@ -359,8 +406,9 @@ done:
static int ascmatch(const ut8 *s, const unichar *us, size_t ulen) {
size_t i;
for (i = 0; i < ulen; i++) {
- if (s[i] != us[i])
+ if (s[i] != us[i]) {
return 0;
+ }
}
return s[i]? 0: 1;
}
@@ -449,8 +497,9 @@ static int looks_ascii(const ut8 *buf, size_t nbytes, unichar *ubuf, size_t *ule
*ulen = 0;
for (i = 0; i < nbytes; i++) {
int t = text_chars[buf[i]];
- if (t != T)
+ if (t != T) {
return 0;
+ }
ubuf[(*ulen)++] = buf[i];
}
return 1;
@@ -462,8 +511,9 @@ static int looks_latin1(const ut8 *buf, size_t nbytes, unichar *ubuf, size_t *ul
for (i = 0; i < nbytes; i++) {
int t = text_chars[buf[i]];
- if (t != T && t != I)
+ if (t != T && t != I) {
return 0;
+ }
ubuf[(*ulen)++] = buf[i];
}
return 1;
@@ -474,8 +524,9 @@ static int looks_extended(const ut8 *buf, size_t nbytes, unichar *ubuf, size_t *
*ulen = 0;
for (i = 0; i < nbytes; i++) {
int t = text_chars[buf[i]];
- if (t != T && t != I && t != X)
+ if (t != T && t != I && t != X) {
return 0;
+ }
ubuf[(*ulen)++] = buf[i];
}
return 1;
@@ -493,46 +544,53 @@ encode_utf8(ut8 *buf, size_t len, unichar *ubuf, size_t ulen)
for (i = 0; i < ulen; i++) {
if (ubuf[i] <= 0x7f) {
- if (end - buf < 1)
+ if (end - buf < 1) {
return NULL;
+ }
*buf++ = (ut8)ubuf[i];
} else if (ubuf[i] <= 0x7ff) {
- if (end - buf < 2)
+ if (end - buf < 2) {
return NULL;
+ }
*buf++ = (ut8)((ubuf[i] >> 6) + 0xc0);
*buf++ = (ut8)((ubuf[i] & 0x3f) + 0x80);
} else if (ubuf[i] <= 0xffff) {
- if (end - buf < 3)
+ if (end - buf < 3) {
return NULL;
+ }
*buf++ = (ut8)((ubuf[i] >> 12) + 0xe0);
*buf++ = (ut8)(((ubuf[i] >> 6) & 0x3f) + 0x80);
*buf++ = (ut8)((ubuf[i] & 0x3f) + 0x80);
} else if (ubuf[i] <= 0x1fffff) {
- if (end - buf < 4)
+ if (end - buf < 4) {
return NULL;
+ }
*buf++ = (ut8)((ubuf[i] >> 18) + 0xf0);
*buf++ = (ut8)(((ubuf[i] >> 12) & 0x3f) + 0x80);
*buf++ = (ut8)(((ubuf[i] >> 6) & 0x3f) + 0x80);
*buf++ = (ut8)((ubuf[i] & 0x3f) + 0x80);
} else if (ubuf[i] <= 0x3ffffff) {
- if (end - buf < 5)
+ if (end - buf < 5) {
return NULL;
+ }
*buf++ = (ut8)((ubuf[i] >> 24) + 0xf8);
*buf++ = (ut8)(((ubuf[i] >> 18) & 0x3f) + 0x80);
*buf++ = (ut8)(((ubuf[i] >> 12) & 0x3f) + 0x80);
*buf++ = (ut8)(((ubuf[i] >> 6) & 0x3f) + 0x80);
*buf++ = (ut8)((ubuf[i] & 0x3f) + 0x80);
} else if (ubuf[i] <= 0x7fffffff) {
- if (end - buf < 6)
+ if (end - buf < 6) {
return NULL;
+ }
*buf++ = (ut8)((ubuf[i] >> 30) + 0xfc);
*buf++ = (ut8)(((ubuf[i] >> 24) & 0x3f) + 0x80);
*buf++ = (ut8)(((ubuf[i] >> 18) & 0x3f) + 0x80);
*buf++ = (ut8)(((ubuf[i] >> 12) & 0x3f) + 0x80);
*buf++ = (ut8)(((ubuf[i] >> 6) & 0x3f) + 0x80);
*buf++ = (ut8)((ubuf[i] & 0x3f) + 0x80);
- } else /* Invalid character */
+ } else { /* Invalid character */
return NULL;
+ }
}
return buf;
@@ -555,8 +613,9 @@ int file_looks_utf8(const ut8 *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
unichar c;
int gotone = 0, ctrl = 0;
- if (ubuf)
+ if (ubuf) {
*ulen = 0;
+ }
for (i = 0; i < nbytes; i++) {
if ((buf[i] & 0x80) == 0) { /* 0xxxxxxx is plain ASCII */
@@ -565,11 +624,13 @@ int file_looks_utf8(const ut8 *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
* still reject it if it uses weird control characters.
*/
- if (text_chars[buf[i]] != T)
+ if (text_chars[buf[i]] != T) {
ctrl = 1;
+ }
- if (ubuf)
+ if (ubuf) {
ubuf[(*ulen)++] = buf[i];
+ }
} else if ((buf[i] & 0x40) == 0) { /* 10xxxxxx never 1st byte */
return -1;
} else { /* 11xxxxxx begins UTF-8 */
@@ -590,22 +651,26 @@ int file_looks_utf8(const ut8 *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
} else if ((buf[i] & 0x02) == 0) { /* 1111110x */
c = buf[i] & 0x01;
following = 5;
- } else
+ } else {
return -1;
+ }
for (n = 0; n < following; n++) {
i++;
- if (i >= nbytes)
+ if (i >= nbytes) {
goto done;
+ }
- if ((buf[i] & 0x80) == 0 || (buf[i] & 0x40))
+ if ((buf[i] & 0x80) == 0 || (buf[i] & 0x40)) {
return -1;
+ }
c = (c << 6) + (buf[i] & 0x3f);
}
- if (ubuf)
+ if (ubuf) {
ubuf[(*ulen)++] = c;
+ }
gotone = 1;
}
}
@@ -619,8 +684,9 @@ done:
* rest of the text.
*/
static int looks_utf8_with_BOM(const ut8 *buf, size_t nbytes, unichar *ubuf, size_t *ulen) {
- if (nbytes > 3 && buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf)
- return file_looks_utf8(buf + 3, nbytes - 3, ubuf, ulen);
+ if (nbytes > 3 && buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf) {
+ return file_looks_utf8 (buf + 3, nbytes - 3, ubuf, ulen);
+ }
return -1;
}
@@ -628,28 +694,35 @@ static int looks_ucs16(const ut8 *buf, size_t nbytes, unichar *ubuf, size_t *ule
int bigend;
size_t i;
- if (nbytes < 2)
+ if (nbytes < 2) {
return 0;
+ }
- if (buf[0] == 0xff && buf[1] == 0xfe)
+ if (buf[0] == 0xff && buf[1] == 0xfe) {
bigend = 0;
- else if (buf[0] == 0xfe && buf[1] == 0xff)
+ } else if (buf[0] == 0xfe && buf[1] == 0xff) {
bigend = 1;
- else return 0;
+ } else {
+ return 0;
+ }
*ulen = 0;
for (i = 2; i + 1 < nbytes; i += 2) {
/* XXX fix to properly handle chars > 65536 */
- if (bigend)
+ if (bigend) {
ubuf[(*ulen)++] = buf[i + 1] + 256 * buf[i];
- else ubuf[(*ulen)++] = buf[i] + 256 * buf[i + 1];
+ } else {
+ ubuf[(*ulen)++] = buf[i] + 256 * buf[i + 1];
+ }
- if (ubuf[*ulen - 1] == 0xfffe)
+ if (ubuf[*ulen - 1] == 0xfffe) {
return 0;
- if (ubuf[*ulen - 1] < 128 && text_chars[(size_t)ubuf[*ulen - 1]] != T)
+ }
+ if (ubuf[*ulen - 1] < 128 && text_chars[(size_t)ubuf[*ulen - 1]] != T) {
return 0;
+ }
}
return 1 + bigend;
}
@@ -740,7 +813,8 @@ static ut8 ebcdic_1047_to_8859[] = {
*/
static void from_ebcdic(const ut8 *buf, size_t nbytes, ut8 *out) {
size_t i;
- for (i = 0; i < nbytes; i++)
+ for (i = 0; i < nbytes; i++) {
out[i] = ebcdic_to_ascii[buf[i]];
+ }
}
#endif
diff --git a/libr/magic/funcs.c b/libr/magic/funcs.c
index 4ff37471c8..d477067842 100644
--- a/libr/magic/funcs.c
+++ b/libr/magic/funcs.c
@@ -64,10 +64,14 @@ int file_vprintf(RMagic *ms, const char *fmt, va_list ap) {
va_copy (ap2, ap);
len = vsnprintf (cbuf, sizeof (cbuf), fmt, ap2);
va_end (ap2);
- if (len < 0) goto out;
+ if (len < 0) {
+ goto out;
+ }
cbuf[len] = 0;
buf = strdup (cbuf);
- if (!buf) return -1;
+ if (!buf) {
+ return -1;
+ }
buflen = len;
if (ms->o.buf != NULL) {
@@ -83,8 +87,9 @@ int file_vprintf(RMagic *ms, const char *fmt, va_list ap) {
memcpy (newstr, ms->o.buf, obuflen);
memcpy (newstr+obuflen, buf, buflen);
free (buf);
- if (len < 0)
+ if (len < 0) {
goto out;
+ }
free (ms->o.buf);
buf = newstr;
}
@@ -101,8 +106,9 @@ out:
/*VARARGS*/
static void file_error_core(RMagic *ms, int error, const char *f, va_list va, ut32 lineno) {
/* Only the first error is ok */
- if (!ms || ms->haderr)
+ if (!ms || ms->haderr) {
return;
+ }
if (lineno != 0) {
free(ms->o.buf);
ms->o.buf = NULL;
@@ -110,8 +116,9 @@ static void file_error_core(RMagic *ms, int error, const char *f, va_list va, ut
}
// OPENBSDBUG
file_vprintf (ms, f, va);
- if (error > 0)
- (void)file_printf (ms, " (%s)", strerror(error));
+ if (error > 0) {
+ (void)file_printf (ms, " (%s)", strerror (error));
+ }
ms->haderr++;
ms->error = error;
}
@@ -149,19 +156,21 @@ void file_badread(RMagic *ms) {
int file_buffer(RMagic *ms, int fd, const char *inname, const void *buf, size_t nb) {
int mime, m = 0;
- if (!ms)
+ if (!ms) {
return -1;
+ }
mime = ms->flags & R_MAGIC_MIME;
if (nb == 0) {
if ((!mime || (mime & R_MAGIC_MIME_TYPE)) &&
- file_printf(ms, mime ? "application/x-empty" : "empty") == -1)
+ file_printf (ms, mime ? "application/x-empty" : "empty") == -1) {
return -1;
+ }
return 1;
} else if (nb == 1) {
if ((!mime || (mime & R_MAGIC_MIME_TYPE)) &&
- file_printf(ms, mime ? "application/octet-stream" :
- "very short file (no magic)") == -1)
+ file_printf (ms, mime ? "application/octet-stream" : "very short file (no magic)") == -1) {
return -1;
+ }
return 1;
}
@@ -196,8 +205,9 @@ int file_buffer(RMagic *ms, int fd, const char *inname, const void *buf, size_t
}
int file_reset(RMagic *ms) {
- if (!ms)
+ if (!ms) {
return 0;
+ }
free (ms->o.buf);
ms->o.buf = NULL;
ms->haderr = 0;
@@ -221,11 +231,13 @@ const char *file_getbuffer(RMagic *ms) {
char *pbuf, *op, *np;
size_t psize, len;
- if (ms->haderr)
+ if (ms->haderr) {
return NULL;
+ }
- if (ms->flags & R_MAGIC_RAW)
+ if (ms->flags & R_MAGIC_RAW) {
return ms->o.buf;
+ }
if (!ms->o.buf) {
eprintf ("ms->o.buf = NULL\n");
@@ -273,15 +285,17 @@ const char *file_getbuffer(RMagic *ms) {
op += bytesconsumed;
np += bytesconsumed;
} else {
- while (bytesconsumed-- > 0)
- OCTALIFY(np, op);
+ while (bytesconsumed-- > 0) {
+ OCTALIFY (np, op);
+ }
}
}
*np = '\0';
/* Parsing succeeded as a multi-byte sequence */
- if (mb_conv != 0)
+ if (mb_conv != 0) {
return ms->o.pbuf;
+ }
}
#endif
for (np = ms->o.pbuf, op = ms->o.buf; *op; op++) {
diff --git a/libr/magic/is_tar.c b/libr/magic/is_tar.c
index 0ff02ed0ca..27fef8cf03 100644
--- a/libr/magic/is_tar.c
+++ b/libr/magic/is_tar.c
@@ -63,15 +63,17 @@ static int from_oct(int digs, const char *where) {
int value = 0;
while (isspace ((ut8)*where)) { /* Skip spaces */
where++;
- if (--digs <= 0)
- return -1; /* All blank field */
+ if (--digs <= 0) {
+ return -1; /* All blank field */
+ }
}
while (digs > 0 && isodigit(*where)) { /* Scan til nonoctal */
value = (value << 3) | (*where++ - '0');
--digs;
}
- if (digs > 0 && *where && !isspace((ut8)*where))
- return -1; /* Ended on non-space/nul */
+ if (digs > 0 && *where && !isspace ((ut8)*where)) {
+ return -1; /* Ended on non-space/nul */
+ }
return value;
}
@@ -87,8 +89,9 @@ static int is_tar(const ut8 *buf, size_t nbytes) {
int i, sum, recsum;
const char *p;
- if (nbytes < sizeof(union record))
+ if (nbytes < sizeof (union record)) {
return 0;
+ }
recsum = from_oct (8, header->header.chksum);
@@ -103,14 +106,19 @@ static int is_tar(const ut8 *buf, size_t nbytes) {
}
/* Adjust checksum to count the "chksum" field as blanks. */
- for (i = sizeof header->header.chksum; --i >= 0;)
+ for (i = sizeof header->header.chksum; --i >= 0;) {
sum -= 0xFF & header->header.chksum[i];
- sum += ' ' * sizeof header->header.chksum;
- if (sum != recsum) return 0; /* Not a tar archive */
- if (strcmp (header->header.magic, GNUTMAGIC) == 0)
- return 3; /* GNU Unix Standard tar archive */
- if (strcmp (header->header.magic, TMAGIC) == 0)
- return 2; /* Unix Standard tar archive */
+ }
+ sum += ' ' * sizeof header->header.chksum;
+ if (sum != recsum) {
+ return 0; /* Not a tar archive */
+ }
+ if (strcmp (header->header.magic, GNUTMAGIC) == 0) {
+ return 3; /* GNU Unix Standard tar archive */
+ }
+ if (strcmp (header->header.magic, TMAGIC) == 0) {
+ return 2; /* Unix Standard tar archive */
+ }
return 1; /* Old fashioned tar archive */
}
@@ -122,13 +130,15 @@ int file_is_tar(RMagic *ms, const ut8 *buf, size_t nbytes) {
int tar = is_tar(buf, nbytes);
int mime = ms->flags & R_MAGIC_MIME;
- if (tar < 1 || tar > 3)
+ if (tar < 1 || tar > 3) {
return 0;
- if (mime == R_MAGIC_MIME_ENCODING)
+ }
+ if (mime == R_MAGIC_MIME_ENCODING) {
return 0;
- if (file_printf (ms, mime ? "application/x-tar" :
- tartype[tar - 1]) == -1)
+ }
+ if (file_printf (ms, mime ? "application/x-tar" : tartype[tar - 1]) == -1) {
return -1;
+ }
return 1;
}
#endif
diff --git a/libr/magic/magic.c b/libr/magic/magic.c
index 60d2498d12..5e82e9ed17 100644
--- a/libr/magic/magic.c
+++ b/libr/magic/magic.c
@@ -137,8 +137,9 @@ R_API int r_magic_errno(RMagic* m) {
static void free_mlist(struct mlist *mlist) {
struct mlist *ml;
- if (!mlist)
+ if (!mlist) {
return;
+ }
for (ml = mlist->next; ml != mlist;) {
struct mlist *next = ml->next;
struct r_magic *mg = ml->magic;
@@ -151,23 +152,31 @@ static void free_mlist(struct mlist *mlist) {
static int info_from_stat(RMagic *ms, unsigned short md) {
/* We cannot open it, but we were able to stat it. */
- if (md & 0222)
- if (file_printf (ms, "writable, ") == -1)
+ if (md & 0222) {
+ if (file_printf (ms, "writable, ") == -1) {
return -1;
- if (md & 0111)
- if (file_printf (ms, "executable, ") == -1)
+ }
+ }
+ if (md & 0111) {
+ if (file_printf (ms, "executable, ") == -1) {
return -1;
- if (S_ISREG (md))
- if (file_printf (ms, "regular file, ") == -1)
+ }
+ }
+ if (S_ISREG (md)) {
+ if (file_printf (ms, "regular file, ") == -1) {
return -1;
- if (file_printf (ms, "no read permission") == -1)
+ }
+ }
+ if (file_printf (ms, "no read permission") == -1) {
return -1;
+ }
return 0;
}
static void close_and_restore (const RMagic *ms, const char *name, int fd, const struct stat *sb) {
- if (fd>0)
+ if (fd > 0) {
close (fd);
+ }
}
static const char *file_or_fd(RMagic *ms, const char *inname, int fd) {
@@ -181,11 +190,13 @@ static const char *file_or_fd(RMagic *ms, const char *inname, int fd) {
* some overlapping space for matches near EOF
*/
#define SLOP (1 + sizeof(union VALUETYPE))
- if (!(buf = malloc (HOWMANY + SLOP)))
+ if (!(buf = malloc (HOWMANY + SLOP))) {
return NULL;
+ }
- if (file_reset (ms) == -1)
+ if (file_reset (ms) == -1) {
goto done;
+ }
switch (file_fsmagic (ms, inname, &sb)) {
case -1: goto done; /* error */
@@ -194,8 +205,9 @@ static const char *file_or_fd(RMagic *ms, const char *inname, int fd) {
}
if (!inname) {
- if (fstat (fd, &sb) == 0 && S_ISFIFO (sb.st_mode))
+ if (fstat (fd, &sb) == 0 && S_ISFIFO (sb.st_mode)) {
ispipe = 1;
+ }
} else {
int flags = O_RDONLY|O_BINARY;
@@ -208,8 +220,9 @@ static const char *file_or_fd(RMagic *ms, const char *inname, int fd) {
errno = 0;
if ((fd = open (inname, flags)) < 0) {
eprintf ("couldn't open file\n");
- if (info_from_stat (ms, sb.st_mode) == -1)
+ if (info_from_stat (ms, sb.st_mode) == -1) {
goto done;
+ }
rv = 0;
goto done;
}
@@ -232,13 +245,16 @@ static const char *file_or_fd(RMagic *ms, const char *inname, int fd) {
while ((r = read(fd, (void *)&buf[nbytes],
(size_t)(HOWMANY - nbytes))) > 0) {
nbytes += r;
- if (r < PIPE_BUF) break;
+ if (r < PIPE_BUF) {
+ break;
+ }
}
if (nbytes == 0) {
/* We can not read it, but we were able to stat it. */
- if (info_from_stat(ms, sb.st_mode) == -1)
+ if (info_from_stat (ms, sb.st_mode) == -1) {
goto done;
+ }
rv = 0;
goto done;
}
@@ -253,8 +269,9 @@ static const char *file_or_fd(RMagic *ms, const char *inname, int fd) {
#endif
(void)memset (buf + nbytes, 0, SLOP); /* NUL terminate */
- if (file_buffer (ms, fd, inname, buf, (size_t)nbytes) == -1)
+ if (file_buffer (ms, fd, inname, buf, (size_t)nbytes) == -1) {
goto done;
+ }
rv = 0;
done:
free (buf);
@@ -267,7 +284,9 @@ done:
// TODO: reinitialize all the time
R_API RMagic* r_magic_new(int flags) {
RMagic *ms = R_NEW0 (RMagic);
- if (!ms) return NULL;
+ if (!ms) {
+ return NULL;
+ }
r_magic_setflags (ms, flags);
ms->o.buf = ms->o.pbuf = NULL;
ms->c.li = malloc ((ms->c.len = 10) * sizeof (*ms->c.li));
@@ -283,7 +302,9 @@ R_API RMagic* r_magic_new(int flags) {
}
R_API void r_magic_free(RMagic *ms) {
- if (!ms) return;
+ if (!ms) {
+ return;
+ }
free_mlist (ms->mlist);
free (ms->o.pbuf);
free (ms->o.buf);
@@ -322,28 +343,36 @@ R_API const char * r_magic_file(RMagic *ms, const char *inname) {
}
R_API const char * r_magic_buffer(RMagic *ms, const void *buf, size_t nb) {
- if (file_reset (ms) == -1)
+ if (file_reset (ms) == -1) {
return NULL;
+ }
/*
* The main work is done here!
* We have the file name and/or the data buffer to be identified.
*/
- if (file_buffer (ms, -1, NULL, buf, nb) == -1)
+ if (file_buffer (ms, -1, NULL, buf, nb) == -1) {
return NULL;
+ }
return file_getbuffer (ms);
}
R_API const char * r_magic_error(RMagic *ms) {
- if (!ms) return 0;
+ if (!ms) {
+ return 0;
+ }
return ms->haderr ? ms->o.buf : NULL;
}
R_API int r_magic_errno(RMagic *ms) {
- if (!ms) return 0;
+ if (!ms) {
+ return 0;
+ }
return ms->haderr ? ms->error : 0;
}
R_API void r_magic_setflags(RMagic *ms, int flags) {
- if (ms) ms->flags = flags;
+ if (ms) {
+ ms->flags = flags;
+ }
}
#endif
diff --git a/libr/magic/softmagic.c b/libr/magic/softmagic.c
index 4887f9c128..e965496be0 100644
--- a/libr/magic/softmagic.c
+++ b/libr/magic/softmagic.c
@@ -164,12 +164,14 @@ static int match(RMagic *ms, struct r_magic *magic, ut32 nmagic, const ut8 *s, s
if (*R_MAGIC_DESC) {
need_separator = 1;
printed_something = 1;
- if (print_sep(ms, firstline) == -1)
+ if (print_sep (ms, firstline) == -1) {
return -1;
+ }
}
- if ((ms->c.li[cont_level].off = mprint(ms, m)) == -1)
+ if ((ms->c.li[cont_level].off = mprint (ms, m)) == -1) {
return -1;
+ }
/* and any continuations that match */
if (file_check_mem(ms, ++cont_level) == -1) {
@@ -191,16 +193,19 @@ static int match(RMagic *ms, struct r_magic *magic, ut32 nmagic, const ut8 *s, s
cont_level = m->cont_level;
}
ms->offset = m->offset;
- if (m->flag & OFFADD)
+ if (m->flag & OFFADD) {
ms->offset += ms->c.li[cont_level - 1].off;
+ }
if (m->cond == COND_ELSE || m->cond == COND_ELIF) {
- if (ms->c.li[cont_level].last_match == 1)
+ if (ms->c.li[cont_level].last_match == 1) {
continue;
+ }
}
flush = !mget(ms, s, m, nbytes, cont_level);
- if (flush && m->reln != '!')
+ if (flush && m->reln != '!') {
continue;
+ }
switch (flush ? 1 : magiccheck(ms, m)) {
case -1:
@@ -210,9 +215,9 @@ static int match(RMagic *ms, struct r_magic *magic, ut32 nmagic, const ut8 *s, s
break;
default:
ms->c.li[cont_level].last_match = 1;
- if (m->type != FILE_DEFAULT)
+ if (m->type != FILE_DEFAULT) {
ms->c.li[cont_level].got_match = 1;
- else if (ms->c.li[cont_level].got_match) {
+ } else if (ms->c.li[cont_level].got_match) {
ms->c.li[cont_level].got_match = 0;
break;
}
@@ -222,8 +227,9 @@ static int match(RMagic *ms, struct r_magic *magic, ut32 nmagic, const ut8 *s, s
*/
if (*R_MAGIC_DESC) {
printed_something = 1;
- if (print_sep(ms, firstline) == -1)
+ if (print_sep (ms, firstline) == -1) {
return -1;
+ }
}
/*
* This continuation matched. Print
@@ -235,22 +241,26 @@ static int match(RMagic *ms, struct r_magic *magic, ut32 nmagic, const ut8 *s, s
if (need_separator
&& ((m->flag & NOSPACE) == 0)
&& *R_MAGIC_DESC) {
- if (file_printf (ms, " ") == -1)
+ if (file_printf (ms, " ") == -1) {
return -1;
+ }
need_separator = 0;
}
- if ((ms->c.li[cont_level].off = mprint(ms, m)) == -1)
+ if ((ms->c.li[cont_level].off = mprint (ms, m)) == -1) {
return -1;
- if (*R_MAGIC_DESC)
+ }
+ if (*R_MAGIC_DESC) {
need_separator = 1;
+ }
/*
* If we see any continuations
* at a higher level,
* process them.
*/
- if (file_check_mem(ms, ++cont_level) == -1)
+ if (file_check_mem (ms, ++cont_level) == -1) {
return -1;
+ }
break;
}
}
@@ -258,8 +268,9 @@ static int match(RMagic *ms, struct r_magic *magic, ut32 nmagic, const ut8 *s, s
firstline = 0;
returnval = 1;
}
- if ((ms->flags & R_MAGIC_CONTINUE) == 0 && printed_something)
+ if ((ms->flags & R_MAGIC_CONTINUE) == 0 && printed_something) {
return 1; /* don't keep searching */
+ }
}
return returnval; /* This is hit if -k is set or there is no match */
}
@@ -268,8 +279,9 @@ static int check_fmt(RMagic *ms, struct r_magic *m) {
RRegex rx;
int rc;
- if (!strchr (R_MAGIC_DESC, '%'))
+ if (!strchr (R_MAGIC_DESC, '%')) {
return 0;
+ }
rc = r_regex_comp (&rx, "%[-0-9\\.]*s", R_REGEX_EXTENDED|R_REGEX_NOSUB);
if (rc) {
@@ -288,10 +300,12 @@ char * strdupn(const char *str, size_t n) {
size_t len;
char *copy;
- for (len = 0; len < n && str[len]; len++)
+ for (len = 0; len < n && str[len]; len++) {
continue;
- if (!(copy = malloc (len + 1)))
+ }
+ if (!(copy = malloc (len + 1))) {
return NULL;
+ }
(void)memcpy (copy, str, len);
copy[len] = '\0';
return copy;
@@ -323,8 +337,9 @@ static st32 mprint(RMagic *ms, struct r_magic *m) {
}
break;
default:
- if (file_printf(ms, R_MAGIC_DESC, (ut8) v) == -1)
+ if (file_printf (ms, R_MAGIC_DESC, (ut8)v) == -1) {
return -1;
+ }
break;
}
t = ms->offset + sizeof(char);
@@ -348,8 +363,9 @@ static st32 mprint(RMagic *ms, struct r_magic *m) {
}
break;
default:
- if (file_printf(ms, R_MAGIC_DESC, (unsigned short) v) == -1)
+ if (file_printf (ms, R_MAGIC_DESC, (unsigned short)v) == -1) {
return -1;
+ }
break;
}
t = ms->offset + sizeof(short);
@@ -374,8 +390,9 @@ static st32 mprint(RMagic *ms, struct r_magic *m) {
}
break;
default:
- if (file_printf(ms, R_MAGIC_DESC, (ut32) v) == -1)
+ if (file_printf (ms, R_MAGIC_DESC, (ut32)v) == -1) {
return -1;
+ }
break;
}
t = ms->offset + sizeof(st32);
@@ -384,8 +401,9 @@ static st32 mprint(RMagic *ms, struct r_magic *m) {
case FILE_BEQUAD:
case FILE_LEQUAD:
v = file_signextend(ms, m, p->q);
- if (file_printf(ms, R_MAGIC_DESC, (ut64) v) == -1)
+ if (file_printf (ms, R_MAGIC_DESC, (ut64)v) == -1) {
return -1;
+ }
t = ms->offset + sizeof(ut64);
break;
@@ -394,50 +412,56 @@ static st32 mprint(RMagic *ms, struct r_magic *m) {
case FILE_BESTRING16:
case FILE_LESTRING16:
if (m->reln == '=' || m->reln == '!') {
- if (file_printf (ms, R_MAGIC_DESC, m->value.s) == -1)
+ if (file_printf (ms, R_MAGIC_DESC, m->value.s) == -1) {
return -1;
+ }
t = ms->offset + m->vallen;
}
else {
- if (*m->value.s == '\0')
+ if (*m->value.s == '\0') {
p->s[strcspn (p->s, "\n")] = '\0';
- if (file_printf (ms, R_MAGIC_DESC, p->s) == -1)
+ }
+ if (file_printf (ms, R_MAGIC_DESC, p->s) == -1) {
return -1;
+ }
t = ms->offset + strlen (p->s);
- if (m->type == FILE_PSTRING)
+ if (m->type == FILE_PSTRING) {
t++;
+ }
}
break;
case FILE_DATE:
case FILE_BEDATE:
case FILE_LEDATE:
case FILE_MEDATE:
- if (file_printf(ms, R_MAGIC_DESC, file_fmttime(p->l, 1)) == -1)
+ if (file_printf (ms, R_MAGIC_DESC, file_fmttime (p->l, 1)) == -1) {
return -1;
+ }
t = ms->offset + sizeof(time_t);
break;
case FILE_LDATE:
case FILE_BELDATE:
case FILE_LELDATE:
case FILE_MELDATE:
- if (file_printf(ms, R_MAGIC_DESC, file_fmttime(p->l, 0)) == -1)
+ if (file_printf (ms, R_MAGIC_DESC, file_fmttime (p->l, 0)) == -1) {
return -1;
+ }
t = ms->offset + sizeof(time_t);
break;
case FILE_QDATE:
case FILE_BEQDATE:
case FILE_LEQDATE:
- if (file_printf(ms, R_MAGIC_DESC, file_fmttime((ut32)p->q, 1))
- == -1)
+ if (file_printf (ms, R_MAGIC_DESC, file_fmttime ((ut32)p->q, 1)) == -1) {
return -1;
+ }
t = ms->offset + sizeof(ut64);
break;
case FILE_QLDATE:
case FILE_BEQLDATE:
case FILE_LEQLDATE:
- if (file_printf(ms, R_MAGIC_DESC, file_fmttime((ut32)p->q, 0))
- == -1)
+ if (file_printf (ms, R_MAGIC_DESC, file_fmttime ((ut32)p->q, 0)) == -1) {
return -1;
+ }
t = ms->offset + sizeof(ut64);
break;
case FILE_FLOAT:
@@ -459,8 +483,9 @@ static st32 mprint(RMagic *ms, struct r_magic *m) {
}
break;
default:
- if (file_printf(ms, R_MAGIC_DESC, vf) == -1)
+ if (file_printf (ms, R_MAGIC_DESC, vf) == -1) {
return -1;
+ }
break;
}
t = ms->offset + sizeof(float);
@@ -484,8 +509,9 @@ static st32 mprint(RMagic *ms, struct r_magic *m) {
}
break;
default:
- if (file_printf(ms, R_MAGIC_DESC, vd) == -1)
+ if (file_printf (ms, R_MAGIC_DESC, vd) == -1) {
return -1;
+ }
break;
}
t = ms->offset + sizeof(double);
@@ -502,26 +528,32 @@ static st32 mprint(RMagic *ms, struct r_magic *m) {
rval = file_printf(ms, R_MAGIC_DESC, cp);
free(cp);
- if (rval == -1)
+ if (rval == -1) {
return -1;
+ }
- if ((m->str_flags & REGEX_OFFSET_START))
+ if ((m->str_flags & REGEX_OFFSET_START)) {
t = ms->search.offset;
- else
+ } else {
t = ms->search.offset + ms->search.rm_len;
+ }
break;
}
case FILE_SEARCH:
- if (file_printf(ms, R_MAGIC_DESC, m->value.s) == -1)
+ if (file_printf (ms, R_MAGIC_DESC, m->value.s) == -1) {
return -1;
- if ((m->str_flags & REGEX_OFFSET_START))
+ }
+ if ((m->str_flags & REGEX_OFFSET_START)) {
t = ms->search.offset;
- else t = ms->search.offset + m->vallen;
+ } else {
+ t = ms->search.offset + m->vallen;
+ }
break;
case FILE_DEFAULT:
- if (file_printf(ms, R_MAGIC_DESC, m->value.s) == -1)
+ if (file_printf (ms, R_MAGIC_DESC, m->value.s) == -1) {
return -1;
+ }
t = ms->offset;
break;
default:
@@ -637,21 +669,25 @@ static int mconvert(RMagic *ms, struct r_magic *m) {
/* Null terminate and eat *trailing* return */
p->s[sizeof(p->s) - 1] = '\0';
len = strlen(p->s);
- if (len-- && p->s[len] == '\n')
+ if (len-- && p->s[len] == '\n') {
p->s[len] = '\0';
+ }
return 1;
}
case FILE_PSTRING: {
char *ptr1 = p->s, *ptr2 = ptr1 + 1;
size_t len = *p->s;
- if (len >= sizeof(p->s))
- len = sizeof(p->s) - 1;
- while (len--)
+ if (len >= sizeof (p->s)) {
+ len = sizeof (p->s) - 1;
+ }
+ while (len--) {
*ptr1++ = *ptr2++;
+ }
*ptr1 = '\0';
len = strlen(p->s);
- if (len-- && p->s[len] == '\n')
+ if (len-- && p->s[len] == '\n') {
p->s[len] = '\0';
+ }
return 1;
}
case FILE_BESHORT:
@@ -780,11 +816,13 @@ static int mcopy(RMagic *ms, union VALUETYPE *p, int type, int indir, const ut8
lines && ((b = strchr(c = b, '\n')) || (b = strchr(c, '\r')));
lines--, b++) {
last = b;
- if (b[0] == '\r' && b[1] == '\n')
+ if (b[0] == '\r' && b[1] == '\n') {
b++;
+ }
}
- if (lines)
+ if (lines) {
last = (const char *)s + nbytes;
+ }
ms->search.s = buf;
ms->search.s_len = last - buf;
@@ -799,8 +837,9 @@ static int mcopy(RMagic *ms, union VALUETYPE *p, int type, int indir, const ut8
char *dst = p->s;
char *edst = &p->s[sizeof(p->s) - 1];
- if (type == FILE_BESTRING16)
+ if (type == FILE_BESTRING16) {
src++;
+ }
/* check for pointer overflow */
if (src < s) {
@@ -809,15 +848,15 @@ static int mcopy(RMagic *ms, union VALUETYPE *p, int type, int indir, const ut8
return -1;
}
for (/*EMPTY*/; src < esrc; src += 2, dst++) {
- if (dst < edst)
+ if (dst < edst) {
*dst = *src;
- else
+ } else {
break;
+ }
if (*dst == '\0') {
- if (type == FILE_BESTRING16 ?
- *(src - 1) != '\0' :
- *(src + 1) != '\0')
+ if (type == FILE_BESTRING16 ? *(src - 1) != '\0' : *(src + 1) != '\0') {
*dst = ' ';
+ }
}
}
*edst = '\0';
@@ -843,9 +882,10 @@ static int mcopy(RMagic *ms, union VALUETYPE *p, int type, int indir, const ut8
* the usefulness of padding with zeroes eludes me, it
* might even cause problems
*/
- if (nbytes < sizeof(*p))
- (void)memset(((char *)(void *)p) + nbytes, '\0',
- sizeof(*p) - nbytes);
+ if (nbytes < sizeof (*p)) {
+ (void)memset (((char *)(void *)p) + nbytes, '\0',
+ sizeof (*p) - nbytes);
+ }
return 0;
}
@@ -854,8 +894,9 @@ static int mget(RMagic *ms, const ut8 *s, struct r_magic *m, size_t nbytes, unsi
ut32 count = m->str_range;
union VALUETYPE *p = &ms->ms_value;
- if (mcopy(ms, p, m->type, m->flag & INDIR, s, offset, nbytes, count) == -1)
+ if (mcopy (ms, p, m->type, m->flag & INDIR, s, offset, nbytes, count) == -1) {
return -1;
+ }
if ((ms->flags & R_MAGIC_DEBUG) != 0) {
mdebug(offset, (char *)(void *)p, sizeof(union VALUETYPE));
@@ -896,8 +937,9 @@ static int mget(RMagic *ms, const ut8 *s, struct r_magic *m, size_t nbytes, unsi
}
switch (m->in_type) {
case FILE_BYTE:
- if (nbytes < (offset + 1))
+ if (nbytes < (offset + 1)) {
return 0;
+ }
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
case FILE_OPAND: offset = p->b & off; break;
@@ -909,14 +951,17 @@ static int mget(RMagic *ms, const ut8 *s, struct r_magic *m, size_t nbytes, unsi
case FILE_OPDIVIDE: offset = p->b / off; break;
case FILE_OPMODULO: offset = p->b % off; break;
}
- } else
+ } else {
offset = p->b;
- if (m->in_op & FILE_OPINVERSE)
+ }
+ if (m->in_op & FILE_OPINVERSE) {
offset = ~offset;
+ }
break;
case FILE_BESHORT:
- if (nbytes < (offset + 2))
+ if (nbytes < (offset + 2)) {
return 0;
+ }
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
case FILE_OPAND: offset = (short)((p->hs[0]<<8)| (p->hs[1])) & off; break;
@@ -928,15 +973,18 @@ static int mget(RMagic *ms, const ut8 *s, struct r_magic *m, size_t nbytes, unsi
case FILE_OPDIVIDE: offset = (short)((p->hs[0]<<8)| (p->hs[1])) / off; break;
case FILE_OPMODULO: offset = (short)((p->hs[0]<<8)| (p->hs[1])) % off; break;
}
- } else
- offset = (short)((p->hs[0]<<8)|
+ } else {
+ offset = (short)((p->hs[0] << 8) |
(p->hs[1]));
- if (m->in_op & FILE_OPINVERSE)
+ }
+ if (m->in_op & FILE_OPINVERSE) {
offset = ~offset;
+ }
break;
case FILE_LESHORT:
- if (nbytes < (offset + 2))
+ if (nbytes < (offset + 2)) {
return 0;
+ }
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
case FILE_OPAND: offset = (short)((p->hs[1]<<8)| (p->hs[0])) & off; break;
@@ -948,13 +996,17 @@ static int mget(RMagic *ms, const ut8 *s, struct r_magic *m, size_t nbytes, unsi
case FILE_OPDIVIDE: offset = (short)((p->hs[1]<<8)| (p->hs[0])) / off; break;
case FILE_OPMODULO: offset = (short)((p->hs[1]<<8)| (p->hs[0])) % off; break;
}
- } else offset = (short)((p->hs[1]<<8)| (p->hs[0]));
- if (m->in_op & FILE_OPINVERSE)
+ } else {
+ offset = (short)((p->hs[1] << 8) | (p->hs[0]));
+ }
+ if (m->in_op & FILE_OPINVERSE) {
offset = ~offset;
+ }
break;
case FILE_SHORT:
- if (nbytes < (offset + 2))
+ if (nbytes < (offset + 2)) {
return 0;
+ }
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
case FILE_OPAND: offset = p->h & off; break;
@@ -966,13 +1018,17 @@ static int mget(RMagic *ms, const ut8 *s, struct r_magic *m, size_t nbytes, unsi
case FILE_OPDIVIDE: offset = p->h / off; break;
case FILE_OPMODULO: offset = p->h % off; break;
}
- } else offset = p->h;
- if (m->in_op & FILE_OPINVERSE)
+ } else {
+ offset = p->h;
+ }
+ if (m->in_op & FILE_OPINVERSE) {
offset = ~offset;
+ }
break;
case FILE_BELONG:
- if (nbytes < (offset + 4))
+ if (nbytes < (offset + 4)) {
return 0;
+ }
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
case FILE_OPAND:
@@ -1000,13 +1056,17 @@ static int mget(RMagic *ms, const ut8 *s, struct r_magic *m, size_t nbytes, unsi
offset = (st32)((p->hl[0]<<24)| (p->hl[1]<<16)| (p->hl[2]<<8)| (p->hl[3])) % off;
break;
}
- } else offset = (st32)((p->hl[0]<<24)| (p->hl[1]<<16)| (p->hl[2]<<8)| (p->hl[3]));
- if (m->in_op & FILE_OPINVERSE)
+ } else {
+ offset = (st32) ((p->hl[0] << 24) | (p->hl[1] << 16) | (p->hl[2] << 8) | (p->hl[3]));
+ }
+ if (m->in_op & FILE_OPINVERSE) {
offset = ~offset;
+ }
break;
case FILE_LELONG:
- if (nbytes < (offset + 4))
+ if (nbytes < (offset + 4)) {
return 0;
+ }
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
case FILE_OPAND:
@@ -1034,13 +1094,17 @@ static int mget(RMagic *ms, const ut8 *s, struct r_magic *m, size_t nbytes, unsi
offset = (st32)((p->hl[3]<<24)| (p->hl[2]<<16)| (p->hl[1]<<8)| (p->hl[0])) % off;
break;
}
- } else offset = (st32)((p->hl[3]<<24)| (p->hl[2]<<16)| (p->hl[1]<<8)| (p->hl[0]));
- if (m->in_op & FILE_OPINVERSE)
+ } else {
+ offset = (st32) ((p->hl[3] << 24) | (p->hl[2] << 16) | (p->hl[1] << 8) | (p->hl[0]));
+ }
+ if (m->in_op & FILE_OPINVERSE) {
offset = ~offset;
+ }
break;
case FILE_MELONG:
- if (nbytes < (offset + 4))
+ if (nbytes < (offset + 4)) {
return 0;
+ }
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
case FILE_OPAND:
@@ -1068,13 +1132,17 @@ static int mget(RMagic *ms, const ut8 *s, struct r_magic *m, size_t nbytes, unsi
offset = (st32)((p->hl[1]<<24)| (p->hl[0]<<16)| (p->hl[3]<<8)| (p->hl[2])) % off;
break;
}
- } else offset = (st32)((p->hl[1]<<24)| (p->hl[0]<<16)| (p->hl[3]<<8)| (p->hl[2]));
- if (m->in_op & FILE_OPINVERSE)
+ } else {
+ offset = (st32) ((p->hl[1] << 24) | (p->hl[0] << 16) | (p->hl[3] << 8) | (p->hl[2]));
+ }
+ if (m->in_op & FILE_OPINVERSE) {
offset = ~offset;
+ }
break;
case FILE_LONG:
- if (nbytes < (offset + 4))
+ if (nbytes < (offset + 4)) {
return 0;
+ }
if (off) {
switch (m->in_op & FILE_OPS_MASK) {
case FILE_OPAND: offset = p->l & off; break;
@@ -1086,17 +1154,21 @@ static int mget(RMagic *ms, const ut8 *s, struct r_magic *m, size_t nbytes, unsi
case FILE_OPDIVIDE: offset = p->l / off; break;
case FILE_OPMODULO: offset = p->l % off; break;
}
- } else
+ } else {
offset = p->l;
- if (m->in_op & FILE_OPINVERSE)
+ }
+ if (m->in_op & FILE_OPINVERSE) {
offset = ~offset;
+ }
break;
}
- if (m->flag & INDIROFFADD)
- offset += ms->c.li[cont_level-1].off;
- if (mcopy (ms, p, m->type, 0, s, offset, nbytes, count) == -1)
+ if (m->flag & INDIROFFADD) {
+ offset += ms->c.li[cont_level - 1].off;
+ }
+ if (mcopy (ms, p, m->type, 0, s, offset, nbytes, count) == -1) {
return -1;
+ }
ms->offset = offset;
if ((ms->flags & R_MAGIC_DEBUG) != 0) {
@@ -1109,14 +1181,16 @@ static int mget(RMagic *ms, const ut8 *s, struct r_magic *m, size_t nbytes, unsi
/* Verify we have enough data to match magic type */
switch (m->type) {
case FILE_BYTE:
- if (nbytes < (offset + 1)) /* should alway be true */
+ if (nbytes < (offset + 1)) { /* should alway be true */
return 0;
+ }
break;
case FILE_SHORT:
case FILE_BESHORT:
case FILE_LESHORT:
- if (nbytes < (offset + 2))
+ if (nbytes < (offset + 2)) {
return 0;
+ }
break;
case FILE_LONG:
case FILE_BELONG:
@@ -1133,24 +1207,28 @@ static int mget(RMagic *ms, const ut8 *s, struct r_magic *m, size_t nbytes, unsi
case FILE_FLOAT:
case FILE_BEFLOAT:
case FILE_LEFLOAT:
- if (nbytes < (offset + 4))
+ if (nbytes < (offset + 4)) {
return 0;
+ }
break;
case FILE_DOUBLE:
case FILE_BEDOUBLE:
case FILE_LEDOUBLE:
- if (nbytes < (offset + 8))
+ if (nbytes < (offset + 8)) {
return 0;
+ }
break;
case FILE_STRING:
case FILE_PSTRING:
case FILE_SEARCH:
- if (nbytes < (offset + m->vallen))
+ if (nbytes < (offset + m->vallen)) {
return 0;
+ }
break;
case FILE_REGEX:
- if (nbytes < offset)
+ if (nbytes < offset) {
return 0;
+ }
break;
case FILE_DEFAULT: /* nothing to check */
default:
@@ -1176,34 +1254,41 @@ static ut64 file_strncmp(const char *s1, const char *s2, size_t len, ut32 flags)
*/
v = 0;
if (0L == flags) { /* normal string: do it fast */
- while (len-- > 0)
- if ((v = *b++ - *a++) != '\0')
+ while (len-- > 0) {
+ if ((v = *b++ - *a++) != '\0') {
break;
+ }
+ }
} else { /* combine the others */
while (len-- > 0) {
if ((flags & STRING_IGNORE_LOWERCASE) &&
islower(*a)) {
- if ((v = tolower(*b++) - *a++) != '\0')
+ if ((v = tolower (*b++) - *a++) != '\0') {
break;
+ }
} else if ((flags & STRING_IGNORE_UPPERCASE) && isupper(*a)) {
- if ((v = toupper(*b++) - *a++) != '\0')
+ if ((v = toupper (*b++) - *a++) != '\0') {
break;
+ }
} else if ((flags & STRING_COMPACT_BLANK) && isspace(*a)) {
a++;
if (isspace(*b++)) {
- while (isspace(*b))
+ while (isspace (*b)) {
b++;
+ }
} else {
v = 1;
break;
}
} else if ((flags & STRING_COMPACT_OPTIONAL_BLANK) && isspace(*a)) {
a++;
- while (isspace(*b))
+ while (isspace (*b)) {
b++;
+ }
} else {
- if ((v = *b++ - *a++) != '\0')
+ if ((v = *b++ - *a++) != '\0') {
break;
+ }
}
}
}
@@ -1313,18 +1398,21 @@ static int magiccheck(RMagic *ms, struct r_magic *m) {
case FILE_SEARCH: { /* search ms->search.s for the string m->value.s */
size_t slen, idx;
- if (!ms->search.s)
+ if (!ms->search.s) {
return 0;
+ }
slen = R_MIN (m->vallen, sizeof (m->value.s));
l = 0;
v = 0;
for (idx = 0; m->str_range == 0 || idx < m->str_range; idx++) {
- if ((int)ms->search.offset < 0)
+ if ((int)ms->search.offset < 0) {
break;
- if (slen + idx > ms->search.s_len)
+ }
+ if (slen + idx > ms->search.s_len) {
break;
+ }
v = file_strncmp (m->value.s, ms->search.s + idx, slen, m->str_flags);
if (v == 0) { /* found match */
ms->search.offset += idx;
@@ -1338,8 +1426,9 @@ static int magiccheck(RMagic *ms, struct r_magic *m) {
RRegex rx;
char errmsg[512];
- if (!ms->search.s)
+ if (!ms->search.s) {
return 0;
+ }
l = 0;
rc = r_regex_comp (&rx, m->value.s,
@@ -1383,8 +1472,9 @@ static int magiccheck(RMagic *ms, struct r_magic *m) {
}
r_regex_fini (&rx);
}
- if (v == (ut64)-1)
+ if (v == (ut64)-1) {
return -1;
+ }
break;
}
default:
@@ -1395,51 +1485,60 @@ static int magiccheck(RMagic *ms, struct r_magic *m) {
v = file_signextend (ms, m, v);
switch (m->reln) {
case 'x':
- if ((ms->flags & R_MAGIC_DEBUG) != 0)
- (void) fprintf(stderr, "%"PFMT64u" == *any* = 1\n", (ut64)v);
+ if ((ms->flags & R_MAGIC_DEBUG) != 0) {
+ (void)fprintf (stderr, "%" PFMT64u " == *any* = 1\n", (ut64)v);
+ }
matched = 1;
break;
case '!':
matched = v != l;
- if ((ms->flags & R_MAGIC_DEBUG) != 0)
- fprintf(stderr, "%"PFMT64u" != %"PFMT64u" = %d\n", (ut64)v, (ut64)l, matched);
+ if ((ms->flags & R_MAGIC_DEBUG) != 0) {
+ fprintf (stderr, "%" PFMT64u " != %" PFMT64u " = %d\n", (ut64)v, (ut64)l, matched);
+ }
break;
case '=':
matched = v == l;
- if ((ms->flags & R_MAGIC_DEBUG) != 0)
- eprintf ("%"PFMT64u" == %"PFMT64u" = %d\n", (ut64)v, (ut64)l, matched);
+ if ((ms->flags & R_MAGIC_DEBUG) != 0) {
+ eprintf ("%" PFMT64u " == %" PFMT64u " = %d\n", (ut64)v, (ut64)l, matched);
+ }
break;
case '>':
if (m->flag & UNSIGNED) {
matched = v > l;
- if ((ms->flags & R_MAGIC_DEBUG) != 0)
- eprintf ("%"PFMT64u" > %"PFMT64u" = %d\n", (ut64)v, (ut64)l, matched);
+ if ((ms->flags & R_MAGIC_DEBUG) != 0) {
+ eprintf ("%" PFMT64u " > %" PFMT64u " = %d\n", (ut64)v, (ut64)l, matched);
+ }
} else {
matched = (ut64) v > (ut64) l;
- if ((ms->flags & R_MAGIC_DEBUG) != 0)
- eprintf ("%"PFMT64u" > %"PFMT64u" = %d\n", (st64)v, (st64)l, matched);
+ if ((ms->flags & R_MAGIC_DEBUG) != 0) {
+ eprintf ("%" PFMT64u " > %" PFMT64u " = %d\n", (st64)v, (st64)l, matched);
+ }
}
break;
case '<':
if (m->flag & UNSIGNED) {
matched = v < l;
- if ((ms->flags & R_MAGIC_DEBUG) != 0)
- eprintf ("%"PFMT64u" < %"PFMT64u" = %d\n", (ut64)v, (ut64)l, matched);
+ if ((ms->flags & R_MAGIC_DEBUG) != 0) {
+ eprintf ("%" PFMT64u " < %" PFMT64u " = %d\n", (ut64)v, (ut64)l, matched);
+ }
} else {
matched = (ut64) v < (ut64) l;
- if ((ms->flags & R_MAGIC_DEBUG) != 0)
- eprintf ("%"PFMT64d" < %"PFMT64d" = %d\n", (st64)v, (st64)l, matched);
+ if ((ms->flags & R_MAGIC_DEBUG) != 0) {
+ eprintf ("%" PFMT64d " < %" PFMT64d " = %d\n", (st64)v, (st64)l, matched);
+ }
}
break;
case '&':
matched = (v & l) == l;
- if ((ms->flags & R_MAGIC_DEBUG) != 0)
- eprintf("((%"PFMT64x" & %"PFMT64x") == %"PFMT64x") = %d\n", (ut64)v, (ut64)l, (ut64)l, matched);
+ if ((ms->flags & R_MAGIC_DEBUG) != 0) {
+ eprintf ("((%" PFMT64x " & %" PFMT64x ") == %" PFMT64x ") = %d\n", (ut64)v, (ut64)l, (ut64)l, matched);
+ }
break;
case '^':
matched = (v & l) != l;
- if ((ms->flags & R_MAGIC_DEBUG) != 0)
- eprintf ("((%"PFMT64x" & %"PFMT64x") != %"PFMT64x") = %d\n", (ut64)v, (ut64)l, (ut64)l, matched);
+ if ((ms->flags & R_MAGIC_DEBUG) != 0) {
+ eprintf ("((%" PFMT64x " & %" PFMT64x ") != %" PFMT64x ") = %d\n", (ut64)v, (ut64)l, (ut64)l, matched);
+ }
break;
default:
matched = 0;
diff --git a/libr/parse/code.c b/libr/parse/code.c
index d895f41d44..52aaa5c308 100644
--- a/libr/parse/code.c
+++ b/libr/parse/code.c
@@ -12,7 +12,9 @@ static void appendstring(const char *msg, char **s) {
printf ("%s\n", msg);
} else if (*s) {
char *p = malloc (strlen (msg) + strlen (*s) + 1);
- if (!p) return;
+ if (!p) {
+ return;
+ }
strcpy (p, *s);
free (*s);
*s = p;
@@ -76,7 +78,9 @@ static int typeload(void *p, const char *k, const char *v) {
R_API char *r_parse_c_file(RAnal *anal, const char *path) {
char *str = NULL;
TCCState *T = tcc_new (anal->cpu, anal->bits, anal->os);
- if (!T) return NULL;
+ if (!T) {
+ return NULL;
+ }
tcc_set_callback (T, &appendstring, &str);
sdb_foreach (anal->sdb_types, typeload, anal);
if (tcc_add_file (T, path) == -1) {
@@ -90,7 +94,9 @@ R_API char *r_parse_c_file(RAnal *anal, const char *path) {
R_API char *r_parse_c_string(RAnal *anal, const char *code) {
char *str = NULL;
TCCState *T = tcc_new (anal->cpu, anal->bits, anal->os);
- if (!T) return NULL;
+ if (!T) {
+ return NULL;
+ }
tcc_set_callback (T, &appendstring, &str);
sdb_foreach (anal->sdb_types, typeload, NULL);
if (tcc_compile_string (T, code) != 0) {
diff --git a/libr/parse/p/parse_6502_pseudo.c b/libr/parse/p/parse_6502_pseudo.c
index f341ae2d0a..899cbeb1f9 100644
--- a/libr/parse/p/parse_6502_pseudo.c
+++ b/libr/parse/p/parse_6502_pseudo.c
@@ -70,11 +70,15 @@ static int replace(int argc, const char *argv[], char *newstr, ADDR_TYPE type) {
{0, "sei", "set_interrupt"},
{1, "jsr", "1()"},
{0, NULL}};
- if (!newstr) return false;
+ if (!newstr) {
+ return false;
+ }
for (i = 0; ops[i].op != NULL; i++) {
if (ops[i].narg) {
- if (argc - 1 != ops[i].narg) continue;
+ if (argc - 1 != ops[i].narg) {
+ continue;
+ }
}
if (!strcmp(ops[i].op, argv[0])) {
for (j = k = 0; ops[i].str[j] != '\0'; j++, k++) {
@@ -109,7 +113,9 @@ static int replace(int argc, const char *argv[], char *newstr, ADDR_TYPE type) {
static ADDR_TYPE addr_type(const char *str) {
if (strchr(str, '(')) {
char *e = strchr (str, ')');
- if (!e) return NORM;
+ if (!e) {
+ return NORM;
+ }
char *o = strchr (e, ',');
return (o) ? IND_IDX : IDX_IND;
}
@@ -122,7 +128,9 @@ static int parse(RParse *p, const char *data, char *str) {
char *buf, *ptr, *optr;
ADDR_TYPE atype;
- if (len >= sizeof(w0)) return false;
+ if (len >= sizeof (w0)) {
+ return false;
+ }
// malloc can be slow here :?
if (!(buf = malloc (len + 1))) {
return false;
@@ -135,19 +143,23 @@ static int parse(RParse *p, const char *data, char *str) {
r_str_replace_char (buf, ')', ' ');
*w0 = *w1 = *w2 = '\0';
ptr = strchr (buf, ' ');
- if (!ptr) ptr = strchr (buf, '\t');
+ if (!ptr) {
+ ptr = strchr (buf, '\t');
+ }
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr == ' '; ptr++)
+ for (++ptr; *ptr == ' '; ptr++) {
;
+ }
strncpy (w0, buf, sizeof(w0) - 1);
strncpy (w1, ptr, sizeof(w1) - 1);
optr = ptr;
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr == ' '; ptr++)
+ for (++ptr; *ptr == ' '; ptr++) {
;
+ }
strncpy (w1, optr, sizeof(w1) - 1);
strncpy (w2, ptr, sizeof(w2) - 1);
}
@@ -158,7 +170,9 @@ static int parse(RParse *p, const char *data, char *str) {
const char *wa[] = {w0, w1, w2};
int nw = 0;
for (i = 0; i < 3; i++) {
- if (wa[i][0]) nw++;
+ if (wa[i][0]) {
+ nw++;
+ }
}
replace (nw, wa, str, atype);
}
diff --git a/libr/parse/p/parse_arm_pseudo.c b/libr/parse/p/parse_arm_pseudo.c
index f41c7ee9c3..474d6f5e26 100644
--- a/libr/parse/p/parse_arm_pseudo.c
+++ b/libr/parse/p/parse_arm_pseudo.c
@@ -192,7 +192,9 @@ static int parse(RParse *p, const char *data, char *str) {
}
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w0, buf, sizeof (w0) - 1);
strncpy (w1, ptr, sizeof (w1) - 1);
@@ -214,14 +216,18 @@ static int parse(RParse *p, const char *data, char *str) {
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w1, optr, sizeof (w1) - 1);
strncpy (w2, ptr, sizeof (w2) - 1);
optr = ptr;
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w2, optr, sizeof (w2) - 1);
strncpy (w3, ptr, sizeof (w3) - 1);
}
diff --git a/libr/parse/p/parse_att2intel.c b/libr/parse/p/parse_att2intel.c
index be6180e1c2..07d34ea71e 100644
--- a/libr/parse/p/parse_att2intel.c
+++ b/libr/parse/p/parse_att2intel.c
@@ -45,7 +45,9 @@ static int replace(int argc, const char *argv[], char *newstr) {
strcpy(newstr+k, w);
k += strlen(w)-1;
}
- } else newstr[k] = ops[i].str[j];
+ } else {
+ newstr[k] = ops[i].str[j];
+ }
}
newstr[k]='\0';
}
@@ -75,7 +77,9 @@ static int parse(RParse *p, const char *data, char *str) {
// malloc can be slow here :?
buf = strdup (data);
- if (!buf) return false;
+ if (!buf) {
+ return false;
+ }
r_str_trim_head (buf);
ptr = strchr (buf, '#');
@@ -97,8 +101,9 @@ static int parse(RParse *p, const char *data, char *str) {
if (ptr) {
*ptr = 0;
num = (char*)r_str_lchr (buf, ' ');
- if (!num)
- num = (char*)r_str_lchr (buf, ',');
+ if (!num) {
+ num = (char *)r_str_lchr (buf, ',');
+ }
if (num) {
n = atoi (num+1);
*ptr = '[';
@@ -106,21 +111,29 @@ static int parse(RParse *p, const char *data, char *str) {
ptr = (char*)r_str_lchr (buf, ']');
if (n && ptr) {
char *rest = strdup (ptr+1);
- if(n>0) sprintf (ptr, "+%d]%s", n, rest);
- else sprintf (ptr, "%d]%s", n, rest);
+ if (n > 0) {
+ sprintf (ptr, "+%d]%s", n, rest);
+ } else {
+ sprintf (ptr, "%d]%s", n, rest);
+ }
free (rest);
}
- } else *ptr = '[';
+ } else {
+ *ptr = '[';
+ }
}
if (*buf) {
*w0 = *w1 = *w2 = *w3 = 0;
ptr = strchr (buf, ' ');
- if (!ptr)
+ if (!ptr) {
ptr = strchr (buf, '\t');
+ }
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w0, buf, sizeof(w0) - 1);
strncpy (w1, ptr, sizeof(w1) - 1);
@@ -128,13 +141,17 @@ static int parse(RParse *p, const char *data, char *str) {
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w1, optr, sizeof(w1)-1);
strncpy (w2, ptr, sizeof(w2)-1);
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w2, optr, sizeof(w2)-1);
strncpy (w3, ptr, sizeof(w3)-1);
}
@@ -144,8 +161,9 @@ static int parse(RParse *p, const char *data, char *str) {
const char *wa[] = { w0, w1, w2, w3 };
int nw = 0;
for (i=0; i<4; i++) {
- if (wa[i][0] != '\0')
- nw++;
+ if (wa[i][0] != '\0') {
+ nw++;
+ }
}
replace (nw, wa, str);
}
diff --git a/libr/parse/p/parse_avr_pseudo.c b/libr/parse/p/parse_avr_pseudo.c
index 30215562e2..11b792d8e5 100644
--- a/libr/parse/p/parse_avr_pseudo.c
+++ b/libr/parse/p/parse_avr_pseudo.c
@@ -110,7 +110,9 @@ static int replace(int argc, const char *argv[], char *newstr) {
strcpy (newstr + k, w);
k += strlen(w) - 1;
}
- } else newstr[k] = ops[i].str[j];
+ } else {
+ newstr[k] = ops[i].str[j];
+ }
}
newstr[k] = '\0';
}
diff --git a/libr/parse/p/parse_dalvik_pseudo.c b/libr/parse/p/parse_dalvik_pseudo.c
index 9c6c4ba05a..35c330c142 100644
--- a/libr/parse/p/parse_dalvik_pseudo.c
+++ b/libr/parse/p/parse_dalvik_pseudo.c
@@ -203,7 +203,9 @@ static int replace(int argc, const char *argv[], char *newstr) {
strcpy (newstr+k, w);
k += strlen(w)-1;
}
- } else newstr[k] = ops[i].str[j];
+ } else {
+ newstr[k] = ops[i].str[j];
+ }
}
newstr[k]='\0';
}
@@ -240,8 +242,9 @@ static int parse(RParse *p, const char *data, char *str) {
}
// malloc can be slow here :?
- if (!(buf = malloc (len+1)))
+ if (!(buf = malloc (len + 1))) {
return false;
+ }
memcpy (buf, data, len+1);
r_str_trim (buf);
@@ -253,11 +256,14 @@ static int parse(RParse *p, const char *data, char *str) {
w3[0]='\0';
w4[0]='\0';
ptr = strchr (buf, ' ');
- if (!ptr)
+ if (!ptr) {
ptr = strchr (buf, '\t');
+ }
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w0, buf, sizeof (w0) - 1);
w0[sizeof(w0)-1] = '\0';
strncpy (w1, ptr, sizeof (w1) - 1);
@@ -265,11 +271,15 @@ static int parse(RParse *p, const char *data, char *str) {
optr=ptr;
ptr2 = strchr (ptr, '}');
- if (ptr2) ptr = ptr2+1;
+ if (ptr2) {
+ ptr = ptr2 + 1;
+ }
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w1, optr, sizeof (w1) - 1);
w1[sizeof(w1)-1] = '\0';
strncpy (w2, ptr, sizeof (w2) - 1);
@@ -278,7 +288,9 @@ static int parse(RParse *p, const char *data, char *str) {
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w2, optr, sizeof (w2) - 1);
w2[sizeof(w2)-1] = '\0';
strncpy (w3, ptr, sizeof (w3) - 1);
@@ -288,7 +300,9 @@ static int parse(RParse *p, const char *data, char *str) {
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w3, optr, sizeof (w3) - 1);
w3[sizeof(w3)-1] = '\0';
strncpy (w4, ptr, sizeof (w4) - 1);
@@ -301,8 +315,9 @@ static int parse(RParse *p, const char *data, char *str) {
const char *wa[] = { w0, w1, w2, w3, w4 };
int nw = 0;
for (i=0; i<4; i++) {
- if (wa[i][0] != '\0')
- nw++;
+ if (wa[i][0] != '\0') {
+ nw++;
+ }
}
replace (nw, wa, str);
{
diff --git a/libr/parse/p/parse_m68k_pseudo.c b/libr/parse/p/parse_m68k_pseudo.c
index 3b577d5571..93d3672857 100644
--- a/libr/parse/p/parse_m68k_pseudo.c
+++ b/libr/parse/p/parse_m68k_pseudo.c
@@ -132,11 +132,14 @@ static int parse(RParse *p, const char *data, char *str) {
w3[0]='\0';
w4[0]='\0';
ptr = strchr (buf, ' ');
- if (!ptr)
+ if (!ptr) {
ptr = strchr (buf, '\t');
+ }
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w0, buf, WSZ - 1);
strncpy (w1, ptr, WSZ - 1);
@@ -144,14 +147,18 @@ static int parse(RParse *p, const char *data, char *str) {
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w1, optr, WSZ - 1);
strncpy (w2, ptr, WSZ - 1);
optr=ptr;
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w2, optr, WSZ - 1);
strncpy (w3, ptr, WSZ - 1);
optr=ptr;
@@ -159,7 +166,9 @@ static int parse(RParse *p, const char *data, char *str) {
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w3, optr, WSZ - 1);
strncpy (w4, ptr, WSZ - 1);
}
diff --git a/libr/parse/p/parse_mips_pseudo.c b/libr/parse/p/parse_mips_pseudo.c
index 46abc4f9e1..87f423e3f9 100644
--- a/libr/parse/p/parse_mips_pseudo.c
+++ b/libr/parse/p/parse_mips_pseudo.c
@@ -103,7 +103,9 @@ static int replace(int argc, const char *argv[], char *newstr) {
strcpy (newstr+k, w);
k += strlen (w) - 1;
}
- } else newstr[k] = ops[i].str[j];
+ } else {
+ newstr[k] = ops[i].str[j];
+ }
}
newstr[k]='\0';
}
@@ -139,8 +141,9 @@ static int parse(RParse *p, const char *data, char *str) {
}
// malloc can be slow here :?
- if (!(buf = malloc (len+1)))
+ if (!(buf = malloc (len + 1))) {
return false;
+ }
memcpy (buf, data, len+1);
r_str_replace_char (buf, '(', ',');
@@ -154,11 +157,14 @@ static int parse(RParse *p, const char *data, char *str) {
w3[0]='\0';
w4[0]='\0';
ptr = strchr (buf, ' ');
- if (!ptr)
+ if (!ptr) {
ptr = strchr (buf, '\t');
+ }
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w0, buf, WSZ - 1);
strncpy (w1, ptr, WSZ - 1);
@@ -166,14 +172,18 @@ static int parse(RParse *p, const char *data, char *str) {
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w1, optr, WSZ - 1);
strncpy (w2, ptr, WSZ - 1);
optr=ptr;
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w2, optr, WSZ - 1);
strncpy (w3, ptr, WSZ - 1);
optr=ptr;
@@ -181,7 +191,9 @@ static int parse(RParse *p, const char *data, char *str) {
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr==' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
strncpy (w3, optr, WSZ - 1);
strncpy (w4, ptr, WSZ - 1);
}
@@ -194,8 +206,9 @@ static int parse(RParse *p, const char *data, char *str) {
const char *wa[] = { w0, w1, w2, w3, w4 };
int nw = 0;
for (i=0; i<4; i++) {
- if (wa[i][0] != '\0')
- nw++;
+ if (wa[i][0] != '\0') {
+ nw++;
+ }
}
replace (nw, wa, str);
{
@@ -272,14 +285,17 @@ static bool varsub(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data
}
/* iterate over arguments */
r_list_foreach (args, argiter, arg) {
- if (arg->delta < 10) snprintf (oldstr, sizeof (oldstr)-1,
- "[%s + %d]",
- p->anal->reg->name[R_REG_NAME_BP],
- arg->delta);
- else snprintf (oldstr, sizeof (oldstr)-1,
- "[%s + 0x%x]",
- p->anal->reg->name[R_REG_NAME_BP],
- arg->delta);
+ if (arg->delta < 10) {
+ snprintf (oldstr, sizeof (oldstr) - 1,
+ "[%s + %d]",
+ p->anal->reg->name[R_REG_NAME_BP],
+ arg->delta);
+ } else {
+ snprintf (oldstr, sizeof (oldstr) - 1,
+ "[%s + 0x%x]",
+ p->anal->reg->name[R_REG_NAME_BP],
+ arg->delta);
+ }
snprintf (newstr, sizeof (newstr)-1, "[%s + %s]",
p->anal->reg->name[R_REG_NAME_BP],
arg->name);
@@ -315,8 +331,11 @@ static bool varsub(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data
}
r_list_foreach (vars, variter, var) {
- if (var->delta < 10) snprintf (oldstr, sizeof (oldstr)-1, "[%s - %d]", bp, var->delta);
- else snprintf (oldstr, sizeof (oldstr)-1, "[%s - 0x%x]", bp, var->delta);
+ if (var->delta < 10) {
+ snprintf (oldstr, sizeof (oldstr) - 1, "[%s - %d]", bp, var->delta);
+ } else {
+ snprintf (oldstr, sizeof (oldstr) - 1, "[%s - 0x%x]", bp, var->delta);
+ }
snprintf (newstr, sizeof (newstr)-1, "[%s - %s]", bp, var->name);
if (strstr (tstr, oldstr) != NULL) {
tstr = r_str_replace (tstr, oldstr, newstr, 1);
diff --git a/libr/parse/p/parse_mreplace.c b/libr/parse/p/parse_mreplace.c
index 9a4a07a75f..b3b1fb95a5 100644
--- a/libr/parse/p/parse_mreplace.c
+++ b/libr/parse/p/parse_mreplace.c
@@ -29,7 +29,9 @@ static int assemble(RParse *p, char *data, char *str) {
if (ptr) {
*ptr = '\0';
sprintf (data, "mov %s, %s", str, ptr+1);
- } else strcpy (data, str);
+ } else {
+ strcpy (data, str);
+ }
return true;
}
diff --git a/libr/parse/p/parse_mreplace/mmemory.c b/libr/parse/p/parse_mreplace/mmemory.c
index 878b484f3d..1373a6c044 100644
--- a/libr/parse/p/parse_mreplace/mmemory.c
+++ b/libr/parse/p/parse_mreplace/mmemory.c
@@ -30,13 +30,17 @@ void memFree(memChunk *chunk) {
}
void memInit() {
mInfo = (memInfo*) malloc (sizeof (memInfo));
- if (!mInfo) return;
+ if (!mInfo) {
+ return;
+ }
memset (mInfo, 0, sizeof (memInfo));
mInfo->state = MEM_STATE_OK;
mInfo->allocated += sizeof (memInfo);
}
void memCheckState() {
- if (!mInfo) memInit();
+ if (!mInfo) {
+ memInit ();
+ }
if (mInfo->state != MEM_STATE_OK){
fprintf (stderr,"\rMemory not initialized :p\n");
exit (0);
@@ -81,7 +85,9 @@ memChunk *memString(char *string) {
void memCopy(memChunk *dest,memChunk *source) {
long nbytes;
memCheckState ();
- if ((!source->address) || (!dest->address)) return;
+ if ((!source->address) || (!dest->address)) {
+ return;
+ }
nbytes=dest->size > source->size ? source->size : dest->size;
#if DEBUG3
eprintf ("Copying %d byte(s) to dest (size %d)\n", nbytes, dest->address, dest->size);
diff --git a/libr/parse/p/parse_mreplace/mreplace.c b/libr/parse/p/parse_mreplace/mreplace.c
index 9ddb5b41a0..9df20500ca 100644
--- a/libr/parse/p/parse_mreplace/mreplace.c
+++ b/libr/parse/p/parse_mreplace/mreplace.c
@@ -30,7 +30,9 @@
int matchs(const char *string, char *pattern) {
int status = 0;
RRegex *re = r_regex_new (pattern, "");
- if (!re) return status;
+ if (!re) {
+ return status;
+ }
if (r_regex_comp (re, pattern, R_REGEX_EXTENDED|R_REGEX_NOSUB) == 0) {
status = r_regex_exec (re, string, (size_t) 0, NULL, 0)? 1: 0;
}
@@ -42,7 +44,9 @@ void sreplace(char *s,char *orig,char *rep,char multi,long dsize){
char *p;
memChunk *buffer,*string,*result;
- if(!(p = strstr (s, orig))) return;
+ if (!(p = strstr (s, orig))) {
+ return;
+ }
buffer = memReserve (dsize);
string = memString (s);
@@ -74,9 +78,15 @@ char *mreplace(char *string, char *se,char *rep) {
int status, i;
RRegex *re;
- if (!string) return "";
- if (!strlen (se)) return string;
- if (!strcmp (se,rep)) return string;
+ if (!string) {
+ return "";
+ }
+ if (!strlen (se)) {
+ return string;
+ }
+ if (!strcmp (se, rep)) {
+ return string;
+ }
temp = memStringReserve (string,INPUTLINE_BUFFER_REPLACE_SIZE);
search = memStringReserve (se,INPUTLINE_BUFFER_REPLACE_SIZE);
@@ -91,11 +101,14 @@ char *mreplace(char *string, char *se,char *rep) {
#endif
re = r_regex_new ("", 0);
- if (r_regex_comp (re, search->address, R_REGEX_EXTENDED) != 0)
- if(r_regex_comp (re, search->address, R_REGEX_EXTENDED<<1))
+ if (r_regex_comp (re, search->address, R_REGEX_EXTENDED) != 0) {
+ if (r_regex_comp (re, search->address, R_REGEX_EXTENDED << 1)) {
noMatch = 1;
- if ((status = r_regex_exec (re, string, nmatch, pm, 0)))
+ }
+ }
+ if ((status = r_regex_exec (re, string, nmatch, pm, 0))) {
noMatch = 1;
+ }
if (noMatch) {
memFree (temp);
memFree (search);
@@ -160,7 +173,9 @@ char *treplace(char *data,char *search,char *replace){
memChunk *result,*line;
//ulong resultAllocSize;
- if (!strlen(search)) return data;
+ if (!strlen (search)) {
+ return data;
+ }
#if MDEBUG2
DBG ("treplace(string,se,re)","string : %s",data);
@@ -173,12 +188,17 @@ char *treplace(char *data,char *search,char *replace){
p=data;
while (sscanf (p, "%[^\n]", line->address) == 1){
- if (p - data > strlen (data)) break;
+ if (p - data > strlen (data)) {
+ break;
+ }
newline = mreplace (line->address, search, replace);
memStrCat (result, newline);
- if (line->address && *(p + strlen (line->address))) memStrCat (result, "\n");
- else break;
+ if (line->address && *(p + strlen (line->address))) {
+ memStrCat (result, "\n");
+ } else {
+ break;
+ }
p += strlen (line->address) + 1;
}
diff --git a/libr/parse/p/parse_ppc_pseudo.c b/libr/parse/p/parse_ppc_pseudo.c
index 8818b55728..1504fab762 100644
--- a/libr/parse/p/parse_ppc_pseudo.c
+++ b/libr/parse/p/parse_ppc_pseudo.c
@@ -122,9 +122,13 @@ static int can_replace(const char *str, int idx, int max_operands) {
static const char* getspr(const char *reg) {
static char cspr[16];
ut32 spr = 0;
- if (!reg) return NULL;
+ if (!reg) {
+ return NULL;
+ }
spr = strtol(reg, NULL, 16);
- if(spr > 9999) return NULL; //just to avoid overflows..
+ if (spr > 9999) {
+ return NULL; //just to avoid overflows..
+ }
switch (spr) {
case SPR_MQ:
diff --git a/libr/parse/p/parse_sh_pseudo.c b/libr/parse/p/parse_sh_pseudo.c
index 9bb3003c85..d7db975acd 100644
--- a/libr/parse/p/parse_sh_pseudo.c
+++ b/libr/parse/p/parse_sh_pseudo.c
@@ -132,7 +132,9 @@ static int replace(int argc, const char *argv[], char *newstr) {
strcpy (newstr + k, w);
k += strlen(w) - 1;
}
- } else newstr[k] = ops[i].str[j];
+ } else {
+ newstr[k] = ops[i].str[j];
+ }
}
newstr[k] = '\0';
}
diff --git a/libr/parse/p/parse_x86_pseudo.c b/libr/parse/p/parse_x86_pseudo.c
index 3167e8a48a..095cb68400 100644
--- a/libr/parse/p/parse_x86_pseudo.c
+++ b/libr/parse/p/parse_x86_pseudo.c
@@ -181,21 +181,29 @@ static int parse (RParse *p, const char *data, char *str) {
ptr = end;
}
*ptr = '\0';
- if (ptr != end) for (++ptr; *ptr == ' '; ptr++);
+ if (ptr != end) {
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
+ }
r_str_ncpy (w0, buf, sizeof (w0));
r_str_ncpy (w1, ptr, sizeof (w1));
optr = ptr;
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr == ' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
r_str_ncpy (w1, optr, sizeof (w1));
r_str_ncpy (w2, ptr, sizeof (w2));
optr = ptr;
ptr = strchr (ptr, ',');
if (ptr) {
*ptr = '\0';
- for (++ptr; *ptr == ' '; ptr++);
+ for (++ptr; *ptr == ' '; ptr++) {
+ ;
+ }
r_str_ncpy (w2, optr, sizeof (w2));
r_str_ncpy (w3, ptr, sizeof (w3));
}
diff --git a/libr/parse/p/parse_z80_pseudo.c b/libr/parse/p/parse_z80_pseudo.c
index 6b1ebecbf3..a962ba65c4 100644
--- a/libr/parse/p/parse_z80_pseudo.c
+++ b/libr/parse/p/parse_z80_pseudo.c
@@ -52,7 +52,9 @@ static int replace(int argc, const char *argv[], char *newstr) {
strcpy (newstr+k, w);
k += strlen(w)-1;
}
- } else newstr[k] = ops[i].str[j];
+ } else {
+ newstr[k] = ops[i].str[j];
+ }
}
newstr[k]='\0';
}
diff --git a/libr/parse/parse.c b/libr/parse/parse.c
index 84008ffdef..88c13a6975 100644
--- a/libr/parse/parse.c
+++ b/libr/parse/parse.c
@@ -125,13 +125,17 @@ static char *findNextNumber(char *op) {
if (p[0] && p[1] == ';') {
// "\x1b[%d;2;%d;%d;%dm", fgbg, r, g, b
// "\x1b[%d;5;%dm", fgbg, rgb (r, g, b)
- for (; p[0] && p[1] && p[0] != 0x1b && p[1] != '\\'; p++);
+ for (; p[0] && p[1] && p[0] != 0x1b && p[1] != '\\'; p++) {
+ ;
+ }
if (p[0] && p[1] == '\\') {
p++;
}
} else {
// "\x1b[%dm", 30 + k
- for (; *p && *p != 'J' && *p != 'm' && *p != 'H'; p++);
+ for (; *p && *p != 'J' && *p != 'm' && *p != 'H'; p++) {
+ ;
+ }
if (*p) {
p++;
if (!*p) {
@@ -156,7 +160,9 @@ static char *findNextNumber(char *op) {
}
if (!IS_DIGIT (*p)) {
char *t = p;
- for (; *t && *t != ']'; t++);
+ for (; *t && *t != ']'; t++) {
+ ;
+ }
if (*t == ']') {
continue;
}
@@ -183,8 +189,12 @@ static int filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_
bool x86 = false;
bool computed = false;
if (p && p->cur && p->cur->name) {
- if (strstr (p->cur->name, "x86")) x86 = true;
- if (strstr (p->cur->name, "m68k")) x86 = true;
+ if (strstr (p->cur->name, "x86")) {
+ x86 = true;
+ }
+ if (strstr (p->cur->name, "m68k")) {
+ x86 = true;
+ }
}
if (!data || !p) {
return 0;
@@ -218,7 +228,9 @@ static int filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_
// eprintf ("(%s) (%c)\n", optr, *ptr2);
}
} else {
- for (ptr2 = ptr; *ptr2 && (*ptr2 != ']' && (*ptr2 != '\x1b') && !IS_SEPARATOR (*ptr2)); ptr2++);
+ for (ptr2 = ptr; *ptr2 && (*ptr2 != ']' && (*ptr2 != '\x1b') && !IS_SEPARATOR (*ptr2)); ptr2++) {
+ ;
+ }
}
off = r_num_math (NULL, ptr);
if (off >= p->minval) {
@@ -269,7 +281,9 @@ static int filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_
if (computed && ptr != ptr2 && *ptr) {
if (*ptr2 == ']') {
ptr2++;
- for (ptr--; ptr > data && *ptr != '['; ptr--);
+ for (ptr--; ptr > data && *ptr != '['; ptr--) {
+ ;
+ }
if (ptr == data) {
ptr = ptr_backup;
}
@@ -297,7 +311,9 @@ static int filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_
}
while (*ptr_right) {
if (*ptr_right == 0x1b) {
- while (*ptr_right && *ptr_right != 'm') ptr_right++;
+ while (*ptr_right && *ptr_right != 'm') {
+ ptr_right++;
+ }
if (*ptr_right) {
ptr_right++;
}
@@ -316,7 +332,9 @@ static int filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_
if (ptr_left < str) {
break;
}
- for (; ptr_esc >= str && *ptr_esc != 0x1b; ptr_esc--);
+ for (; ptr_esc >= str && *ptr_esc != 0x1b; ptr_esc--) {
+ ;
+ }
if (ptr_esc < str) {
ptr_esc = ptr_end - flag_len + 1;
}
diff --git a/libr/reg/cond.c b/libr/reg/cond.c
index 473c30f6c0..cb0ae1c965 100644
--- a/libr/reg/cond.c
+++ b/libr/reg/cond.c
@@ -32,8 +32,9 @@ R_API RRegItem *r_reg_cond_get(RReg *reg, const char *name) {
RRegItem *r;
if (name) {
r_list_foreach (reg->regset[i].regs, iter, r) {
- if (r->flags && !strcmp (name, r->flags))
+ if (r->flags && !strcmp (name, r->flags)) {
return r;
+ }
}
}
return NULL;
@@ -47,25 +48,52 @@ R_API const char *r_reg_cond_to_string(int n) {
const char *cs[] = {
"eq", "ne", "cf", "neg", "of", "hi", "he",
"lo", "loe", "ge", "gt", "lt", "le"};
- if (n < 0 || (n > (sizeof (cs) / sizeof (*cs)) - 1))
+ if (n < 0 || (n > (sizeof (cs) / sizeof (*cs)) - 1)) {
return NULL;
+ }
return cs[n];
}
R_API int r_reg_cond_from_string(const char *str) {
- if (!strcmp (str, "eq")) return R_REG_COND_EQ;
- if (!strcmp (str, "ne")) return R_REG_COND_NE;
- if (!strcmp (str, "cf")) return R_REG_COND_CF;
- if (!strcmp (str, "neg")) return R_REG_COND_NEG;
- if (!strcmp (str, "of")) return R_REG_COND_OF;
- if (!strcmp (str, "hi")) return R_REG_COND_HI;
- if (!strcmp (str, "he")) return R_REG_COND_HE;
- if (!strcmp (str, "lo")) return R_REG_COND_LO;
- if (!strcmp (str, "loe")) return R_REG_COND_LOE;
- if (!strcmp (str, "ge")) return R_REG_COND_GE;
- if (!strcmp (str, "gt")) return R_REG_COND_GT;
- if (!strcmp (str, "lt")) return R_REG_COND_LT;
- if (!strcmp (str, "le")) return R_REG_COND_LE;
+ if (!strcmp (str, "eq")) {
+ return R_REG_COND_EQ;
+ }
+ if (!strcmp (str, "ne")) {
+ return R_REG_COND_NE;
+ }
+ if (!strcmp (str, "cf")) {
+ return R_REG_COND_CF;
+ }
+ if (!strcmp (str, "neg")) {
+ return R_REG_COND_NEG;
+ }
+ if (!strcmp (str, "of")) {
+ return R_REG_COND_OF;
+ }
+ if (!strcmp (str, "hi")) {
+ return R_REG_COND_HI;
+ }
+ if (!strcmp (str, "he")) {
+ return R_REG_COND_HE;
+ }
+ if (!strcmp (str, "lo")) {
+ return R_REG_COND_LO;
+ }
+ if (!strcmp (str, "loe")) {
+ return R_REG_COND_LOE;
+ }
+ if (!strcmp (str, "ge")) {
+ return R_REG_COND_GE;
+ }
+ if (!strcmp (str, "gt")) {
+ return R_REG_COND_GT;
+ }
+ if (!strcmp (str, "lt")) {
+ return R_REG_COND_LT;
+ }
+ if (!strcmp (str, "le")) {
+ return R_REG_COND_LE;
+ }
eprintf ("| Usage: drc [condition]\n"
"| eq equal\n"
"| ne not equal\n"
@@ -115,8 +143,12 @@ R_API int r_reg_cond(RReg *r, int type) {
}
R_API RRegFlags *r_reg_cond_retrieve(RReg *r, RRegFlags *f) {
- if (!f) f = R_NEW0 (RRegFlags);
- if (!f) return NULL;
+ if (!f) {
+ f = R_NEW0 (RRegFlags);
+ }
+ if (!f) {
+ return NULL;
+ }
f->s = r_reg_cond_get_value (r, "sign"); // sign, negate flag, less than zero
f->z = r_reg_cond_get_value (r, "zero"); // zero flag
f->c = r_reg_cond_get_value (r, "carry"); // carry flag
diff --git a/libr/search/aes-find.c b/libr/search/aes-find.c
index 5c752e0a22..8e39d6dbce 100644
--- a/libr/search/aes-find.c
+++ b/libr/search/aes-find.c
@@ -39,10 +39,12 @@ static int aes_key_test(const unsigned char *buf) {
R_API int r_search_aes_update(RSearch *s, ut64 from, const ut8 *buf, int len) {
int i, last = len-31;
- if (last>0)
- for (i=0; i 0) {
+ for (i = 0; i < last; i++) {
+ if (aes_key_test (buf + i)) {
+ return i;
+ }
+ }
}
return -1;
}
diff --git a/libr/search/bytepat.c b/libr/search/bytepat.c
index 6dbf803b5d..706b31be8d 100644
--- a/libr/search/bytepat.c
+++ b/libr/search/bytepat.c
@@ -19,7 +19,9 @@ typedef struct _fnditem {
static fnditem* init_fi() {
fnditem* n;
n = (fnditem*) malloc (sizeof (fnditem));
- if (!n) return NULL;
+ if (!n) {
+ return NULL;
+ }
n->next = NULL;
return n;
}
@@ -38,7 +40,9 @@ static void fini_fi(fnditem* fi) {
static void add_fi (fnditem* n, unsigned char* blk, int patlen) {
fnditem* p;
- for (p=n; p->next!=NULL; p=p->next);
+ for (p = n; p->next != NULL; p = p->next) {
+ ;
+ }
p->next = (fnditem*) malloc (sizeof (fnditem));
p = p->next;
memcpy (p->str, blk, patlen);
@@ -47,9 +51,11 @@ static void add_fi (fnditem* n, unsigned char* blk, int patlen) {
static int is_fi_present(fnditem* n, unsigned char* blk , int patlen) {
fnditem* p;
- for (p=n; p->next!=NULL; p=p->next)
- if (!memcmp (blk, p->str, patlen))
+ for (p = n; p->next != NULL; p = p->next) {
+ if (!memcmp (blk, p->str, patlen)) {
return true;
+ }
+ }
return false;
}
@@ -108,8 +114,9 @@ R_API int r_search_pattern(RSearch *s, ut64 from, ut64 to) {
add_fi (root, sblk, patlen);
pcnt++;
eprintf ("\nbytes: %d: ", pcnt);
- for (k = 0; k0)
- eprintf ("\ncount: %d: %d\n", pcnt, moar+1);
+ if (moar > 0) {
+ eprintf ("\ncount: %d: %d\n", pcnt, moar + 1);
+ }
bproc += rb;
}
bact += (moar > 0)? patlen: 1;
diff --git a/libr/search/keyword.c b/libr/search/keyword.c
index 0e3fa9c6e5..82408c1b30 100644
--- a/libr/search/keyword.c
+++ b/libr/search/keyword.c
@@ -5,18 +5,22 @@
static int ignoreMask(const ut8 *bm, int len) {
int i;
for (i=0; itype = R_SEARCH_KEYWORD_TYPE_BINARY;
kw->data = (void *) data;
kw->keyword_length = kwlen;
@@ -57,7 +61,9 @@ R_API RSearchKeyword* r_search_keyword_new_str(const char *kwbuf, const char *bm
if (bmstr) {
bmbuf = malloc (strlen (bmstr)+1);
- if (!bmbuf) return NULL;
+ if (!bmbuf) {
+ return NULL;
+ }
bmlen = r_hex_str2bin (bmstr, bmbuf);
if (bmlen < 1) {
free (bmbuf);
@@ -83,7 +89,9 @@ R_API RSearchKeyword* r_search_keyword_new_wide(const char *kwbuf, const char *b
if (bmstr) {
bmbuf = malloc (strlen (bmstr)+1);
- if (!bmbuf) return NULL;
+ if (!bmbuf) {
+ return NULL;
+ }
bmlen = r_hex_str2bin (bmstr, bmbuf);
if (bmlen < 1) {
free(bmbuf);
@@ -94,10 +102,11 @@ R_API RSearchKeyword* r_search_keyword_new_wide(const char *kwbuf, const char *b
len = strlen(kwbuf);
str = malloc((len+1)*2);
for (p2=kwbuf, p=str; *p2; p+=2, p2++) {
- if (ignore_case)
+ if (ignore_case) {
p[0] = tolower((const unsigned char)*p2);
- else
+ } else {
p[0] = *p2;
+ }
p[1] = 0;
}
@@ -115,12 +124,14 @@ R_API RSearchKeyword* r_search_keyword_new_hex(const char *kwstr, const char *bm
ut8 *kwbuf, *bmbuf;
int kwlen, bmlen = 0;
- if (!kwstr)
+ if (!kwstr) {
return NULL;
+ }
kwbuf = malloc (strlen (kwstr)+1);
- if (!kwbuf)
+ if (!kwbuf) {
return NULL;
+ }
kwlen = r_hex_str2bin (kwstr, kwbuf);
if (kwlen < 1) {
@@ -159,10 +170,12 @@ R_API RSearchKeyword* r_search_keyword_new_hexmask(const char *kwstr, const char
bm = malloc (len + 4);
if (kw != NULL && bm != NULL) {
len = r_hex_str2binmask (kwstr, (ut8*)kw, (ut8*)bm);
- if (len<0)
- len = -len -1;
- if (len>0)
+ if (len < 0) {
+ len = -len - 1;
+ }
+ if (len > 0) {
ks = r_search_keyword_new (kw, len, bm, len, data);
+ }
}
free (kw);
free (bm);
@@ -175,28 +188,34 @@ R_API RSearchKeyword *r_search_keyword_new_regexp (const char *str, const char *
RSearchKeyword *kw;
int i = 0, start, length;
- while (isspace((const unsigned char)str[i]))
+ while (isspace ((const unsigned char)str[i])) {
i++;
+ }
- if (str[i++] != '/')
+ if (str[i++] != '/') {
return NULL;
+ }
/* Find the fist non backslash-escaped slash */
for (start = i; str[i]; i++) {
- if (str[i] == '/' && str[i-1] != '\\')
+ if (str[i] == '/' && str[i - 1] != '\\') {
break;
+ }
}
- if (str[i++] != '/')
+ if (str[i++] != '/') {
return NULL;
+ }
length = i - start - 1;
- if ((length > 128) || (length < 1))
+ if ((length > 128) || (length < 1)) {
return NULL;
+ }
kw = R_NEW0(RSearchKeyword);
- if (!kw)
+ if (!kw) {
return NULL;
+ }
kw->bin_keyword = malloc (length+1);
if (!kw->bin_keyword) {
diff --git a/libr/search/regexp.c b/libr/search/regexp.c
index ac98df1d52..595be71543 100644
--- a/libr/search/regexp.c
+++ b/libr/search/regexp.c
@@ -14,8 +14,9 @@ R_API int r_search_regexp_update(RSearch *s, ut64 from, const ut8 *buf, int len)
r_list_foreach (s->kws, iter, kw) {
int reflags = R_REGEX_EXTENDED;
- if (kw->icase)
+ if (kw->icase) {
reflags |= R_REGEX_ICASE;
+ }
if (r_regex_comp (&compiled, (char *)kw->bin_keyword, reflags)) {
eprintf ("Cannot compile '%s' regexp\n", kw->bin_keyword);
diff --git a/libr/search/rsa-find.c b/libr/search/rsa-find.c
index b8fd7aef10..d0bbbe28aa 100644
--- a/libr/search/rsa-find.c
+++ b/libr/search/rsa-find.c
@@ -22,8 +22,9 @@ static const ut8* parse_next_rsa_field(const ut8* start, ut32 *len) {
} else {
int i;
const int lensize = start[1] & 127;
- for (i=0; i < lensize; i++)
- *len = (*len << 8) | start[2+i];
+ for (i = 0; i < lensize; i++) {
+ *len = (*len << 8) | start[2 + i];
+ }
return start + 2 + lensize;
}
}
@@ -36,11 +37,14 @@ static int check_rsa_fields(const ut8* start) {
// skip sequence field
ut8 const* ptr = parse_next_rsa_field (start, &len);
- if (!len || len > 1024)
+ if (!len || len > 1024) {
return false;
- for (i = 0; i < NB_PRIV_FIELDS; i++)
- if (!(ptr = parse_next_rsa_field (ptr, &len)))
+ }
+ for (i = 0; i < NB_PRIV_FIELDS; i++) {
+ if (!(ptr = parse_next_rsa_field (ptr, &len))) {
return false;
+ }
+ }
return true;
}
@@ -54,8 +58,9 @@ R_API int r_search_rsa_update(RSearch* s, ut64 from, const ut8 *buf, int len) {
}
for (i = 0; i < len - sizeof (versionmarker); i++) {
- if (memcmp (&buf[i], versionmarker, sizeof (versionmarker)))
+ if (memcmp (&buf[i], versionmarker, sizeof (versionmarker))) {
continue;
+ }
index = 0;
for (k=i; k != 0 && k > i - 20; k--) {
@@ -65,11 +70,13 @@ R_API int r_search_rsa_update(RSearch* s, ut64 from, const ut8 *buf, int len) {
}
}
- if (!index)
+ if (!index) {
continue;
+ }
- if (check_rsa_fields(buf + index))
+ if (check_rsa_fields (buf + index)) {
return i;
+ }
}
return -1;
}
diff --git a/libr/search/search.c b/libr/search/search.c
index 5da690edbb..15655cc89e 100644
--- a/libr/search/search.c
+++ b/libr/search/search.c
@@ -17,7 +17,9 @@ typedef struct {
R_API RSearch *r_search_new(int mode) {
RSearch *s = R_NEW0 (RSearch);
- if (!s) return NULL;
+ if (!s) {
+ return NULL;
+ }
if (!r_search_set_mode (s, mode)) {
free (s);
eprintf ("Cannot init search for mode %d\n", mode);
@@ -60,8 +62,9 @@ R_API RSearch *r_search_free(RSearch *s) {
}
R_API int r_search_set_string_limits(RSearch *s, ut32 min, ut32 max) {
- if (max < min)
+ if (max < min) {
return false;
+ }
s->string_min = min;
s->string_max = max;
return true;
@@ -336,7 +339,9 @@ static bool brute_force_match(RSearch *s, RSearchKeyword *kw, const ut8 *buf, in
a = tolower (a);
b = tolower (b);
}
- if ((a & kw->bin_binmask[k]) != (b & kw->bin_binmask[k])) break;
+ if ((a & kw->bin_binmask[k]) != (b & kw->bin_binmask[k])) {
+ break;
+ }
}
} else if (kw->icase) {
while (j < kw->keyword_length &&
diff --git a/libr/socket/http.c b/libr/socket/http.c
index 6fc8081226..53510ebc5e 100644
--- a/libr/socket/http.c
+++ b/libr/socket/http.c
@@ -7,25 +7,34 @@ static char *r_socket_http_answer (RSocket *s, int *code, int *rlen) {
const char *p;
int ret, olen, len = 0, bufsz = 32768, delta = 0;
char *dn, *res, *buf = malloc (bufsz + 32); // XXX: use r_buffer here
- if (!buf) return NULL;
+ if (!buf) {
+ return NULL;
+ }
r_socket_block_time (s, 1, 5);
res = NULL;
olen = r_socket_read_block (s, (unsigned char*) buf, bufsz);
- if (olen < 1) goto fail;
+ if (olen < 1) {
+ goto fail;
+ }
buf[olen] = 0;
if ((dn = (char*)r_str_casestr (buf, "\n\n"))) {
delta += 2;
} else if ((dn = (char*)r_str_casestr (buf, "\r\n\r\n"))) {
delta += 4;
- } else goto fail;
+ } else {
+ goto fail;
+ }
olen -= delta;
*dn = 0; // chop headers
/* Parse Len */
p = r_str_casestr (buf, "Content-Length: ");
- if (p) len = atoi (p+16);
- else len = olen - (dn - buf);
+ if (p) {
+ len = atoi (p + 16);
+ } else {
+ len = olen - (dn - buf);
+ }
if (len >0) {
if (len > olen) {
@@ -34,8 +43,9 @@ static char *r_socket_http_answer (RSocket *s, int *code, int *rlen) {
do {
ret = r_socket_read_block (s,
(ut8*) res+olen, len-olen);
- if (ret < 1)
+ if (ret < 1) {
break;
+ }
olen += ret;
} while (olen 0) {
hr->s = r_socket_accept_timeout (s, 1);
} else {
@@ -23,8 +25,9 @@ R_API RSocketHTTPRequest *r_socket_http_accept (RSocket *s, int accept_timeout,
free (hr);
return NULL;
}
- if (timeout>0)
+ if (timeout > 0) {
r_socket_block_time (hr->s, 1, timeout);
+ }
for (;;) {
#if __WINDOWS__
if (breaked)
@@ -46,11 +49,15 @@ R_API RSocketHTTPRequest *r_socket_http_accept (RSocket *s, int accept_timeout,
return NULL;
}
p = strchr (buf, ' ');
- if (p) *p = 0;
+ if (p) {
+ *p = 0;
+ }
hr->method = strdup (buf);
if (p) {
q = strstr (p+1, " HTTP"); //strchr (p+1, ' ');
- if (q) *q = 0;
+ if (q) {
+ *q = 0;
+ }
hr->path = strdup (p+1);
}
} else {
@@ -85,41 +92,60 @@ R_API void r_socket_http_response (RSocketHTTPRequest *rs, int code, const char
code==302?"Found":
code==404?"not found":
"UNKNOWN";
- if (len<1) len = out? strlen (out): 0;
- if (!headers) headers = "";
+ if (len < 1) {
+ len = out ? strlen (out) : 0;
+ }
+ if (!headers) {
+ headers = "";
+ }
r_socket_printf (rs->s, "HTTP/1.0 %d %s\r\n%s"
"Connection: close\r\nContent-Length: %d\r\n\r\n",
code, strcode, headers, len);
- if (out && len>0) r_socket_write (rs->s, (void*)out, len);
+ if (out && len > 0) {
+ r_socket_write (rs->s, (void *)out, len);
+ }
}
R_API ut8 *r_socket_http_handle_upload(const ut8 *str, int len, int *retlen) {
- if (retlen)
+ if (retlen) {
*retlen = 0;
+ }
if (!strncmp ((const char *)str, "------------------------------", 10)) {
int datalen;
char *ret;
const char *data, *token = (const char *)str+10;
const char *end = strchr (token, '\n');
- if (!end)
+ if (!end) {
return NULL;
+ }
data = strstr (end, "Content-Disposition: form-data; ");
if (data) {
data = strchr (data, '\n');
- if (data) data = strchr (data+1, '\n');
+ if (data) {
+ data = strchr (data + 1, '\n');
+ }
}
if (data) {
- while (*data==10 || *data==13) data++;
+ while (*data == 10 || *data == 13) {
+ data++;
+ }
end = (const char *)str+len-40;
- while (*end=='-') end--;
- if (*end==10 || *end==13) end--;
+ while (*end == '-') {
+ end--;
+ }
+ if (*end == 10 || *end == 13) {
+ end--;
+ }
datalen = (size_t)(end-data);
ret = malloc (datalen+1);
- if (!ret) return NULL;
+ if (!ret) {
+ return NULL;
+ }
memcpy (ret, data, datalen);
ret[datalen] = 0;
- if (retlen)
+ if (retlen) {
*retlen = datalen;
+ }
return (ut8*)ret;
}
}
diff --git a/libr/socket/proc.c b/libr/socket/proc.c
index 082363c902..bf6692136b 100644
--- a/libr/socket/proc.c
+++ b/libr/socket/proc.c
@@ -22,26 +22,31 @@ R_API struct r_socket_proc_t *r_socket_proc_open(char* const argv[]) {
const int flags = 0; //O_NONBLOCK|O_CLOEXEC;
#endif
- if (!sp)
+ if (!sp) {
return NULL;
+ }
if (pipe (sp->fd0)==-1) {
perror ("pipe");
goto error;
}
- if (fcntl (sp->fd0[0], flags) < 0)
+ if (fcntl (sp->fd0[0], flags) < 0) {
goto error;
- if (fcntl (sp->fd0[1], flags) < 0)
+ }
+ if (fcntl (sp->fd0[1], flags) < 0) {
goto error;
+ }
if (pipe (sp->fd1)==-1) {
perror ("pipe");
goto error;
}
- if (fcntl (sp->fd1[0], flags) < 0)
+ if (fcntl (sp->fd1[0], flags) < 0) {
goto error;
- if (fcntl (sp->fd1[1], flags) < 0)
+ }
+ if (fcntl (sp->fd1[1], flags) < 0) {
goto error;
+ }
sp->pid = r_sys_fork ();
switch (sp->pid) {
diff --git a/libr/socket/r2pipe.c b/libr/socket/r2pipe.c
index 7ddcf9d037..7d7c6887ff 100644
--- a/libr/socket/r2pipe.c
+++ b/libr/socket/r2pipe.c
@@ -18,7 +18,9 @@ static void env(const char *s, int f) {
#endif
R_API int r2p_close(R2Pipe *r2p) {
- if (!r2p) return 0;
+ if (!r2p) {
+ return 0;
+ }
#if __WINDOWS__ && !defined(__CYGWIN__)
if (r2p->pipe) {
CloseHandle (r2p->pipe);
@@ -231,10 +233,14 @@ R_API int r2p_write(R2Pipe *r2p, const char *str) {
R_API char *r2p_read(R2Pipe *r2p) {
int bufsz = 0;
char *buf = NULL;
- if (!r2p) return NULL;
+ if (!r2p) {
+ return NULL;
+ }
bufsz = 4096;
buf = calloc (1, bufsz);
- if (!buf) return NULL;
+ if (!buf) {
+ return NULL;
+ }
#if __WINDOWS__ && !defined(__CYGWIN__)
BOOL bSuccess = FALSE;
DWORD dwRead = 0;
diff --git a/libr/socket/run.c b/libr/socket/run.c
index f505a70671..ca312f0046 100644
--- a/libr/socket/run.c
+++ b/libr/socket/run.c
@@ -247,9 +247,10 @@ static void setASLR(RRunProfile *r, int enabled) {
setRVA ("0\n");
#else
#if HAVE_DECL_ADDR_NO_RANDOMIZE
- if (personality (ADDR_NO_RANDOMIZE) == -1)
+ if (personality (ADDR_NO_RANDOMIZE) == -1) {
#endif
setRVA ("0\n");
+ }
#endif
}
#elif __APPLE__
@@ -451,17 +452,27 @@ R_API bool r_run_parseline(RRunProfile *p, char *b) {
if (!e) {
return 0;
}
- if (!strcmp (b, "program")) p->_args[0] = p->_program = strdup (e);
- else if (!strcmp (b, "system")) p->_system = strdup (e);
- else if (!strcmp (b, "runlib")) p->_runlib = strdup (e);
- else if (!strcmp (b, "runlib.fcn")) p->_runlib_fcn = strdup (e);
- else if (!strcmp (b, "aslr")) p->_aslr = parseBool (e);
- else if (!strcmp (b, "pid")) p->_pid = atoi (e);
- else if (!strcmp (b, "pidfile")) p->_pidfile = strdup (e);
- else if (!strcmp (b, "connect")) p->_connect = strdup (e);
- else if (!strcmp (b, "listen")) p->_listen = strdup (e);
- else if (!strcmp (b, "pty")) p->_pty = parseBool (e);
- else if (!strcmp (b, "stdio")) {
+ if (!strcmp (b, "program")) {
+ p->_args[0] = p->_program = strdup (e);
+ } else if (!strcmp (b, "system")) {
+ p->_system = strdup (e);
+ } else if (!strcmp (b, "runlib")) {
+ p->_runlib = strdup (e);
+ } else if (!strcmp (b, "runlib.fcn")) {
+ p->_runlib_fcn = strdup (e);
+ } else if (!strcmp (b, "aslr")) {
+ p->_aslr = parseBool (e);
+ } else if (!strcmp (b, "pid")) {
+ p->_pid = atoi (e);
+ } else if (!strcmp (b, "pidfile")) {
+ p->_pidfile = strdup (e);
+ } else if (!strcmp (b, "connect")) {
+ p->_connect = strdup (e);
+ } else if (!strcmp (b, "listen")) {
+ p->_listen = strdup (e);
+ } else if (!strcmp (b, "pty")) {
+ p->_pty = parseBool (e);
+ } else if (!strcmp (b, "stdio")) {
if (e[0] == '!') {
p->_stdio = strdup (e);
} else {
@@ -469,32 +480,55 @@ R_API bool r_run_parseline(RRunProfile *p, char *b) {
p->_stderr = strdup (e);
p->_stdin = strdup (e);
}
- }
- else if (!strcmp (b, "stdout")) p->_stdout = strdup (e);
- else if (!strcmp (b, "stdin")) p->_stdin = strdup (e);
- else if (!strcmp (b, "stderr")) p->_stderr = strdup (e);
- else if (!strcmp (b, "input")) p->_input = strdup (e);
- else if (!strcmp (b, "chdir")) p->_chgdir = strdup (e);
- else if (!strcmp (b, "core")) p->_docore = parseBool (e);
- else if (!strcmp (b, "fork")) p->_dofork = parseBool (e);
- else if (!strcmp (b, "sleep")) p->_r2sleep = atoi (e);
- else if (!strcmp (b, "maxstack")) p->_maxstack = atoi (e);
- else if (!strcmp (b, "maxproc")) p->_maxproc = atoi (e);
- else if (!strcmp (b, "maxfd")) p->_maxfd = atoi (e);
- else if (!strcmp (b, "bits")) p->_bits = atoi (e);
- else if (!strcmp (b, "chroot")) p->_chroot = strdup (e);
- else if (!strcmp (b, "libpath")) p->_libpath = strdup (e);
- else if (!strcmp (b, "preload")) p->_preload = strdup (e);
- else if (!strcmp (b, "r2preload")) p->_r2preload = parseBool (e);
- else if (!strcmp (b, "r2preweb")) r_sys_setenv ("RARUN2_WEB", "yes");
- else if (!strcmp (b, "setuid")) p->_setuid = strdup (e);
- else if (!strcmp (b, "seteuid")) p->_seteuid = strdup (e);
- else if (!strcmp (b, "setgid")) p->_setgid = strdup (e);
- else if (!strcmp (b, "setegid")) p->_setegid = strdup (e);
- else if (!strcmp (b, "nice")) p->_nice = atoi (e);
- else if (!strcmp (b, "timeout")) p->_timeout = atoi (e);
- else if (!strcmp (b, "timeoutsig")) p->_timeout_sig = r_signal_from_string (e);
- else if (!memcmp (b, "arg", 3)) {
+ } else if (!strcmp (b, "stdout")) {
+ p->_stdout = strdup (e);
+ } else if (!strcmp (b, "stdin")) {
+ p->_stdin = strdup (e);
+ } else if (!strcmp (b, "stderr")) {
+ p->_stderr = strdup (e);
+ } else if (!strcmp (b, "input")) {
+ p->_input = strdup (e);
+ } else if (!strcmp (b, "chdir")) {
+ p->_chgdir = strdup (e);
+ } else if (!strcmp (b, "core")) {
+ p->_docore = parseBool (e);
+ } else if (!strcmp (b, "fork")) {
+ p->_dofork = parseBool (e);
+ } else if (!strcmp (b, "sleep")) {
+ p->_r2sleep = atoi (e);
+ } else if (!strcmp (b, "maxstack")) {
+ p->_maxstack = atoi (e);
+ } else if (!strcmp (b, "maxproc")) {
+ p->_maxproc = atoi (e);
+ } else if (!strcmp (b, "maxfd")) {
+ p->_maxfd = atoi (e);
+ } else if (!strcmp (b, "bits")) {
+ p->_bits = atoi (e);
+ } else if (!strcmp (b, "chroot")) {
+ p->_chroot = strdup (e);
+ } else if (!strcmp (b, "libpath")) {
+ p->_libpath = strdup (e);
+ } else if (!strcmp (b, "preload")) {
+ p->_preload = strdup (e);
+ } else if (!strcmp (b, "r2preload")) {
+ p->_r2preload = parseBool (e);
+ } else if (!strcmp (b, "r2preweb")) {
+ r_sys_setenv ("RARUN2_WEB", "yes");
+ } else if (!strcmp (b, "setuid")) {
+ p->_setuid = strdup (e);
+ } else if (!strcmp (b, "seteuid")) {
+ p->_seteuid = strdup (e);
+ } else if (!strcmp (b, "setgid")) {
+ p->_setgid = strdup (e);
+ } else if (!strcmp (b, "setegid")) {
+ p->_setegid = strdup (e);
+ } else if (!strcmp (b, "nice")) {
+ p->_nice = atoi (e);
+ } else if (!strcmp (b, "timeout")) {
+ p->_timeout = atoi (e);
+ } else if (!strcmp (b, "timeoutsig")) {
+ p->_timeout_sig = r_signal_from_string (e);
+ } else if (!memcmp (b, "arg", 3)) {
int n = atoi (b + 3);
if (n >= 0 && n < R_RUN_PROFILE_NARGS) {
p->_args[n] = getstr (e);
@@ -522,8 +556,12 @@ R_API bool r_run_parseline(RRunProfile *p, char *b) {
if (p) {
*p++ = 0;
len = strlen(p);
- if (p[len-1] == '\n') p[len-1] = 0;
- if (p[len-2] == '\r') p[len-2] = 0;
+ if (p[len - 1] == '\n') {
+ p[len - 1] = 0;
+ }
+ if (p[len - 2] == '\r') {
+ p[len - 2] = 0;
+ }
r_sys_setenv (buf, p);
}
}
@@ -734,18 +772,22 @@ R_API int r_run_config_env(RRunProfile *p) {
if (handle_redirection (p->_stderr, false, false, true) != 0) {
return 1;
}
- if (p->_aslr != -1)
+ if (p->_aslr != -1) {
setASLR (p, p->_aslr);
+ }
#if __UNIX__
set_limit (p->_docore, RLIMIT_CORE, RLIM_INFINITY);
- if (p->_maxfd)
+ if (p->_maxfd) {
set_limit (p->_maxfd, RLIMIT_NOFILE, p->_maxfd);
+ }
#ifdef RLIMIT_NPROC
- if (p->_maxproc)
+ if (p->_maxproc) {
set_limit (p->_maxproc, RLIMIT_NPROC, p->_maxproc);
+ }
#endif
- if (p->_maxstack)
+ if (p->_maxstack) {
set_limit (p->_maxstack, RLIMIT_STACK, p->_maxstack);
+ }
#else
if (p->_docore || p->_maxfd || p->_maxproc || p->_maxstack)
eprintf ("Warning: setrlimits not supported for this platform\n");
@@ -1033,12 +1075,17 @@ R_API int r_run_start(RRunProfile *p) {
}
#if __UNIX__
// XXX HACK close all non-tty fds
- { int i; for (i=3; i<10; i++) close (i); }
+ { int i;
+ for (i = 3; i < 10; i++) {
+ close (i);
+ }
+ }
// TODO: use posix_spawn
if (p->_setgid) {
int ret = setgid (atoi (p->_setgid));
- if (ret < 0)
+ if (ret < 0) {
return 1;
+ }
}
if (p->_pid) {
eprintf ("PID: %d\n", getpid ());
diff --git a/libr/socket/socket.c b/libr/socket/socket.c
index a066a3fbae..ec047447e7 100644
--- a/libr/socket/socket.c
+++ b/libr/socket/socket.c
@@ -182,7 +182,9 @@ R_API int r_socket_unix_listen (RSocket *s, const char *file) {
R_API RSocket *r_socket_new (int is_ssl) {
RSocket *s = R_NEW0 (RSocket);
- if (!s) return NULL;
+ if (!s) {
+ return NULL;
+ }
s->is_ssl = is_ssl;
s->port = 0;
#if __UNIX_
@@ -434,7 +436,9 @@ R_API int r_socket_close_fd (RSocket *s) {
/* shutdown the socket and close the file descriptor */
R_API int r_socket_close (RSocket *s) {
int ret = false;
- if (!s) return false;
+ if (!s) {
+ return false;
+ }
if (s->fd != -1) {
#if __UNIX__ || defined(__CYGWIN__)
shutdown (s->fd, SHUT_RDWR);
@@ -465,10 +469,12 @@ R_API int r_socket_free (RSocket *s) {
int res = r_socket_close (s);
#if HAVE_LIB_SSL
if (s->is_ssl) {
- if (s->sfd)
+ if (s->sfd) {
SSL_free (s->sfd);
- if (s->ctx)
+ }
+ if (s->ctx) {
SSL_CTX_free (s->ctx);
+ }
}
#endif
free (s);
@@ -477,8 +483,9 @@ R_API int r_socket_free (RSocket *s) {
R_API int r_socket_port_by_name(const char *name) {
struct servent *p = getservbyname (name, "tcp");
- if (p && p->s_port)
+ if (p && p->s_port) {
return ntohs (p->s_port);
+ }
return r_num_get (NULL, name);
}
@@ -498,8 +505,9 @@ R_API bool r_socket_listen (RSocket *s, const char *port, const char *certfile)
return false;
}
#endif
- if ((s->fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP))<0)
+ if ((s->fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
return false;
+ }
#if __UNIX__ || defined(__CYGWIN__)
linger.l_onoff = 1;
linger.l_linger = 1;
@@ -510,12 +518,14 @@ R_API bool r_socket_listen (RSocket *s, const char *port, const char *certfile)
{ // fix close after write bug //
int x = 1500; // FORCE MTU
ret = setsockopt (s->fd, SOL_SOCKET, SO_SNDBUF, (void*)&x, sizeof (int));
- if (ret < 0)
+ if (ret < 0) {
return false;
}
+ }
ret = setsockopt (s->fd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof optval);
- if (ret < 0)
+ if (ret < 0) {
return false;
+ }
#endif
memset (&s->sa, 0, sizeof (s->sa));
s->sa.sin_family = AF_INET;
@@ -638,16 +648,20 @@ R_API int r_socket_block_time (RSocket *s, int block, int sec) {
#if __UNIX__ || defined(__CYGWIN__)
int ret, flags;
#endif
- if (!s) return false;
+ if (!s) {
+ return false;
+ }
#if __UNIX__ || defined(__CYGWIN__)
flags = fcntl (s->fd, F_GETFL, 0);
- if (flags < 0)
+ if (flags < 0) {
return false;
+ }
ret = fcntl (s->fd, F_SETFL, block?
(flags & ~O_NONBLOCK):
(flags | O_NONBLOCK));
- if (ret < 0)
+ if (ret < 0) {
return false;
+ }
#elif __WINDOWS__ && !defined(__CYGWIN__) //&& !defined(__MINGW64__)
// HACK: nonblocking io on w32 behaves strange
return true;
@@ -658,16 +672,18 @@ R_API int r_socket_block_time (RSocket *s, int block, int sec) {
tv.tv_sec = sec;
tv.tv_usec = 0;
if (setsockopt (s->fd, SOL_SOCKET, SO_RCVTIMEO,
- (char *)&tv, sizeof (tv)) < 0)
+ (char *)&tv, sizeof (tv)) < 0) {
return false;
+ }
}
return true;
}
R_API int r_socket_flush(RSocket *s) {
#if HAVE_LIB_SSL
- if (s->is_ssl && s->bio)
- return BIO_flush(s->bio);
+ if (s->is_ssl && s->bio) {
+ return BIO_flush (s->bio);
+ }
#endif
return true;
}
@@ -717,10 +733,13 @@ R_API char *r_socket_to_string(RSocket *s) {
if (!getpeername (s->fd, &sa, &sl)) {
struct sockaddr_in *sain = (struct sockaddr_in*) &sa;
ut8 *a = (ut8*) &(sain->sin_addr);
- if ((str = malloc (32)))
+ if ((str = malloc (32))) {
sprintf (str, "%d.%d.%d.%d:%d",
- a[0],a[1],a[2],a[3], ntohs (sain->sin_port));
- } else eprintf ("getperrname: failed\n"); //r_sys_perror ("getpeername");
+ a[0], a[1], a[2], a[3], ntohs (sain->sin_port));
+ }
+ } else {
+ eprintf ("getperrname: failed\n"); //r_sys_perror ("getpeername");
+ }
return str;
#else
return NULL;
@@ -740,10 +759,11 @@ R_API int r_socket_write(RSocket *s, void *buf, int len) {
}
#if HAVE_LIB_SSL
if (s->is_ssl) {
- if (s->bio)
+ if (s->bio) {
ret = BIO_write (s->bio, buf+delta, b);
- else
- ret = SSL_write (s->sfd, buf+delta, b);
+ } else {
+ ret = SSL_write (s->sfd, buf + delta, b);
+ }
} else
#endif
{
diff --git a/libr/util/base85.c b/libr/util/base85.c
index b197716a9c..2511ba5d39 100644
--- a/libr/util/base85.c
+++ b/libr/util/base85.c
@@ -33,7 +33,9 @@
static int getc_nospace(FILE *f) {
int c;
- while (isspace (c = getc (f)));
+ while (isspace (c = getc (f))) {
+ ;
+ }
return c;
}
diff --git a/libr/util/base91.c b/libr/util/base91.c
index 4fded32b5e..b24134955e 100644
--- a/libr/util/base91.c
+++ b/libr/util/base91.c
@@ -15,8 +15,9 @@ static const char b91[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
int get_char_index(const char c) {
int i;
for (i = 0; i < 91; i++ ) {
- if (b91[i] == c)
+ if (b91[i] == c) {
return i;
+ }
}
return -1;
}
@@ -27,12 +28,14 @@ R_API int r_base91_decode(ut8* bout, const char *bin, int len) {
int b = 0;
int n = 0;
int c;
- if (len < 0)
+ if (len < 0) {
len = strlen (bin);
+ }
for (in = out = 0; in < len; in++) {
c = get_char_index(bin[in]);
- if (c == -1)
+ if (c == -1) {
continue;
+ }
if (v < 0) {
v = c;
} else {
@@ -47,8 +50,9 @@ R_API int r_base91_decode(ut8* bout, const char *bin, int len) {
bout[out++] = b & 255;
b >>= 8;
n -= 8;
- if (n <= 7)
+ if (n <= 7) {
break;
+ }
}
v = -1;
}
@@ -64,8 +68,9 @@ R_API int r_base91_encode(char *bout, const ut8 *bin, int len) {
int v = 0;
int b = 0;
int n = 0;
- if (len < 0)
+ if (len < 0) {
len = strlen ((const char *)bin);
+ }
for (in = out = 0; in < len; in++) {
b |= (bin[in] << n);
n += 8;
diff --git a/libr/util/bdiff.c b/libr/util/bdiff.c
index 73ab9e380f..8c41c306f5 100644
--- a/libr/util/bdiff.c
+++ b/libr/util/bdiff.c
@@ -48,13 +48,16 @@ static int splitlines(const char *a, int len, struct line **lr) {
/* count the lines */
i = 1; /* extra line for sentinel */
- for (p = a; p < a + len; p++)
- if (*p == '\n' || p == plast)
+ for (p = a; p < a + len; p++) {
+ if (*p == '\n' || p == plast) {
i++;
+ }
+ }
*lr = l = (struct line *)malloc(sizeof(struct line) * i);
- if (!l)
+ if (!l) {
return -1;
+ }
/* build the line array and calculate hashes */
h = 0;
@@ -88,18 +91,21 @@ static int equatelines(struct line *a, int an, struct line *b, int bn) {
struct pos *h = NULL;
/* build a hash table of the next highest power of 2 */
- while (buckets < bn + 1)
+ while (buckets < bn + 1) {
buckets *= 2;
+ }
/* try to allocate a large hash table to avoid collisions */
for (scale = 4; scale; scale /= 2) {
h = (struct pos *)malloc(scale * buckets * sizeof(struct pos));
- if (h)
+ if (h) {
break;
+ }
}
- if (!h)
+ if (!h) {
return 0;
+ }
buckets = buckets * scale - 1;
@@ -113,9 +119,11 @@ static int equatelines(struct line *a, int an, struct line *b, int bn) {
for (i = bn - 1; i >= 0; i--) {
/* find the equivalence class */
for (j = b[i].h & buckets; h[j].pos != INT_MAX;
- j = (j + 1) & buckets)
- if (!cmp(b + i, b + h[j].pos))
+ j = (j + 1) & buckets) {
+ if (!cmp (b + i, b + h[j].pos)) {
break;
+ }
+ }
/* add to the head of the equivalence class */
b[i].n = h[j].pos;
@@ -131,15 +139,18 @@ static int equatelines(struct line *a, int an, struct line *b, int bn) {
for (i = 0; i < an; i++) {
/* find the equivalence class */
for (j = a[i].h & buckets; h[j].pos != INT_MAX;
- j = (j + 1) & buckets)
- if (!cmp(a + i, b + h[j].pos))
+ j = (j + 1) & buckets) {
+ if (!cmp (a + i, b + h[j].pos)) {
break;
+ }
+ }
a[i].e = j; /* use equivalence class for quick compare */
- if (h[j].len <= t)
+ if (h[j].len <= t) {
a[i].n = h[j].pos; /* point to head of match list */
- else
+ } else {
a[i].n = INT_MAX; /* too popular */
+ }
}
/* discard hash tables */
@@ -154,16 +165,18 @@ static int longest_match(struct line *a, struct line *b, struct pos *pos,
for (i = a1; i < a2; i++) {
/* skip things before the current block */
- for (j = a[i].n; j < b1; j = b[j].n)
+ for (j = a[i].n; j < b1; j = b[j].n) {
;
+ }
/* loop through all lines match a[i] in b */
for (; j < b2; j = b[j].n) {
/* does this extend an earlier match? */
- if (i > a1 && j > b1 && pos[j - 1].pos == i - 1)
+ if (i > a1 && j > b1 && pos[j - 1].pos == i - 1) {
k = pos[j - 1].len + 1;
- else
+ } else {
k = 1;
+ }
pos[j].pos = i;
pos[j].len = k;
@@ -183,11 +196,13 @@ static int longest_match(struct line *a, struct line *b, struct pos *pos,
/* expand match to include neighboring popular lines */
while (mi - mb > a1 && mj - mb > b1 &&
- a[mi - mb - 1].e == b[mj - mb - 1].e)
+ a[mi - mb - 1].e == b[mj - mb - 1].e) {
mb++;
+ }
while (mi + mk < a2 && mj + mk < b2 &&
- a[mi + mk].e == b[mj + mk].e)
+ a[mi + mk].e == b[mj + mk].e) {
mk++;
+ }
*omi = mi - mb;
*omj = mj - mb;
@@ -202,8 +217,9 @@ static void recurse(struct line *a, struct line *b, struct pos *pos,
/* find the longest match in this chunk */
k = longest_match(a, b, pos, a1, a2, b1, b2, &i, &j);
- if (!k)
+ if (!k) {
return;
+ }
/* and recurse on the remaining chunks on either side */
recurse(a, b, pos, a1, i, b1, j, l);
@@ -244,19 +260,22 @@ static struct hunklist diff(struct line *a, int an, struct line *b, int bn)
struct hunk *next = curr+1;
int shift = 0;
- if (next == l.head)
+ if (next == l.head) {
break;
+ }
- if (curr->a2 == next->a1)
- while (curr->a2+shift < an && curr->b2+shift < bn
- && !cmp(a+curr->a2+shift, b+curr->b2+shift))
+ if (curr->a2 == next->a1) {
+ while (curr->a2 + shift < an && curr->b2 + shift < bn && !cmp (a + curr->a2 + shift, b + curr->b2 + shift)) {
shift++;
- else if (curr->b2 == next->b1)
- while (curr->b2+shift < bn && curr->a2+shift < an
- && !cmp(b+curr->b2+shift, a+curr->a2+shift))
+ }
+ } else if (curr->b2 == next->b1) {
+ while (curr->b2 + shift < bn && curr->a2 + shift < an && !cmp (b + curr->b2 + shift, a + curr->a2 + shift)) {
shift++;
- if (!shift)
+ }
+ }
+ if (!shift) {
continue;
+ }
curr->b2 += shift;
next->b1 += shift;
curr->a2 += shift;
@@ -317,8 +336,9 @@ R_API int r_diff_buffers_delta(RDiff *d, const ut8 *sa, int la, const ut8 *sb, i
dop.b_off = offa; // XXX offb not used??
dop.b_buf = (ut8 *)bl[lb].l;
dop.b_len = len;
- if (!d->callback (d, d->user, &dop))
+ if (!d->callback (d, d->user, &dop)) {
break;
+ }
}
#if 0
if (rlen > 0) {
diff --git a/libr/util/bitmap.c b/libr/util/bitmap.c
index 6175171b6d..f93c26ef4a 100644
--- a/libr/util/bitmap.c
+++ b/libr/util/bitmap.c
@@ -12,15 +12,18 @@
R_API RBitmap *r_bitmap_new(size_t len) {
RBitmap *b = R_NEW0 (RBitmap);
- if (!b) return NULL;
+ if (!b) {
+ return NULL;
+ }
b->length = len;
b->bitmap = calloc (BITMAP_WORD_COUNT (len), sizeof (RBitword));
return b;
}
R_API void r_bitmap_set_bytes(RBitmap *b, const ut8 *buf, int len) {
- if (b->length < len)
+ if (b->length < len) {
len = b->length;
+ }
memcpy (b->bitmap, buf, len);
}
@@ -30,15 +33,17 @@ R_API void r_bitmap_free(RBitmap *b) {
}
R_API void r_bitmap_set(RBitmap *b, size_t bit) {
- if (bitlength)
- b->bitmap[(bit >> BITWORD_BITS_SHIFT)] |= \
+ if (bit < b->length) {
+ b->bitmap[(bit >> BITWORD_BITS_SHIFT)] |=
((RBitword)1 << (bit & BITWORD_BITS_MASK));
+ }
}
R_API void r_bitmap_unset(RBitmap *b, size_t bit) {
- if (bit < b->length)
- b->bitmap[(bit >> BITWORD_BITS_SHIFT)] &= \
+ if (bit < b->length) {
+ b->bitmap[(bit >> BITWORD_BITS_SHIFT)] &=
~((RBitword)1 << (bit & BITWORD_BITS_MASK));
+ }
}
R_API int r_bitmap_test(RBitmap *b, size_t bit) {
diff --git a/libr/util/btree.c b/libr/util/btree.c
index 9133d866f7..6a0366f971 100644
--- a/libr/util/btree.c
+++ b/libr/util/btree.c
@@ -8,7 +8,9 @@ R_API void btree_init(struct btree_node **T) {
R_API struct btree_node *btree_remove(struct btree_node *p, BTREE_DEL(del)) {
struct btree_node *rp = NULL, *f;
- if (!p) return p;
+ if (!p) {
+ return p;
+ }
if (p->right) {
if (p->left) {
f = p;
@@ -21,10 +23,18 @@ R_API struct btree_node *btree_remove(struct btree_node *p, BTREE_DEL(del)) {
f->left = rp->right;
rp->right = p->right;
rp->left = p->left;
- } else rp->left = p->left;
- } else rp = p->right;
- } else rp = p->left;
- if (del) del (p->data);
+ } else {
+ rp->left = p->left;
+ }
+ } else {
+ rp = p->right;
+ }
+ } else {
+ rp = p->left;
+ }
+ if (del) {
+ del (p->data);
+ }
free (p);
return(rp);
}
@@ -33,16 +43,19 @@ R_API void *btree_search(struct btree_node *root, void *x, BTREE_CMP(cmp), int p
struct btree_node *p = NULL;
if (root) {
- if (cmp (x, root->data)<0)
+ if (cmp (x, root->data) < 0) {
p = btree_search (root->left, x, cmp, parent);
- else if (cmp(x, root->data)>0)
+ } else if (cmp (x, root->data) > 0) {
p = btree_search (root->right, x, cmp, parent);
- else p = root;
+ } else {
+ p = root;
+ }
}
/* node found */
if (p) {
- if (parent)
+ if (parent) {
return root;
+ }
return p;
} return NULL;
}
@@ -85,7 +98,9 @@ R_API void btree_cleartree(struct btree_node *proot, BTREE_DEL(del)) {
if (proot) {
btree_cleartree (proot->left, del);
btree_cleartree (proot->right, del);
- if (del) del (proot->data);
+ if (del) {
+ del (proot->data);
+ }
free (proot);
}
}
@@ -93,11 +108,17 @@ R_API void btree_cleartree(struct btree_node *proot, BTREE_DEL(del)) {
R_API void btree_insert(struct btree_node **T, struct btree_node *p, BTREE_CMP(cmp)) {
int ret = cmp (p->data, (*T)->data);
if (ret<0) {
- if ((*T)->left) btree_insert (&(*T)->left, p, cmp);
- else (*T)->left = p;
+ if ((*T)->left) {
+ btree_insert (&(*T)->left, p, cmp);
+ } else {
+ (*T)->left = p;
+ }
} else if (ret>0) {
- if ((*T)->right) btree_insert (&(*T)->right, p, cmp);
- else (*T)->right = p;
+ if ((*T)->right) {
+ btree_insert (&(*T)->right, p, cmp);
+ } else {
+ (*T)->right = p;
+ }
}
}
@@ -123,8 +144,12 @@ R_API struct btree_node *btree_hittest(struct btree_node *root, struct btree_nod
if (root) {
struct btree_node *ml = btree_hittest(root->left, root);
struct btree_node *mr = btree_hittest(root->right, root);
- if (ml && ml->hits > p->hits) p = ml;
- if (mr && mr->hits > p->hits) p = mr;
+ if (ml && ml->hits > p->hits) {
+ p = ml;
+ }
+ if (mr && mr->hits > p->hits) {
+ p = mr;
+ }
}
return p;
}
diff --git a/libr/util/buf.c b/libr/util/buf.c
index 12621e3b79..b30c960d81 100644
--- a/libr/util/buf.c
+++ b/libr/util/buf.c
@@ -269,7 +269,9 @@ R_API RBuffer *r_buf_new_file(const char *file, bool newFile) {
R_API RBuffer *r_buf_new_slurp(const char *file) {
int len;
RBuffer *b = r_buf_new ();
- if (!b) return NULL;
+ if (!b) {
+ return NULL;
+ }
b->buf = (ut8*)r_file_slurp (file, &len);
b->length = len;
if (b->buf) {
@@ -421,9 +423,12 @@ R_API bool r_buf_append_nbytes(RBuffer *b, int length) {
}
return false;
}
- if (b->empty) b->length = b->empty = 0;
- if (!(b->buf = realloc (b->buf, b->length+length)))
+ if (b->empty) {
+ b->length = b->empty = 0;
+ }
+ if (!(b->buf = realloc (b->buf, b->length + length))) {
return false;
+ }
memset (b->buf+b->length, 0, length);
b->length += length;
return true;
@@ -436,9 +441,12 @@ R_API bool r_buf_append_ut16(RBuffer *b, ut16 n) {
if (b->fd != -1) {
return r_buf_append_bytes (b, (const ut8*)&n, sizeof (n));
}
- if (b->empty) b->length = b->empty = 0;
- if (!(b->buf = realloc (b->buf, b->length + sizeof (n))))
+ if (b->empty) {
+ b->length = b->empty = 0;
+ }
+ if (!(b->buf = realloc (b->buf, b->length + sizeof (n)))) {
return false;
+ }
memmove (b->buf+b->length, &n, sizeof (n));
b->length += sizeof (n);
return true;
@@ -469,9 +477,12 @@ R_API bool r_buf_append_ut64(RBuffer *b, ut64 n) {
if (b->fd != -1) {
return r_buf_append_bytes (b, (const ut8*)&n, sizeof (n));
}
- if (b->empty) b->length = b->empty = 0;
- if (!(b->buf = realloc (b->buf, b->length+sizeof (n))))
+ if (b->empty) {
+ b->length = b->empty = 0;
+ }
+ if (!(b->buf = realloc (b->buf, b->length + sizeof (n)))) {
return false;
+ }
memmove (b->buf+b->length, &n, sizeof (n));
b->length += sizeof (n);
return true;
@@ -584,9 +595,9 @@ static int r_buf_fcpy_at (RBuffer *b, ut64 addr, ut8 *buf, const char *fmt, int
return -1;
}
tsize = 2;
- for (i = len = 0; i < n; i++)
- for (j = 0; fmt[j]; j++) {
- switch (fmt[j]) {
+ for (i = len = 0; i < n; i++) {
+ for (j = 0; fmt[j]; j++) {
+ switch (fmt[j]) {
#ifdef _MSC_VER
case'0':case'1':case'2':case'3':case'4':case'5':case'6':case'7':case'8':case'9':
#else
@@ -681,6 +692,7 @@ static int r_buf_fcpy_at (RBuffer *b, ut64 addr, ut8 *buf, const char *fmt, int
}
len += tsize * m;
m = 1;
+ }
}
b->cur = vaddr + len;
return len;
@@ -821,7 +833,9 @@ R_API int r_buf_fwrite_at (RBuffer *b, ut64 addr, ut8 *buf, const char *fmt, int
}
R_API void r_buf_deinit(RBuffer *b) {
- if (!b) return;
+ if (!b) {
+ return;
+ }
if (b->fd != -1) {
r_sandbox_close (b->fd);
b->fd = -1;
diff --git a/libr/util/calc.c b/libr/util/calc.c
index 5867f6d48a..ff26050870 100644
--- a/libr/util/calc.c
+++ b/libr/util/calc.c
@@ -45,14 +45,30 @@ static inline RNumCalcValue Nror(RNumCalcValue n, RNumCalcValue v) {
return n;
}
static inline RNumCalcValue Nmod(RNumCalcValue n, RNumCalcValue v) {
- if (v.d) n.d = (n.d - (n.d/v.d)); else n.d = 0;
- if (v.n) n.n %= v.n; else n.n = 0;
+ if (v.d) {
+ n.d = (n.d - (n.d / v.d));
+ } else {
+ n.d = 0;
+ }
+ if (v.n) {
+ n.n %= v.n;
+ } else {
+ n.n = 0;
+ }
return n;
}
static inline RNumCalcValue Ndiv(RNumCalcValue n, RNumCalcValue v) {
- if (v.d) n.d /= v.d; else n.d = 0;
- if (v.n) n.n /= v.n; else n.n = 0;
+ if (v.d) {
+ n.d /= v.d;
+ } else {
+ n.d = 0;
+ }
+ if (v.n) {
+ n.n /= v.n;
+ } else {
+ n.n = 0;
+ }
return n;
}
diff --git a/libr/util/chmod.c b/libr/util/chmod.c
index 08531b42b6..33f49f1448 100644
--- a/libr/util/chmod.c
+++ b/libr/util/chmod.c
@@ -20,8 +20,9 @@ R_API int r_file_chmod (const char *file, const char *mod, int recursive) {
#if __UNIX__
oper = '=';
mode = 0;
- if (!parsemode (mod))
+ if (!parsemode (mod)) {
return false;
+ }
return chmodr (file, recursive);
#else
return -1;
@@ -33,8 +34,9 @@ R_API int r_file_chmod (const char *file, const char *mod, int recursive) {
int chmodr(const char *path, int rflag) {
struct stat st;
- if (stat (path, &st) == -1)
+ if (stat (path, &st) == -1) {
return 0;
+ }
switch (oper) {
case '+':
@@ -51,8 +53,9 @@ int chmodr(const char *path, int rflag) {
eprintf ("chmod %s:", path);
return false;
}
- if (rflag)
+ if (rflag) {
recurse (path, rflag, chmodr);
+ }
return true;
}
@@ -64,20 +67,42 @@ int parsemode(const char *str) {
octal = strtol(str, &end, 8);
if (*end == '\0') {
- if (octal & 04000) mode |= S_ISUID;
- if (octal & 02000) mode |= S_ISGID;
- if (octal & 00400) mode |= S_IRUSR;
- if (octal & 00200) mode |= S_IWUSR;
- if (octal & 00100) mode |= S_IXUSR;
- if (octal & 00040) mode |= S_IRGRP;
- if (octal & 00020) mode |= S_IWGRP;
- if (octal & 00010) mode |= S_IXGRP;
- if (octal & 00004) mode |= S_IROTH;
- if (octal & 00002) mode |= S_IWOTH;
- if (octal & 00001) mode |= S_IXOTH;
+ if (octal & 04000) {
+ mode |= S_ISUID;
+ }
+ if (octal & 02000) {
+ mode |= S_ISGID;
+ }
+ if (octal & 00400) {
+ mode |= S_IRUSR;
+ }
+ if (octal & 00200) {
+ mode |= S_IWUSR;
+ }
+ if (octal & 00100) {
+ mode |= S_IXUSR;
+ }
+ if (octal & 00040) {
+ mode |= S_IRGRP;
+ }
+ if (octal & 00020) {
+ mode |= S_IWGRP;
+ }
+ if (octal & 00010) {
+ mode |= S_IXGRP;
+ }
+ if (octal & 00004) {
+ mode |= S_IROTH;
+ }
+ if (octal & 00002) {
+ mode |= S_IWOTH;
+ }
+ if (octal & 00001) {
+ mode |= S_IXOTH;
+ }
return true;
}
- for(p = str; *p; p++)
+ for (p = str; *p; p++) {
switch(*p) {
/* masks */
case 'u':
@@ -116,17 +141,22 @@ int parsemode(const char *str) {
eprintf ("%s: invalid mode\n", str);
return false;
}
- if (mask)
+ }
+ if (mask) {
mode &= mask;
+ }
return true;
}
char * agetcwd(void) {
char *buf = malloc (4096);
- if (!buf) return NULL;
- if(!getcwd(buf, 4096))
- eprintf("getcwd:");
- return buf;
+ if (!buf) {
+ return NULL;
+ }
+ if (!getcwd (buf, 4096)) {
+ eprintf ("getcwd:");
+ }
+ return buf;
}
static void recurse(const char *path, int rec, int (*fn)(const char *,int)) {
@@ -135,10 +165,10 @@ static void recurse(const char *path, int rec, int (*fn)(const char *,int)) {
struct stat st;
DIR *dp;
- if (lstat (path, &st) == -1 || !S_ISDIR (st.st_mode))
- return;
- else if (!(dp = opendir (path))) {
- eprintf ("opendir %s:", path);
+ if (lstat (path, &st) == -1 || !S_ISDIR (st.st_mode)) {
+ return;
+ } else if (!(dp = opendir (path))) {
+ eprintf ("opendir %s:", path);
return;
}
cwd = agetcwd();
@@ -148,13 +178,16 @@ static void recurse(const char *path, int rec, int (*fn)(const char *,int)) {
free (cwd);
return;
}
- while ((d = readdir (dp)))
- if (strcmp (d->d_name, ".") && strcmp (d->d_name, ".."))
- fn (d->d_name, 1);
+ while ((d = readdir (dp))) {
+ if (strcmp (d->d_name, ".") && strcmp (d->d_name, "..")) {
+ fn (d->d_name, 1);
+ }
+ }
- closedir (dp);
- if (chdir (cwd) == -1)
- eprintf ("chdir %s:", cwd);
- free (cwd);
+ closedir (dp);
+ if (chdir (cwd) == -1) {
+ eprintf ("chdir %s:", cwd);
+ }
+ free (cwd);
}
#endif
diff --git a/libr/util/constr.c b/libr/util/constr.c
index 07a419ceb7..485297afcb 100644
--- a/libr/util/constr.c
+++ b/libr/util/constr.c
@@ -18,16 +18,18 @@ R_API void r_constr_free (RConstr *c) {
R_API const char *r_constr_get (RConstr *c, const char *str) {
char *e = c->b+c->i, *p = c->b;
for (p = c->b; pi, l = strlen (str)+1;
- if ((c->b + i+l) >= (c->b + c->l))
+ if ((c->b + i + l) >= (c->b + c->l)) {
return NULL;
+ }
memcpy (c->b + i, str, l);
c->i += l;
return c->b+i;
diff --git a/libr/util/date.c b/libr/util/date.c
index e99d382d0a..c4ca1f204c 100644
--- a/libr/util/date.c
+++ b/libr/util/date.c
@@ -47,7 +47,9 @@ R_API int r_print_date_hfs(RPrint *p, const ut8 *buf, int len) {
p->cb_printf ("%s\n", s);
ret = sizeof (time_t);
}
- } else p->cb_printf ("Invalid time\n");
+ } else {
+ p->cb_printf ("Invalid time\n");
+ }
}
}
return ret;
@@ -71,7 +73,9 @@ R_API int r_print_date_unix(RPrint *p, const ut8 *buf, int len) {
p->cb_printf ("%s\n", s);
ret = sizeof (time_t);
}
- } else p->cb_printf ("Invalid time\n");
+ } else {
+ p->cb_printf ("Invalid time\n");
+ }
}
}
return ret;
diff --git a/libr/util/diff.c b/libr/util/diff.c
index 4c5ddd4da4..f380746ff5 100644
--- a/libr/util/diff.c
+++ b/libr/util/diff.c
@@ -424,8 +424,9 @@ out:
}
R_API bool r_diff_buffers_distance_original(RDiff *diff, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity) {
- if (!a || !b)
+ if (!a || !b) {
return false;
+ }
const bool verbose = diff ? diff->verbose : false;
const ut32 length = R_MAX (la, lb);
diff --git a/libr/util/file.c b/libr/util/file.c
index c28354daeb..4db7d079b1 100644
--- a/libr/util/file.c
+++ b/libr/util/file.c
@@ -84,7 +84,9 @@ R_API char *r_file_dirname (const char *path) {
*ptr = 0;
} else {
ptr = (char*)r_str_rchr (newpath, NULL, '\\');
- if (ptr) *ptr = 0;
+ if (ptr) {
+ *ptr = 0;
+ }
}
return newpath;
}
@@ -186,8 +188,9 @@ R_API char *r_file_abspath(const char *file) {
ret = r_str_home (file + 2);
} else {
#if __UNIX__ || __CYGWIN__
- if (cwd && *file != '/')
- ret = r_str_newf ("%s"R_SYS_DIR"%s", cwd, file);
+ if (cwd && *file != '/') {
+ ret = r_str_newf ("%s" R_SYS_DIR "%s", cwd, file);
+ }
#elif __WINDOWS__ && !__CYGWIN__
// Network path
if (!strncmp (file, "\\\\", 2)) {
@@ -476,11 +479,12 @@ R_API char *r_file_slurp_random_line_count(const char *file, int *line) {
}
}
ptr = str + i;
- for (i = 0; ptr[i]; i++)
+ for (i = 0; ptr[i]; i++) {
if (ptr[i] == '\n') {
ptr[i] = '\0';
break;
}
+ }
ptr = strdup (ptr);
}
free (str);
diff --git a/libr/util/flist.c b/libr/util/flist.c
index 5d8fc550a6..3641e5dde4 100644
--- a/libr/util/flist.c
+++ b/libr/util/flist.c
@@ -58,7 +58,9 @@ R_API void r_flist_delete(void **it, int idx) {
r_flist_rewind (it);
free (it[idx]);
it[idx] = NULL;
- for (it += idx; *it; it++) *it = *(it+1);
+ for (it += idx; *it; it++) {
+ *it = *(it + 1);
+ }
}
#define r_flist_foreach(it, pos) \
diff --git a/libr/util/format.c b/libr/util/format.c
index 2a99200c2d..5e4c270ed0 100644
--- a/libr/util/format.c
+++ b/libr/util/format.c
@@ -92,7 +92,9 @@ static void r_print_format_quadword(const RPrint* p, int endian, int mode,
updateAddr (buf + i, size - i, endian, NULL, &addr64);
if (elem == -1 || elem == 0) {
p->cb_printf ("0x%016"PFMT64x, addr64);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
if (size != 0 && elem == -1) {
p->cb_printf (", ");
@@ -102,7 +104,9 @@ static void r_print_format_quadword(const RPrint* p, int endian, int mode,
}
i += 8;
}
- if (!SEEVALUE) p->cb_printf (" ]");
+ if (!SEEVALUE) {
+ p->cb_printf (" ]");
+ }
}
} else if (MUSTSEEJSON) {
if (size==-1) {
@@ -113,12 +117,16 @@ static void r_print_format_quadword(const RPrint* p, int endian, int mode,
updateAddr (buf + i, size - i, endian, NULL, &addr64);
if (elem == -1 || elem == 0) {
p->cb_printf ("%"PFMT64d, addr64);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
if (size != 0 && elem == -1) {
p->cb_printf (", ");
}
- if (elem > -1) elem--;
+ if (elem > -1) {
+ elem--;
+ }
i += 8;
}
p->cb_printf (" ]");
@@ -143,18 +151,27 @@ static void r_print_format_byte(const RPrint* p, int endian, int mode,
if (size == -1) {
p->cb_printf ("0x%02x", buf[i]);
} else {
- if (!SEEVALUE) p->cb_printf ("[ ");
+ if (!SEEVALUE) {
+ p->cb_printf ("[ ");
+ }
while (size--) {
if (elem == -1 || elem == 0) {
p->cb_printf ("0x%02x", buf[i]);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
- if (size != 0 && elem == -1)
+ if (size != 0 && elem == -1) {
p->cb_printf (", ");
- if (elem > -1) elem--;
+ }
+ if (elem > -1) {
+ elem--;
+ }
i++;
}
- if (!SEEVALUE) p->cb_printf (" ]");
+ if (!SEEVALUE) {
+ p->cb_printf (" ]");
+ }
}
} else if (MUSTSEEJSON) {
if (size==-1) {
@@ -164,7 +181,9 @@ static void r_print_format_byte(const RPrint* p, int endian, int mode,
while (size--) {
if (elem == -1 || elem == 0) {
p->cb_printf (", %d", buf[i]);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
if (size != 0 && elem == -1) {
p->cb_printf (", ");
@@ -204,25 +223,36 @@ static int r_print_format_uleb(const RPrint* p, int endian, int mode,
free (tmp);
free (nbr);
} else if (MUSTSEE) {
- if (!SEEVALUE) p->cb_printf ("0x%08"PFMT64x" = ", seeki);
+ if (!SEEVALUE) {
+ p->cb_printf ("0x%08" PFMT64x " = ", seeki);
+ }
if (size==-1) {
r_uleb128_decode (buf+i, &offset, &value);
p->cb_printf ("%"PFMT64d, value);
} else {
- if (!SEEVALUE) p->cb_printf ("[ ");
+ if (!SEEVALUE) {
+ p->cb_printf ("[ ");
+ }
while (size--) {
if (elem == -1 || elem == 0) {
r_uleb128_decode (buf+i, &s, &value);
i += s;
offset += s;
p->cb_printf ("%"PFMT64d, value);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
- if (size != 0 && elem == -1)
+ if (size != 0 && elem == -1) {
p->cb_printf (", ");
- if (elem > -1) elem--;
+ }
+ if (elem > -1) {
+ elem--;
+ }
+ }
+ if (!SEEVALUE) {
+ p->cb_printf (" ]");
}
- if (!SEEVALUE) p->cb_printf (" ]");
}
} else if (MUSTSEEJSON) {
if (size==-1) {
@@ -236,11 +266,16 @@ static int r_print_format_uleb(const RPrint* p, int endian, int mode,
i += s;
offset += s;
p->cb_printf ("\"%"PFMT64d"\"", value);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
- if (size != 0 && elem == -1)
+ if (size != 0 && elem == -1) {
p->cb_printf (", ");
- if (elem > -1) elem--;
+ }
+ if (elem > -1) {
+ elem--;
+ }
}
p->cb_printf (" ]");
}
@@ -259,36 +294,52 @@ static void r_print_format_char(const RPrint* p, int endian, int mode,
if (MUSTSET) {
p->cb_printf ("\"w %s\" @ 0x%08"PFMT64x"\n", setval, seeki+((elem>=0)?elem:0));
} else if (MUSTSEE) {
- if (!SEEVALUE) p->cb_printf ("0x%08"PFMT64x" = ", seeki+((elem>=0)?elem*2:0)); //XXX:: shouldn't it be elem*1??
- if (size==-1)
+ if (!SEEVALUE) {
+ p->cb_printf ("0x%08" PFMT64x " = ", seeki + ((elem >= 0) ? elem * 2 : 0)); //XXX:: shouldn't it be elem*1??
+ }
+ if (size == -1) {
p->cb_printf ("'%c'", IS_PRINTABLE (buf[i])?buf[i]:'.');
- else {
- if (!SEEVALUE) p->cb_printf ("[ ");
+ } else {
+ if (!SEEVALUE) {
+ p->cb_printf ("[ ");
+ }
while (size--) {
if (elem == -1 || elem == 0) {
p->cb_printf ("'%c'", IS_PRINTABLE (buf[i])?buf[i]:'.');
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
- if (size != 0 && elem == -1)
+ if (size != 0 && elem == -1) {
p->cb_printf (", ");
- if (elem > -1) elem--;
+ }
+ if (elem > -1) {
+ elem--;
+ }
i++;
}
- if (!SEEVALUE) p->cb_printf (" ]");
+ if (!SEEVALUE) {
+ p->cb_printf (" ]");
+ }
}
} else if (MUSTSEEJSON) {
- if (size==-1)
+ if (size == -1) {
p->cb_printf ("\"%c\"", IS_PRINTABLE (buf[i])?buf[i]:'.');
- else {
+ } else {
p->cb_printf ("[ ");
while (size--) {
if (elem == -1 || elem == 0) {
p->cb_printf ("\"%c\"", IS_PRINTABLE (buf[i])?buf[i]:'.');
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
- if (size != 0 && elem == -1)
+ if (size != 0 && elem == -1) {
p->cb_printf (", ");
- if (elem > -1) elem--;
+ }
+ if (elem > -1) {
+ elem--;
+ }
i++;
}
p->cb_printf (" ]");
@@ -307,36 +358,52 @@ static void r_print_format_decchar(const RPrint* p, int endian, int mode,
if (MUSTSET) {
p->cb_printf ("\"w %s\" @ 0x%08"PFMT64x"\n", setval, seeki+((elem>=0)?elem:0));
} else if (MUSTSEE) {
- if (!SEEVALUE) p->cb_printf ("0x%08"PFMT64x" = ", seeki+((elem>=0)?elem:0));
- if (size==-1)
+ if (!SEEVALUE) {
+ p->cb_printf ("0x%08" PFMT64x " = ", seeki + ((elem >= 0) ? elem : 0));
+ }
+ if (size == -1) {
p->cb_printf ("%d", buf[i]);
- else {
- if (!SEEVALUE) p->cb_printf ("[ ");
+ } else {
+ if (!SEEVALUE) {
+ p->cb_printf ("[ ");
+ }
while (size--) {
if (elem == -1 || elem == 0) {
p->cb_printf ("%d", buf[i]);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
- if (size != 0 && elem == -1)
+ if (size != 0 && elem == -1) {
p->cb_printf (", ");
- if (elem > -1) elem--;
+ }
+ if (elem > -1) {
+ elem--;
+ }
i++;
}
- if (!SEEVALUE) p->cb_printf (" ]");
+ if (!SEEVALUE) {
+ p->cb_printf (" ]");
+ }
}
} else if (MUSTSEEJSON) {
- if (size==-1)
+ if (size == -1) {
p->cb_printf ("\"%d\"", buf[i]);
- else {
+ } else {
p->cb_printf ("[ ");
while (size--) {
if (elem == -1 || elem == 0) {
p->cb_printf ("\"%d\"", buf[i]);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
- if (size != 0 && elem == -1)
+ if (size != 0 && elem == -1) {
p->cb_printf (", ");
- if (elem > -1) elem--;
+ }
+ if (elem > -1) {
+ elem--;
+ }
i++;
}
p->cb_printf (" ]");
@@ -362,8 +429,12 @@ static int r_print_format_string(const RPrint* p, ut64 seeki, ut64 addr64, ut64
free (encstr);
}
} else if (MUSTSEE) {
- if (!SEEVALUE) p->cb_printf ("0x%08"PFMT64x" = ", seeki);
- if (!SEEVALUE) p->cb_printf ("0x%08"PFMT64x" -> 0x%08"PFMT64x" ", seeki, addr);
+ if (!SEEVALUE) {
+ p->cb_printf ("0x%08" PFMT64x " = ", seeki);
+ }
+ if (!SEEVALUE) {
+ p->cb_printf ("0x%08" PFMT64x " -> 0x%08" PFMT64x " ", seeki, addr);
+ }
if (res && buffer[0] != 0xff && buffer[1] != 0xff) {
p->cb_printf ("%s", buffer);
}
@@ -385,11 +456,15 @@ static void r_print_format_time(const RPrint* p, int endian, int mode,
} else if (MUSTSEE) {
char *timestr = strdup(asctime (gmtime ((time_t*)&addr)));
*(timestr+24) = '\0';
- if (!SEEVALUE) p->cb_printf ("0x%08"PFMT64x" = ", seeki+((elem>=0)?elem*4:0));
+ if (!SEEVALUE) {
+ p->cb_printf ("0x%08" PFMT64x " = ", seeki + ((elem >= 0) ? elem * 4 : 0));
+ }
if (size==-1) {
p->cb_printf ("%s", timestr);
} else {
- if (!SEEVALUE) p->cb_printf ("[ ");
+ if (!SEEVALUE) {
+ p->cb_printf ("[ ");
+ }
while (size--) {
updateAddr (buf + i, size - i, endian, &addr, NULL);
free (timestr);
@@ -409,7 +484,9 @@ static void r_print_format_time(const RPrint* p, int endian, int mode,
}
i += 4;
}
- if (!SEEVALUE) p->cb_printf (" ]");
+ if (!SEEVALUE) {
+ p->cb_printf (" ]");
+ }
}
free (timestr);
} else if (MUSTSEEJSON) {
@@ -426,7 +503,9 @@ static void r_print_format_time(const RPrint* p, int endian, int mode,
*(timestr+24) = '\0';
if (elem == -1 || elem == 0) {
p->cb_printf ("\"%s\"", timestr);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
if (size != 0 && elem == -1) {
p->cb_printf (", ");
@@ -458,7 +537,9 @@ static void r_print_format_hex(const RPrint* p, int endian, int mode,
} else if (mode & R_PRINT_DOT) {
p->cb_printf ("%"PFMT64d, addr);
} else if (MUSTSEE) {
- if (!SEEVALUE) p->cb_printf ("0x%08"PFMT64x" = ", seeki+((elem>=0)?elem*4:0));
+ if (!SEEVALUE) {
+ p->cb_printf ("0x%08" PFMT64x " = ", seeki + ((elem >= 0) ? elem * 4 : 0));
+ }
if (size==-1) {
p->cb_printf ("%"PFMT64d, addr);
} else {
@@ -486,9 +567,9 @@ static void r_print_format_hex(const RPrint* p, int endian, int mode,
}
}
} else if (MUSTSEEJSON) {
- if (size==-1)
+ if (size == -1) {
p->cb_printf ("%d", addr);
- else {
+ } else {
p->cb_printf ("[ ");
while (size--) {
updateAddr (buf + i, size - i, endian, &addr, NULL);
@@ -556,9 +637,9 @@ static void r_print_format_int(const RPrint* p, int endian, int mode,
}
}
} else if (MUSTSEEJSON) {
- if (size==-1)
+ if (size == -1) {
p->cb_printf ("%d", addr);
- else {
+ } else {
p->cb_printf ("[ ");
while (size--) {
updateAddr (buf + i, size - i, endian, &addr, NULL);
@@ -613,42 +694,60 @@ static void r_print_format_octal (const RPrint* p, int endian, int mode,
p->cb_printf ("0%"PFMT64o, addr);
} else if (MUSTSEE) {
ut32 addr32 = (ut32)addr;
- if (!SEEVALUE) p->cb_printf ("0x%08"PFMT64x" = ", seeki+((elem>=0)?elem*4:0));
- if (!SEEVALUE) p->cb_printf ("(octal) ");
- if (size==-1)
+ if (!SEEVALUE) {
+ p->cb_printf ("0x%08" PFMT64x " = ", seeki + ((elem >= 0) ? elem * 4 : 0));
+ }
+ if (!SEEVALUE) {
+ p->cb_printf ("(octal) ");
+ }
+ if (size == -1) {
p->cb_printf (" 0%08"PFMT64o, addr32);
- else {
- if (!SEEVALUE) p->cb_printf ("[ ");
+ } else {
+ if (!SEEVALUE) {
+ p->cb_printf ("[ ");
+ }
while (size--) {
updateAddr (buf + i, size - i, endian, &addr, NULL);
addr32 = (ut32)addr;
if (elem == -1 || elem == 0) {
p->cb_printf ("0%08"PFMT64o, addr32);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
- if (size != 0 && elem == -1)
+ if (size != 0 && elem == -1) {
p->cb_printf (", ");
- if (elem > -1) elem--;
+ }
+ if (elem > -1) {
+ elem--;
+ }
i+=4;
}
- if (!SEEVALUE) p->cb_printf (" ]");
+ if (!SEEVALUE) {
+ p->cb_printf (" ]");
+ }
}
} else if (MUSTSEEJSON) {
ut32 addr32 = (ut32)addr;
- if (size==-1)
+ if (size == -1) {
p->cb_printf ("%d", addr32);
- else {
+ } else {
p->cb_printf ("[ ");
while (size--) {
updateAddr (buf, i, endian, &addr, NULL);
addr32 = (ut32)addr;
if (elem == -1 || elem == 0) {
p->cb_printf ("%d", addr32);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
- if (size != 0 && elem == -1)
+ if (size != 0 && elem == -1) {
p->cb_printf (", ");
- if (elem > -1) elem--;
+ }
+ if (elem > -1) {
+ elem--;
+ }
i+=4;
}
p->cb_printf (" ]");
@@ -672,37 +771,50 @@ static void r_print_format_hexflag(const RPrint* p, int endian, int mode,
p->cb_printf ("0x%08"PFMT64x, addr & UT32_MAX);
} else if (MUSTSEE) {
ut32 addr32 = (ut32)addr;
- if (!SEEVALUE) p->cb_printf ("0x%08"PFMT64x" = ", seeki+((elem>=0)?elem*4:0));
+ if (!SEEVALUE) {
+ p->cb_printf ("0x%08" PFMT64x " = ", seeki + ((elem >= 0) ? elem * 4 : 0));
+ }
if (size==-1) {
p->cb_printf ("0x%08"PFMT64x, (ut64)addr32);
} else {
- if (!SEEVALUE) p->cb_printf ("[ ");
+ if (!SEEVALUE) {
+ p->cb_printf ("[ ");
+ }
while (size--) {
updateAddr (buf + i, size - i, endian, &addr, NULL);
addr32 = (ut32)addr;
if (elem == -1 || elem == 0) {
p->cb_printf ("0x%08"PFMT64x, addr32);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
- if (size != 0 && elem == -1)
+ if (size != 0 && elem == -1) {
p->cb_printf (", ");
- if (elem > -1) elem--;
+ }
+ if (elem > -1) {
+ elem--;
+ }
i+=4;
}
- if (!SEEVALUE) p->cb_printf (" ]");
+ if (!SEEVALUE) {
+ p->cb_printf (" ]");
+ }
}
} else if (MUSTSEEJSON) {
ut32 addr32 = (ut32)addr;
- if (size==-1)
+ if (size == -1) {
p->cb_printf ("%d", addr32);
- else {
+ } else {
p->cb_printf ("[ ");
while (size--) {
updateAddr (buf + i, size - i, endian, &addr, NULL);
addr32 = (ut32)addr;
if (elem == -1 || elem == 0) {
p->cb_printf ("%d", addr32);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
if (size != 0 && elem == -1) {
p->cb_printf (",");
@@ -734,11 +846,15 @@ static int r_print_format_10bytes(const RPrint* p, int mode, const char* setval,
return -1;
}
p->iob.read_at (p->iob.io, (ut64)addr, buffer, 248);
- if (!SEEVALUE) p->cb_printf ("0x%08"PFMT64x" = ", seeki);
+ if (!SEEVALUE) {
+ p->cb_printf ("0x%08" PFMT64x " = ", seeki);
+ }
for (j=0; j<10; j++) {
p->cb_printf ("%02x ", buf[j]);
}
- if (!SEEVALUE) p->cb_printf (" ... (");
+ if (!SEEVALUE) {
+ p->cb_printf (" ... (");
+ }
for (j = 0; j < 10; j++) {
if (!SEEVALUE) {
if (IS_PRINTABLE (buf[j])) {
@@ -748,7 +864,9 @@ static int r_print_format_10bytes(const RPrint* p, int mode, const char* setval,
}
}
}
- if (!SEEVALUE) p->cb_printf (")");
+ if (!SEEVALUE) {
+ p->cb_printf (")");
+ }
} else if (MUSTSEEJSON) {
if (!p->iob.read_at) {
printf ("(cannot read memory)\n");
@@ -779,17 +897,22 @@ static int r_print_format_hexpairs(const RPrint* p, int endian, int mode,
}
} else if (MUSTSEE) {
size = (size < 1) ? 1 : size;
- if (!SEEVALUE) p->cb_printf ("0x%08"PFMT64x" = ", seeki);
+ if (!SEEVALUE) {
+ p->cb_printf ("0x%08" PFMT64x " = ", seeki);
+ }
for (j = 0; j < size; j++) {
p->cb_printf ("%02x ", buf[i + j]);
}
- if (!SEEVALUE) p->cb_printf (" ... (");
+ if (!SEEVALUE) {
+ p->cb_printf (" ... (");
+ }
for (j=0; jcb_printf ("%c", buf[i+j]);
- else
+ } else {
p->cb_printf (".");
+ }
}
}
p->cb_printf (")");
@@ -797,8 +920,9 @@ static int r_print_format_hexpairs(const RPrint* p, int endian, int mode,
size = (size < 1) ? 1 : size;
p->cb_printf ("[ %d", buf[0]);
j = 1;
- for (; j < 10; j++)
+ for (; j < 10; j++) {
p->cb_printf (", %d", buf[j]);
+ }
p->cb_printf ("]}");
return size;
}
@@ -940,7 +1064,9 @@ static void r_print_format_word(const RPrint* p, int endian, int mode,
: (*(buf+i+1))<<8 | (*(buf+i));
if (elem == -1 || elem == 0) {
p->cb_printf ("%d", addr);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
if (size != 0 && elem == -1) {
p->cb_printf (",");
@@ -966,7 +1092,9 @@ static void r_print_format_word(const RPrint* p, int endian, int mode,
: (*(buf+i+1))<<8 | (*(buf+i));
if (elem == -1 || elem == 0) {
p->cb_printf ("0x%04x", addr);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
if (size != 0 && elem == -1) {
p->cb_printf (", ");
@@ -991,12 +1119,16 @@ static void r_print_format_word(const RPrint* p, int endian, int mode,
: (*(buf+i+1))<<8 | (*(buf+i));
if (elem == -1 || elem == 0) {
p->cb_printf ("%d", addr);
- if (elem == 0) elem = -2;
+ if (elem == 0) {
+ elem = -2;
+ }
}
if (size != 0 && elem == -1) {
p->cb_printf (",");
}
- if (elem > -1) elem--;
+ if (elem > -1) {
+ elem--;
+ }
i += 2;
}
p->cb_printf (" ]");
@@ -1040,12 +1172,16 @@ static void r_print_format_nulltermstring(const RPrint* p, const int len, int en
p->cb_printf ("\\\"");
} else if (IS_PRINTABLE (ch)) {
p->cb_printf ("%c", ch);
- } else p->cb_printf (".");
+ } else {
+ p->cb_printf (".");
+ }
}
p->cb_printf ("\\\"");
} else if (MUSTSEE) {
int j = i;
- if (!SEEVALUE) p->cb_printf ("0x%08"PFMT64x" = ", seeki);
+ if (!SEEVALUE) {
+ p->cb_printf ("0x%08" PFMT64x " = ", seeki);
+ }
for (; j < len && ((size == -1 || size-- > 0) && buf[j]) ; j++) {
if (IS_PRINTABLE (buf[j])) {
p->cb_printf ("%c", buf[j]);
@@ -1110,12 +1246,18 @@ static void r_print_format_bitfield(const RPrint* p, ut64 seeki, char* fmtname,
}
bitfield = r_type_enum_getbitfield (p->sdb_types, fmtname, addr);
if (bitfield && *bitfield) {
- if (MUSTSEEJSON) p->cb_printf ("\"%s\"}", bitfield);
- else if (MUSTSEE) p->cb_printf (" %s (bitfield) = %s\n", fieldname, bitfield);
+ if (MUSTSEEJSON) {
+ p->cb_printf ("\"%s\"}", bitfield);
+ } else if (MUSTSEE) {
+ p->cb_printf (" %s (bitfield) = %s\n", fieldname, bitfield);
+ }
} else {
- if (MUSTSEEJSON) p->cb_printf ("\"`tb %s 0x%x`\"}", fmtname, addr);
- else if (MUSTSEE) p->cb_printf (" %s (bitfield) = `tb %s 0x%x`\n",
+ if (MUSTSEEJSON) {
+ p->cb_printf ("\"`tb %s 0x%x`\"}", fmtname, addr);
+ } else if (MUSTSEE) {
+ p->cb_printf (" %s (bitfield) = `tb %s 0x%x`\n",
fieldname, fmtname, addr);
+ }
}
free (bitfield);
}
@@ -1162,8 +1304,11 @@ static void r_print_format_register (const RPrint* p, int mode,
if (MUSTSET) {
p->cb_printf ("dr %s=%s\n", name, setval);
} else if (MUSTSEE) {
- if (!SEEVALUE) p->cb_printf("%s : 0x%08"PFMT64x"\n", ri->name, p->get_register_value (p->reg, ri));
- else p->cb_printf("0x%08"PFMT64x"\n", p->get_register_value (p->reg, ri));
+ if (!SEEVALUE) {
+ p->cb_printf ("%s : 0x%08" PFMT64x "\n", ri->name, p->get_register_value (p->reg, ri));
+ } else {
+ p->cb_printf ("0x%08" PFMT64x "\n", p->get_register_value (p->reg, ri));
+ }
} else if (MUSTSEEJSON) {
p->cb_printf ("%d}", p->get_register_value (p->reg, ri));
}
@@ -1323,7 +1468,9 @@ int r_print_format_struct_size(const char *f, RPrint *p, int mode, int n) {
tabsize_set = true;
tabsize = r_num_math (NULL, fmt + i + 1);
*end = ']';
- while (fmt[i++] != ']');
+ while (fmt[i++] != ']') {
+ ;
+ }
} else {
tabsize = 1;
}
@@ -1580,7 +1727,9 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
if (!fmt) {
fmt = formatname;
}
- while (*fmt && IS_WHITECHAR (*fmt)) fmt++;
+ while (*fmt && IS_WHITECHAR (*fmt)) {
+ fmt++;
+ }
argend = fmt + strlen (fmt);
arg = fmt;
@@ -1919,7 +2068,9 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
p->cb_printf ("f %s=0x%08"PFMT64x"\n", fieldname, seeki);
} else if (slide/STRUCTFLAG>0 && idx==1) {
p->cb_printf ("%s=0x%08"PFMT64x"\n", fieldname, seeki);
- } else p->cb_printf ("f %s=0x%08"PFMT64x"\n", fieldname , seeki);
+ } else {
+ p->cb_printf ("f %s=0x%08" PFMT64x "\n", fieldname, seeki);
+ }
if (newname) {
free (newname);
newname = fieldname = NULL;
@@ -1940,8 +2091,11 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
/* json */
if (MUSTSEEJSON && mode & R_PRINT_JSON) {
if (oldslide <= slide) {
- if (first) first = 0;
- else p->cb_printf (",");
+ if (first) {
+ first = 0;
+ } else {
+ p->cb_printf (",");
+ }
} else if (oldslide) {
p->cb_printf ("]},");
}
@@ -1973,10 +2127,10 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
p->cb_printf (" NULL\n");
}
isptr = PTRBACK;
- } else
- /* format chars */
- // before to enter in the switch statement check buf boundaries due to updateAddr
- // might go beyond its len and it's usually called in each of the following functions
+ } else {
+ /* format chars */
+ // before to enter in the switch statement check buf boundaries due to updateAddr
+ // might go beyond its len and it's usually called in each of the following functions
#if 0
// those boundaries are wrong. the fix was not correct, we need a reproducer
if (((i+3)= ARRAYINDEX_COEF) size %= ARRAYINDEX_COEF;
+ if (size >= ARRAYINDEX_COEF) {
+ size %= ARRAYINDEX_COEF;
+ }
r_print_format_bitfield (p, seeki, fmtname, fieldname, addr, mode, size);
i+=(size==-1)?1:size;
break;
case 'E': // resolve enum
- if (size >= ARRAYINDEX_COEF) size %= ARRAYINDEX_COEF;
+ if (size >= ARRAYINDEX_COEF) {
+ size %= ARRAYINDEX_COEF;
+ }
r_print_format_enum (p, seeki, fmtname, fieldname, addr, mode, size);
i += (size==-1)? 1: size;
break;
@@ -2110,7 +2275,9 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
}
if (MUSTSEE) {
- if (!SEEVALUE) p->cb_printf ("\n");
+ if (!SEEVALUE) {
+ p->cb_printf ("\n");
+ }
}
if (MUSTSEEJSON) {
if (isptr) {
@@ -2221,6 +2388,7 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
invalid = 1;
break;
} //switch
+ }
#if 0
} else {
eprintf ("r_print_format: Likely a heap buffer overflow (%s)\n", buf);
@@ -2232,9 +2400,13 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
}
if (viewflags && p->offname) {
const char *s = p->offname (p->user, seeki);
- if (s) p->cb_printf ("@(%s)", s);
+ if (s) {
+ p->cb_printf ("@(%s)", s);
+ }
s = p->offname (p->user, addr);
- if (s) p->cb_printf ("*(%s)", s);
+ if (s) {
+ p->cb_printf ("*(%s)", s);
+ }
}
if (tmp != 'D' && !invalid && !fmtname && MUSTSEE) {
p->cb_printf ("\n");
diff --git a/libr/util/graph.c b/libr/util/graph.c
index 3de7b89db4..db8de9aec9 100644
--- a/libr/util/graph.c
+++ b/libr/util/graph.c
@@ -61,15 +61,17 @@ static void dfs_node (RGraph *g, RGraphNode *n, RGraphVisitor *vis, int color[])
int i;
if (from && cur) {
- if (color[cur->idx] == WHITE_COLOR && vis->tree_edge)
+ if (color[cur->idx] == WHITE_COLOR && vis->tree_edge) {
vis->tree_edge (cur_edge, vis);
- else if (color[cur->idx] == GRAY_COLOR && vis->back_edge)
+ } else if (color[cur->idx] == GRAY_COLOR && vis->back_edge) {
vis->back_edge (cur_edge, vis);
- else if (color[cur->idx] == BLACK_COLOR && vis->fcross_edge)
+ } else if (color[cur->idx] == BLACK_COLOR && vis->fcross_edge) {
vis->fcross_edge (cur_edge, vis);
+ }
} else if (!cur && from) {
- if (color[from->idx] != BLACK_COLOR && vis->finish_node)
+ if (color[from->idx] != BLACK_COLOR && vis->finish_node) {
vis->finish_node (from, vis);
+ }
color[from->idx] = BLACK_COLOR;
}
free (cur_edge);
@@ -100,7 +102,9 @@ static void dfs_node (RGraph *g, RGraphNode *n, RGraphVisitor *vis, int color[])
R_API RGraph *r_graph_new () {
RGraph *t = R_NEW0 (RGraph);
- if (!t) return NULL;
+ if (!t) {
+ return NULL;
+ }
t->nodes = r_list_new ();
if (!t->nodes) {
r_graph_free(t);
@@ -191,7 +195,9 @@ R_API void r_graph_add_edge_at (RGraph *t, RGraphNode *from, RGraphNode *to, int
}
R_API void r_graph_del_edge (RGraph *t, RGraphNode *from, RGraphNode *to) {
- if (!from || !to || !r_graph_adjacent (t, from, to)) return;
+ if (!from || !to || !r_graph_adjacent (t, from, to)) {
+ return;
+ }
r_list_delete_data (from->out_nodes, to);
r_list_delete_data (from->all_neighbours, to);
r_list_delete_data (to->in_nodes, from);
@@ -201,14 +207,18 @@ R_API void r_graph_del_edge (RGraph *t, RGraphNode *from, RGraphNode *to) {
/* returns the list of nodes reachable from `n` */
R_API const RList *r_graph_get_neighbours (const RGraph *g, const RGraphNode *n) {
- if (!n) return NULL;
+ if (!n) {
+ return NULL;
+ }
return n->out_nodes;
}
/* returns the n-th nodes reachable from the give node `n`.
* This, of course, depends on the order of the nodes. */
R_API RGraphNode *r_graph_nth_neighbour (const RGraph *g, const RGraphNode *n, int nth) {
- if (!n) return NULL;
+ if (!n) {
+ return NULL;
+ }
return (RGraphNode *)r_list_get_n (n->out_nodes, nth);
}
@@ -228,7 +238,9 @@ R_API const RList *r_graph_get_nodes (const RGraph *g) {
/* true if there is an edge from the node `from` to the node `to` */
R_API int r_graph_adjacent (const RGraph *g, const RGraphNode *from, const RGraphNode *to) {
- if (!g || !from) return false;
+ if (!g || !from) {
+ return false;
+ }
return r_list_contains (from->out_nodes, to) ? true : false;
}
diff --git a/libr/util/hex.c b/libr/util/hex.c
index 4011fb65f0..22dd1b30ad 100644
--- a/libr/util/hex.c
+++ b/libr/util/hex.c
@@ -388,9 +388,13 @@ R_API char *r_hex_bin2strdup(const ut8 *in, int len) {
int i, idx;
char tmp[5], *out;
- if ((len + 1) * 2 < len) return NULL;
+ if ((len + 1) * 2 < len) {
+ return NULL;
+ }
out = malloc ((len + 1) * 2);
- if (!out) return NULL;
+ if (!out) {
+ return NULL;
+ }
for (i = idx = 0; i < len; i++, idx += 2) {
snprintf (tmp, sizeof (tmp), "%02x", in[i]);
memcpy (out+idx, tmp, 2);
@@ -436,7 +440,9 @@ R_API int r_hex_str2bin(const char *in, ut8 *out) {
}
if (nibbles % 2) {
- if (out) r_hex_to_byte (&out[nibbles/2], '0');
+ if (out) {
+ r_hex_to_byte (&out[nibbles / 2], '0');
+ }
return -(nibbles+1) / 2;
}
@@ -448,16 +454,25 @@ R_API int r_hex_str2binmask(const char *in, ut8 *out, ut8 *mask) {
int len, ilen = strlen (in)+1;
int has_nibble = 0;
memcpy (out, in, ilen);
- for (ptr=out; *ptr; ptr++) if (*ptr=='.') *ptr = '0';
+ for (ptr = out; *ptr; ptr++) {
+ if (*ptr == '.') {
+ *ptr = '0';
+ }
+ }
len = r_hex_str2bin ((char*)out, out);
if (len<0) { has_nibble = 1; len = -(len+1); }
if (len != -1) {
memcpy (mask, in, ilen);
- if (has_nibble)
- memcpy (mask+ilen, "f0", 3);
- for (ptr=mask; *ptr; ptr++) *ptr = (*ptr=='.')?'0':'f';
+ if (has_nibble) {
+ memcpy (mask + ilen, "f0", 3);
+ }
+ for (ptr = mask; *ptr; ptr++) {
+ *ptr = (*ptr == '.') ? '0' : 'f';
+ }
len = r_hex_str2bin ((char*)mask, mask);
- if (len<0) len++;
+ if (len < 0) {
+ len++;
+ }
}
return len;
}
@@ -465,16 +480,19 @@ R_API int r_hex_str2binmask(const char *in, ut8 *out, ut8 *mask) {
R_API st64 r_hex_bin_truncate (ut64 in, int n) {
switch (n) {
case 1:
- if ((in&UT8_GT0))
- return UT64_8U|in;
+ if ((in & UT8_GT0)) {
+ return UT64_8U | in;
+ }
return in&UT8_MAX;
case 2:
- if ((in&UT16_GT0))
- return UT64_16U|in;
+ if ((in & UT16_GT0)) {
+ return UT64_16U | in;
+ }
return in&UT16_MAX;
case 4:
- if ((in&UT32_GT0))
- return UT64_32U|in;
+ if ((in & UT32_GT0)) {
+ return UT64_32U | in;
+ }
return in&UT32_MAX;
case 8:
return in&UT64_MAX;
@@ -490,10 +508,12 @@ R_API int r_hex_str_is_valid(const char* str) {
str += 2;
}
for (i = 0; str[i] != '\0'; i++) {
- if (IS_HEXCHAR (str[i]))
+ if (IS_HEXCHAR (str[i])) {
len++;
- if (IS_HEXCHAR (str[i]) || IS_WHITESPACE(str[i]))
+ }
+ if (IS_HEXCHAR (str[i]) || IS_WHITESPACE (str[i])) {
continue;
+ }
return -1; //if we're here, then str isnt valid
}
return len;
diff --git a/libr/util/lib.c b/libr/util/lib.c
index dbba860888..bc2505a6b2 100644
--- a/libr/util/lib.c
+++ b/libr/util/lib.c
@@ -113,11 +113,15 @@ R_API char *r_lib_path(const char *libname) {
char *env = strdup (".:../../../../../../../windows/system32");
const char *ext = ".dll";
#endif
- if (!env) env = strdup (".");
+ if (!env) {
+ env = strdup (".");
+ }
path0 = env;
do {
next = strchr (path0, ':');
- if (next) *next = 0;
+ if (next) {
+ *next = 0;
+ }
snprintf (libpath, sizeof (libpath), "%s/%s%s", path0, libname, ext);
//eprintf ("--> %s\n", libpath);
if (r_file_exists (libpath)) {
@@ -178,8 +182,9 @@ R_API RLibHandler *r_lib_get_handler(RLib *lib, int type) {
RLibHandler *h;
RListIter *iter;
r_list_foreach (lib->handlers, iter, h) {
- if (h->type == type)
+ if (h->type == type) {
return h;
+ }
}
return NULL;
}
@@ -323,7 +328,9 @@ R_API int r_lib_open_ptr (RLib *lib, const char *file, void *handler, RLibStruct
free (p->file);
free (p);
r_lib_dl_close (handler);
- } else r_list_append (lib->plugins, p);
+ } else {
+ r_list_append (lib->plugins, p);
+ }
return ret;
}
@@ -426,8 +433,9 @@ R_API bool r_lib_add_handler(RLib *lib,
}
if (!handler) {
handler = R_NEW (RLibHandler);
- if (!handler)
+ if (!handler) {
return false;
+ }
handler->type = type;
r_list_append (lib->handlers, handler);
}
diff --git a/libr/util/list.c b/libr/util/list.c
index 2e5f6686e1..23572a97d0 100644
--- a/libr/util/list.c
+++ b/libr/util/list.c
@@ -300,7 +300,7 @@ R_API int r_list_del_n(RList *list, int n) {
if (!list) {
return false;
}
- for (it = list->head, i = 0; it && it->data; it = it->n, i++)
+ for (it = list->head, i = 0; it && it->data; it = it->n, i++) {
if (i == n) {
if (!it->p && !it->n) {
list->head = list->tail = NULL;
@@ -318,6 +318,7 @@ R_API int r_list_del_n(RList *list, int n) {
list->length--;
return true;
}
+ }
return false;
}
@@ -371,7 +372,9 @@ R_API RList *r_list_clone(RList *list) {
R_API RListIter *r_list_add_sorted(RList *list, void *data, RListComparator cmp) {
RListIter *it, *item = NULL;
if (list && data && cmp) {
- for (it = list->head; it && it->data && cmp (data, it->data) > 0; it = it->n) ;
+ for (it = list->head; it && it->data && cmp (data, it->data) > 0; it = it->n) {
+ ;
+ }
if (it) {
item = R_NEW0 (RListIter);
if (!item) {
diff --git a/libr/util/log.c b/libr/util/log.c
index 0e7cfc77e5..1b053af03e 100644
--- a/libr/util/log.c
+++ b/libr/util/log.c
@@ -11,7 +11,9 @@ R_API void r_log_file(const char *str) {
if (fd) {
fputs (str, fd);
fclose (fd);
- } else eprintf ("ERR: Cannot open %s\n", logfile);
+ } else {
+ eprintf ("ERR: Cannot open %s\n", logfile);
+ }
}
R_API void r_log_msg(const char *str) {
diff --git a/libr/util/name.c b/libr/util/name.c
index f86d671cc9..8b370206ea 100644
--- a/libr/util/name.c
+++ b/libr/util/name.c
@@ -72,11 +72,15 @@ R_API int r_name_filter(char *name, int maxlen) {
}
// trimming trailing and leading underscores
len = strlen (name);
- for (; len > 0 && *(name + len - 1) == '_'; len--);
+ for (; len > 0 && *(name + len - 1) == '_'; len--) {
+ ;
+ }
if (!len) { // name consists only of underscores
return r_name_check (oname);
}
- for (i = 0; *(name + i) == '_'; i++, len--);
+ for (i = 0; *(name + i) == '_'; i++, len--) {
+ ;
+ }
memmove (name, name + i, len);
*(name + len) = '\0';
return r_name_check (oname);
diff --git a/libr/util/pkcs7.c b/libr/util/pkcs7.c
index 4267b47c44..97d35ab9b1 100644
--- a/libr/util/pkcs7.c
+++ b/libr/util/pkcs7.c
@@ -389,7 +389,9 @@ char* r_pkcs7_signerinfos_dump (RX509CertificateRevocationList *crl, char* buffe
pad = "";
}
pad3 = r_str_newf ("%s ", pad);
- if (!pad3) return NULL;
+ if (!pad3) {
+ return NULL;
+ }
pad2 = pad3 + 2;
algo = crl->signature.algorithm;
@@ -485,7 +487,9 @@ static char* r_x509_signedinfo_dump (RPKCS7SignerInfo *si, char* buffer, ut32 le
}
for (i = 0; i < si->authenticatedAttributes.length; ++i) {
RPKCS7Attribute* attr = si->authenticatedAttributes.elements[i];
- if (!attr) continue;
+ if (!attr) {
+ continue;
+ }
r = snprintf (buffer + p, length - p, "%s%s: %u bytes\n",
pad3, attr->oid ? attr->oid->string : "Missing", attr->data ? attr->data->length : 0);
p += (ut32) r;
diff --git a/libr/util/print.c b/libr/util/print.c
index 7f3fd39a33..5e8248fcb8 100644
--- a/libr/util/print.c
+++ b/libr/util/print.c
@@ -1433,14 +1433,22 @@ R_API void r_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step
if (next < arr[i]) {
//if (arr[i]>0 && i>0) p->cb_printf (" ");
if (arr[i] > INC) {
- for (j = 0; j < next + base; j += INC) p->cb_printf (i? " ": "'");
+ for (j = 0; j < next + base; j += INC) {
+ p->cb_printf (i ? " " : "'");
+ }
+ }
+ for (j = next + INC; j + base < arr[i]; j += INC) {
+ p->cb_printf ("_");
}
- for (j = next + INC; j + base < arr[i]; j += INC) p->cb_printf ("_");
} else {
if (i == 0) {
- for (j = INC; j < arr[i] + base; j += INC) p->cb_printf ("'");
+ for (j = INC; j < arr[i] + base; j += INC) {
+ p->cb_printf ("'");
+ }
} else {
- for (j = INC; j < arr[i] + base; j += INC) p->cb_printf (" ");
+ for (j = INC; j < arr[i] + base; j += INC) {
+ p->cb_printf (" ");
+ }
}
}
//for (j=1;jcb_printf (under);
@@ -1636,7 +1644,9 @@ static bool issymbol(char c) {
static bool check_arg_name (RPrint *print, char *p, ut64 func_addr) {
if (func_addr && print->exists_var) {
int z;
- for (z = 0; p[z] && (IS_ALPHA (p[z]) || IS_DIGIT (p[z]) || p[z] == '_'); z++);
+ for (z = 0; p[z] && (IS_ALPHA (p[z]) || IS_DIGIT (p[z]) || p[z] == '_'); z++) {
+ ;
+ }
char tmp = p[z];
p[z] = '\0';
bool ret = print->exists_var (print, func_addr, p);
diff --git a/libr/util/queue.c b/libr/util/queue.c
index 9d6fcdfb68..e7ad59893e 100644
--- a/libr/util/queue.c
+++ b/libr/util/queue.c
@@ -37,8 +37,9 @@ static int increase_capacity(RQueue *q) {
int i, tmp_front;
newelems = R_NEWS0(void *, new_capacity);
- if (!newelems)
+ if (!newelems) {
return false;
+ }
i = -1;
tmp_front = q->front;
@@ -59,8 +60,9 @@ static int increase_capacity(RQueue *q) {
R_API int r_queue_enqueue(RQueue *q, void *el) {
if (is_full(q)) {
int res = increase_capacity (q);
- if (!res)
+ if (!res) {
return false;
+ }
}
q->rear = (q->rear + 1) % q->capacity;
diff --git a/libr/util/r_json.c b/libr/util/r_json.c
index 8633702e56..611ca60193 100644
--- a/libr/util/r_json.c
+++ b/libr/util/r_json.c
@@ -254,14 +254,18 @@ R_API char* r_json_var_string (RJSVar* var, bool expanded) {
}
for (i = 0; i < var->array.l; i++) {
t[i] = r_json_var_string (var->array.a[i], expanded);
- if (!t[i]) continue;
+ if (!t[i]) {
+ continue;
+ }
len += strlen (t[i]) + 1;
}
c = (char*) calloc (len, 1);
p = c + 1;
e = p + len;
for (i = 0; i < var->array.l; i++) {
- if (!t[i]) continue;
+ if (!t[i]) {
+ continue;
+ }
if (c) {
p += snprintf (p, e - p, "%s,", t[i]);
}
@@ -269,8 +273,9 @@ R_API char* r_json_var_string (RJSVar* var, bool expanded) {
}
if (c) {
c[0] = '[';
- if (p == c + 1)
+ if (p == c + 1) {
p++;
+ }
c[len - (e - p)] = ']';
c[len - 1] = 0;
}
@@ -292,7 +297,9 @@ R_API char* r_json_var_string (RJSVar* var, bool expanded) {
len = 3;
for (i = 0; i < var->object.l; i++) {
t[i] = r_json_var_string (var->object.a[i], expanded);
- if (!t[i]) continue;
+ if (!t[i]) {
+ continue;
+ }
fflush (stdout);
len += strlen (t[i]) + strlen (var->object.n[i]) + 4;
}
@@ -300,7 +307,9 @@ R_API char* r_json_var_string (RJSVar* var, bool expanded) {
p = c + 1;
e = p + len;
for (i = 0; i < var->object.l; i++) {
- if (!t[i]) continue;
+ if (!t[i]) {
+ continue;
+ }
if (c) {
p += snprintf (p, e - p, "\"%s\":%s,", var->object.n[i], t[i]);
}
@@ -308,8 +317,9 @@ R_API char* r_json_var_string (RJSVar* var, bool expanded) {
}
if (c) {
c[0] = '{';
- if (p == c + 1)
+ if (p == c + 1) {
p++;
+ }
c[len - (e - p)] = '}';
c[len - 1] = 0;
}
diff --git a/libr/util/randomart.c b/libr/util/randomart.c
index 6ddeaf4218..d2881d8bcc 100644
--- a/libr/util/randomart.c
+++ b/libr/util/randomart.c
@@ -79,8 +79,9 @@ R_API char *r_print_randomart(const ut8 *dgst_raw, ut32 dgst_raw_len, ut64 addr)
y = R_MIN(y, FLDSIZE_Y - 1);
/* augment the field */
- if (field[x][y] < len - 2)
+ if (field[x][y] < len - 2) {
field[x][y]++;
+ }
input = input >> 2;
}
}
@@ -99,24 +100,27 @@ R_API char *r_print_randomart(const ut8 *dgst_raw, ut32 dgst_raw_len, ut64 addr)
p = strchr(retval, '\0');
/* output upper border */
- for (i = p - retval - 1; i < FLDSIZE_X; i++)
+ for (i = p - retval - 1; i < FLDSIZE_X; i++) {
*p++ = '-';
+ }
*p++ = '+';
*p++ = '\n';
/* output content */
for (y = 0; y < FLDSIZE_Y; y++) {
*p++ = '|';
- for (x = 0; x < FLDSIZE_X; x++)
- *p++ = augmentation_string[R_MIN(field[x][y], len)];
+ for (x = 0; x < FLDSIZE_X; x++) {
+ *p++ = augmentation_string[R_MIN (field[x][y], len)];
+ }
*p++ = '|';
*p++ = '\n';
}
/* output lower border */
*p++ = '+';
- for (i = 0; i < FLDSIZE_X; i++)
+ for (i = 0; i < FLDSIZE_X; i++) {
*p++ = '-';
+ }
*p++ = '+';
*p++ = 0;
diff --git a/libr/util/range.c b/libr/util/range.c
index 1c4ff490ed..19c5c6099c 100644
--- a/libr/util/range.c
+++ b/libr/util/range.c
@@ -62,8 +62,9 @@ RRangeItem *r_range_item_get(RRange *rgs, ut64 addr) {
RRangeItem *r;
RListIter *iter;
r_list_foreach (rgs->ranges, iter, r) {
- if (addr >= r->fr && addr < r->to)
+ if (addr >= r->fr && addr < r->to) {
return r;
+ }
}
return NULL;
}
diff --git a/libr/util/regex/regcomp.c b/libr/util/regex/regcomp.c
index 00a1129dc5..e7fb3e6677 100644
--- a/libr/util/regex/regcomp.c
+++ b/libr/util/regex/regcomp.c
@@ -160,24 +160,43 @@ R_API int r_regex_match (const char *pattern, const char *flags, const char *tex
R_API RRegex *r_regex_new (const char *pattern, const char *flags) {
RRegex rx, *r;
memset(&rx, 0, sizeof(RRegex));
- if (r_regex_comp (&rx, pattern, r_regex_flags (flags)))
+ if (r_regex_comp (&rx, pattern, r_regex_flags (flags))) {
return NULL;
+ }
r = malloc (sizeof (RRegex));
- if (!r) return NULL;
+ if (!r) {
+ return NULL;
+ }
memcpy (r, &rx, sizeof (RRegex));
return r;
}
R_API int r_regex_flags(const char *f) {
int flags = 0;
- if (!f||!*f) return 0;
- if (strchr (f, 'e')) flags |= R_REGEX_EXTENDED;
- if (strchr (f, 'i')) flags |= R_REGEX_ICASE;
- if (strchr (f, 's')) flags |= R_REGEX_NOSUB;
- if (strchr (f, 'n')) flags |= R_REGEX_NEWLINE;
- if (strchr (f, 'N')) flags |= R_REGEX_NOSPEC;
- if (strchr (f, 'p')) flags |= R_REGEX_PEND;
- if (strchr (f, 'd')) flags |= R_REGEX_DUMP;
+ if (!f || !*f) {
+ return 0;
+ }
+ if (strchr (f, 'e')) {
+ flags |= R_REGEX_EXTENDED;
+ }
+ if (strchr (f, 'i')) {
+ flags |= R_REGEX_ICASE;
+ }
+ if (strchr (f, 's')) {
+ flags |= R_REGEX_NOSUB;
+ }
+ if (strchr (f, 'n')) {
+ flags |= R_REGEX_NEWLINE;
+ }
+ if (strchr (f, 'N')) {
+ flags |= R_REGEX_NOSPEC;
+ }
+ if (strchr (f, 'p')) {
+ flags |= R_REGEX_PEND;
+ }
+ if (strchr (f, 'd')) {
+ flags |= R_REGEX_DUMP;
+ }
return flags;
}
@@ -323,8 +342,9 @@ R_API int r_regex_comp(RRegex *preg, const char *pattern, int cflags) {
preg->re_magic = MAGIC1;
#ifndef REDEBUG
/* not debugging, so can't rely on the asssert() in regexec() */
- if (g->iflags&BAD)
- SETERROR(R_REGEX_ASSERT);
+ if (g->iflags & BAD) {
+ SETERROR (R_REGEX_ASSERT);
+ }
#endif
if (p->error) {
r_regex_fini (preg);
@@ -395,11 +415,13 @@ static void p_ere_exp(struct parse *p) {
REQUIRE(MORE(), R_REGEX_EPAREN);
p->g->nsub++;
subno = p->g->nsub;
- if (subno < NPAREN)
- p->pbegin[subno] = HERE();
+ if (subno < NPAREN) {
+ p->pbegin[subno] = HERE ();
+ }
EMIT(OLPAREN, subno);
- if (!SEE(')'))
- p_ere(p, ')');
+ if (!SEE (')')) {
+ p_ere (p, ')');
+ }
if (subno < NPAREN) {
p->pend[subno] = HERE();
if (!p->pend[subno]) {
@@ -429,10 +451,11 @@ static void p_ere_exp(struct parse *p) {
SETERROR(R_REGEX_BADRPT);
break;
case '.':
- if (p->g->cflags&R_REGEX_NEWLINE)
+ if (p->g->cflags & R_REGEX_NEWLINE) {
nonnewline(p);
- else
- EMIT(OANY, 0);
+ } else {
+ EMIT (OANY, 0);
+ }
break;
case '[':
p_bracket(p);
@@ -450,13 +473,15 @@ static void p_ere_exp(struct parse *p) {
break;
}
- if (!MORE())
+ if (!MORE ()) {
return;
+ }
c = PEEK();
/* we call { a repetition if followed by a digit */
- if (!( c == '*' || c == '+' || c == '?' ||
- (c == '{' && MORE2() && isdigit((ut8)PEEK2())) ))
- return; /* no repetition, we're done */
+ if (!(c == '*' || c == '+' || c == '?' ||
+ (c == '{' && MORE2 () && isdigit ((ut8)PEEK2 ())))) {
+ return; /* no repetition, we're done */
+ }
NEXT();
REQUIRE(!wascaret, R_REGEX_BADRPT);
@@ -487,26 +512,31 @@ static void p_ere_exp(struct parse *p) {
if (isdigit((ut8)PEEK())) {
count2 = p_count(p);
REQUIRE(count <= count2, R_REGEX_BADBR);
- } else /* single number with comma */
+ } else { /* single number with comma */
count2 = INTFINITY;
- } else /* just a single number */
+ }
+ } else { /* just a single number */
count2 = count;
+ }
repeat(p, pos, count, count2);
if (!EAT('}')) { /* error heuristics */
- while (MORE() && PEEK() != '}')
- NEXT();
+ while (MORE () && PEEK () != '}') {
+ NEXT ();
+ }
REQUIRE(MORE(), R_REGEX_EBRACE);
SETERROR(R_REGEX_BADBR);
}
break;
}
- if (!MORE())
+ if (!MORE ()) {
return;
+ }
c = PEEK();
- if (!( c == '*' || c == '+' || c == '?' ||
- (c == '{' && MORE2() && isdigit((ut8)PEEK2())) ) )
+ if (!(c == '*' || c == '+' || c == '?' ||
+ (c == '{' && MORE2 () && isdigit ((ut8)PEEK2 ())))) {
return;
+ }
SETERROR(R_REGEX_BADRPT);
}
@@ -584,10 +614,11 @@ p_simp_re(struct parse *p,
}
switch (c) {
case '.':
- if (p->g->cflags&R_REGEX_NEWLINE)
+ if (p->g->cflags & R_REGEX_NEWLINE) {
nonnewline(p);
- else
- EMIT(OANY, 0);
+ } else {
+ EMIT (OANY, 0);
+ }
break;
case '[':
p_bracket(p);
@@ -598,12 +629,14 @@ p_simp_re(struct parse *p,
case BACKSL|'(':
p->g->nsub++;
subno = p->g->nsub;
- if (subno < NPAREN)
- p->pbegin[subno] = HERE();
+ if (subno < NPAREN) {
+ p->pbegin[subno] = HERE ();
+ }
EMIT(OLPAREN, subno);
/* the MORE here is an error heuristic */
- if (MORE() && !SEETWO('\\', ')'))
- p_bre(p, '\\', ')');
+ if (MORE () && !SEETWO ('\\', ')')) {
+ p_bre (p, '\\', ')');
+ }
if (subno < NPAREN) {
p->pend[subno] = HERE();
if (!p->pend[subno]) {
@@ -661,19 +694,23 @@ p_simp_re(struct parse *p,
if (MORE() && isdigit((ut8)PEEK())) {
count2 = p_count(p);
REQUIRE(count <= count2, R_REGEX_BADBR);
- } else /* single number with comma */
+ } else { /* single number with comma */
count2 = INTFINITY;
- } else /* just a single number */
+ }
+ } else { /* just a single number */
count2 = count;
+ }
repeat(p, pos, count, count2);
if (!EATTWO('\\', '}')) { /* error heuristics */
- while (MORE() && !SEETWO('\\', '}'))
- NEXT();
+ while (MORE () && !SEETWO ('\\', '}')) {
+ NEXT ();
+ }
REQUIRE(MORE(), R_REGEX_EBRACE);
SETERROR(R_REGEX_BADBR);
}
- } else if (c == '$') /* $ (but not \$) ends it */
- return(1);
+ } else if (c == '$') { /* $ (but not \$) ends it */
+ return (1);
+ }
return(0);
}
@@ -723,16 +760,20 @@ static void p_bracket(struct parse *p) {
return;
}
- if (EAT('^'))
- invert++; /* make note to invert set at end */
- if (EAT(']'))
+ if (EAT ('^')) {
+ invert++; /* make note to invert set at end */
+ }
+ if (EAT (']')) {
CHadd(cs, ']');
- else if (EAT('-'))
- CHadd(cs, '-');
- while (MORE() && PEEK() != ']' && !SEETWO('-', ']'))
- p_b_term(p, cs);
- if (EAT('-'))
- CHadd(cs, '-');
+ } else if (EAT ('-')) {
+ CHadd (cs, '-');
+ }
+ while (MORE () && PEEK () != ']' && !SEETWO ('-', ']')) {
+ p_b_term (p, cs);
+ }
+ if (EAT ('-')) {
+ CHadd (cs, '-');
+ }
MUSTEAT(']', R_REGEX_EBRACK);
if (p->error != 0) { /* don't mess things up further */
@@ -744,27 +785,34 @@ static void p_bracket(struct parse *p) {
int i;
int ci;
- for (i = p->g->csetsize - 1; i >= 0; i--)
+ for (i = p->g->csetsize - 1; i >= 0; i--) {
if (CHIN(cs, i) && isalpha(i)) {
ci = othercase(i);
- if (ci != i)
- CHadd(cs, ci);
+ if (ci != i) {
+ CHadd (cs, ci);
+ }
}
- if (cs->multis != NULL)
- mccase(p, cs);
+ }
+ if (cs->multis != NULL) {
+ mccase (p, cs);
+ }
}
if (invert) {
int i;
- for (i = p->g->csetsize - 1; i >= 0; i--)
- if (CHIN(cs, i))
+ for (i = p->g->csetsize - 1; i >= 0; i--) {
+ if (CHIN (cs, i)) {
CHsub(cs, i);
- else
- CHadd(cs, i);
- if (p->g->cflags&R_REGEX_NEWLINE)
- CHsub(cs, '\n');
- if (cs->multis != NULL)
- mcinvert(p, cs);
+ } else {
+ CHadd (cs, i);
+ }
+ }
+ if (p->g->cflags & R_REGEX_NEWLINE) {
+ CHsub (cs, '\n');
+ }
+ if (cs->multis != NULL) {
+ mcinvert (p, cs);
+ }
}
if (cs->multis) { /* xxx */
@@ -826,16 +874,19 @@ static void p_b_term(struct parse *p, cset *cs) {
if (SEE('-') && MORE2() && PEEK2() != ']') {
/* range */
NEXT();
- if (EAT('-'))
+ if (EAT ('-')) {
finish = '-';
- else
- finish = p_b_symbol(p);
- } else
+ } else {
+ finish = p_b_symbol (p);
+ }
+ } else {
finish = start;
-/* xxx what about signed chars here... */
+ }
+ /* xxx what about signed chars here... */
REQUIRE(start <= finish, R_REGEX_ERANGE);
- for (i = start; i <= finish; i++)
- CHadd(cs, i);
+ for (i = start; i <= finish; i++) {
+ CHadd (cs, i);
+ }
break;
}
}
@@ -850,12 +901,15 @@ static void p_b_cclass(struct parse *p, cset *cs) {
char *u;
char c;
- while (MORE() && isalpha((unsigned char)PEEK()))
- NEXT();
+ while (MORE () && isalpha ((unsigned char)PEEK ())) {
+ NEXT ();
+ }
len = p->next - sp;
- for (cp = cclasses; cp->name != NULL; cp++)
- if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0')
+ for (cp = cclasses; cp->name != NULL; cp++) {
+ if (strncmp (cp->name, sp, len) == 0 && cp->name[len] == '\0') {
break;
+ }
+ }
if (!cp->name) {
/* oops, didn't find it */
SETERROR(R_REGEX_ECTYPE);
@@ -863,10 +917,12 @@ static void p_b_cclass(struct parse *p, cset *cs) {
}
u = cp->chars;
- while ((c = *u++) != '\0')
- CHadd(cs, c);
- for (u = cp->multis; *u != '\0'; u += strlen(u) + 1)
- MCadd(p, cs, u);
+ while ((c = *u++) != '\0') {
+ CHadd (cs, c);
+ }
+ for (u = cp->multis; *u != '\0'; u += strlen (u) + 1) {
+ MCadd (p, cs, u);
+ }
}
/*
@@ -890,8 +946,9 @@ p_b_symbol(struct parse *p)
char value;
REQUIRE(MORE(), R_REGEX_EBRACK);
- if (!EATTWO('[', '.'))
- return(GETNEXT());
+ if (!EATTWO ('[', '.')) {
+ return (GETNEXT ());
+ }
/* collating symbol */
value = p_b_coll_elem(p, '.');
@@ -910,18 +967,22 @@ p_b_coll_elem(struct parse *p,
struct cname *cp;
int len;
- while (MORE() && !SEETWO(endc, ']'))
- NEXT();
+ while (MORE () && !SEETWO (endc, ']')) {
+ NEXT ();
+ }
if (!MORE()) {
SETERROR(R_REGEX_EBRACK);
return(0);
}
len = p->next - sp;
- for (cp = cnames; cp->name != NULL; cp++)
- if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0')
- return(cp->code); /* known name */
- if (len == 1)
- return(*sp); /* single character */
+ for (cp = cnames; cp->name != NULL; cp++) {
+ if (strncmp (cp->name, sp, len) == 0 && cp->name[len] == '\0') {
+ return (cp->code); /* known name */
+ }
+ }
+ if (len == 1) {
+ return (*sp); /* single character */
+ }
SETERROR(R_REGEX_ECOLLATE); /* neither */
return(0);
}
@@ -934,12 +995,13 @@ othercase(int ch)
{
ch = (ut8)ch;
if (isalpha(ch)) {
- if (isupper(ch))
+ if (isupper (ch)) {
return ((ut8)tolower(ch));
- else if (islower(ch))
+ } else if (islower (ch)) {
return ((ut8)toupper(ch));
- else /* peculiar, but could happen */
- return(ch);
+ } else { /* peculiar, but could happen */
+ return (ch);
+ }
}
return ch;
}
@@ -977,12 +1039,13 @@ ordinary(struct parse *p, int ch)
{
cat_t *cap = p->g->categories;
- if ((p->g->cflags&R_REGEX_ICASE) && isalpha((ut8)ch) && othercase(ch) != ch)
+ if ((p->g->cflags & R_REGEX_ICASE) && isalpha ((ut8)ch) && othercase (ch) != ch) {
bothcases(p, ch);
- else {
+ } else {
EMIT(OCHAR, (ut8)ch);
- if (cap[ch] == 0)
+ if (cap[ch] == 0) {
cap[ch] = p->g->ncategories++;
+ }
}
}
@@ -1027,8 +1090,9 @@ repeat(struct parse *p,
# define MAP(n) (((n) <= 1) ? (n) : ((n) == INTFINITY) ? INF : N)
sopno copy;
- if (p->error != 0) /* head off possible runaway recursion */
+ if (p->error != 0) { /* head off possible runaway recursion */
return;
+ }
if (from > to) {
return;
@@ -1090,8 +1154,9 @@ repeat(struct parse *p,
static int /* useless but makes type checking happy */
seterr(struct parse *p, int e)
{
- if (p->error == 0) /* keep earliest error condition */
+ if (p->error == 0) { /* keep earliest error condition */
p->error = e;
+ }
p->next = nuls; /* try to bring things to a halt */
p->end = nuls;
return(0); /* make the return value well-defined */
@@ -1119,23 +1184,27 @@ static cset * allocset(struct parse *p) {
nbytes = nc / CHAR_BIT * css;
ptr = (cset *)realloc((char *)p->g->sets, nc * sizeof(cset));
- if (!ptr)
+ if (!ptr) {
goto nomem;
+ }
p->g->sets = ptr;
ptr = (ut8 *)realloc((char *)p->g->setbits, nbytes);
- if (!ptr)
+ if (!ptr) {
goto nomem;
+ }
p->g->setbits = ptr;
- for (i = 0; i < no; i++)
- p->g->sets[i].ptr = p->g->setbits + css*(i/CHAR_BIT);
+ for (i = 0; i < no; i++) {
+ p->g->sets[i].ptr = p->g->setbits + css * (i / CHAR_BIT);
+ }
(void) memset((char *)p->g->setbits + (nbytes - css), 0, css);
}
/* XXX should not happen */
- if (!p->g->sets || !p->g->setbits)
+ if (!p->g->sets || !p->g->setbits) {
goto nomem;
+ }
cs = &p->g->sets[no];
cs->ptr = p->g->setbits + css*((no)/CHAR_BIT);
@@ -1164,10 +1233,12 @@ static void freeset(struct parse *p, cset *cs) {
cset *top = &p->g->sets[p->g->ncsets];
size_t css = (size_t)p->g->csetsize;
- for (i = 0; i < css; i++)
- CHsub(cs, i);
- if (cs == top-1) /* recover only the easy case */
+ for (i = 0; i < css; i++) {
+ CHsub (cs, i);
+ }
+ if (cs == top - 1) { /* recover only the easy case */
p->g->ncsets--;
+ }
}
/*
@@ -1189,15 +1260,19 @@ freezeset(struct parse *p, cset *cs)
size_t css = (size_t)p->g->csetsize;
/* look for an earlier one which is the same */
- for (cs2 = &p->g->sets[0]; cs2 < top; cs2++)
+ for (cs2 = &p->g->sets[0]; cs2 < top; cs2++) {
if (cs2->hash == h && cs2 != cs) {
/* maybe */
- for (i = 0; i < css; i++)
- if (!!CHIN(cs2, i) != !!CHIN(cs, i))
- break; /* no */
- if (i == css)
- break; /* yes */
+ for (i = 0; i < css; i++) {
+ if (!!CHIN (cs2, i) != !!CHIN (cs, i)) {
+ break; /* no */
+ }
+ }
+ if (i == css) {
+ break; /* yes */
+ }
}
+ }
if (cs2 < top) { /* found one */
freeset(p, cs);
@@ -1216,9 +1291,11 @@ firstch(struct parse *p, cset *cs)
int i;
size_t css = (size_t)p->g->csetsize;
- for (i = 0; i < css; i++)
- if (CHIN(cs, i))
- return((char)i);
+ for (i = 0; i < css; i++) {
+ if (CHIN (cs, i)) {
+ return ((char)i);
+ }
+ }
return(0); /* arbitrary */
}
@@ -1230,9 +1307,11 @@ static int nch(struct parse *p, cset *cs) {
size_t css = (size_t)p->g->csetsize;
int n = 0;
- for (i = 0; i < css; i++)
- if (CHIN(cs, i))
+ for (i = 0; i < css; i++) {
+ if (CHIN (cs, i)) {
n++;
+ }
+ }
return(n);
}
@@ -1246,8 +1325,9 @@ static void mcadd( struct parse *p, cset *cs, char *cp) {
cs->smultis += strlen(cp) + 1;
np = realloc(cs->multis, cs->smultis);
if (!np) {
- if (cs->multis)
- free(cs->multis);
+ if (cs->multis) {
+ free (cs->multis);
+ }
cs->multis = NULL;
SETERROR(R_REGEX_ESPACE);
return;
@@ -1292,9 +1372,11 @@ isinsets(struct re_guts *g, int c)
int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
unsigned uc = (ut8)c;
- for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize)
- if (col[uc] != 0)
- return(1);
+ for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) {
+ if (col[uc] != 0) {
+ return (1);
+ }
+ }
return(0);
}
@@ -1310,9 +1392,11 @@ samesets(struct re_guts *g, int c1, int c2)
unsigned uc1 = (ut8)c1;
unsigned uc2 = (ut8)c2;
- for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize)
- if (col[uc1] != col[uc2])
- return(0);
+ for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) {
+ if (col[uc1] != col[uc2]) {
+ return (0);
+ }
+ }
return(1);
}
@@ -1328,17 +1412,21 @@ categorize(struct parse *p, struct re_guts *g)
cat_t cat;
/* avoid making error situations worse */
- if (!p || p->error != 0 || !cats )
+ if (!p || p->error != 0 || !cats) {
return;
+ }
- for (c = CHAR_MIN; c <= CHAR_MAX; c++)
+ for (c = CHAR_MIN; c <= CHAR_MAX; c++) {
if ( *(cats+c) && isinsets(g, c)) {
cat = g->ncategories++;
cats[c] = cat;
- for (c2 = c+1; c2 <= CHAR_MAX; c2++)
- if (cats[c2] == 0 && samesets(g, c, c2))
+ for (c2 = c + 1; c2 <= CHAR_MAX; c2++) {
+ if (cats[c2] == 0 && samesets (g, c, c2)) {
cats[c2] = cat;
+ }
+ }
}
+ }
}
/*
@@ -1353,8 +1441,9 @@ dupl(struct parse *p,
sopno len = finish - start;
if (finish >= start) {
- if (len == 0)
- return(ret);
+ if (len == 0) {
+ return (ret);
+ }
enlarge(p, p->ssize + len); /* this many unexpected additions */
if (p->ssize >= p->slen + len) {
(void) memcpy((char *)(p->strip + p->slen),
@@ -1377,15 +1466,17 @@ static void
doemit(struct parse *p, sop op, size_t opnd)
{
/* avoid making error situations worse */
- if (p->error != 0)
+ if (p->error != 0) {
return;
+ }
/* deal with oversize operands ("can't happen", more or less) */
if (opnd < 1<slen >= p->ssize)
- enlarge(p, (p->ssize+1) / 2 * 3); /* +50% */
+ if (p->slen >= p->ssize) {
+ enlarge (p, (p->ssize + 1) / 2 * 3); /* +50% */
+ }
if (p->slen < p->ssize) {
/* finally, it's all reduced to the easy case */
p->strip[p->slen++] = SOP(op, opnd);
@@ -1404,8 +1495,9 @@ doinsert(struct parse *p, sop op, size_t opnd, sopno pos)
int i;
/* avoid making error situations worse */
- if (p->error != 0)
+ if (p->error != 0) {
return;
+ }
sn = HERE();
EMIT(op, opnd); /* do checks, ensure space */
@@ -1438,8 +1530,9 @@ static void
dofwd(struct parse *p, sopno pos, sop value)
{
/* avoid making error situations worse */
- if (p->error != 0)
+ if (p->error != 0) {
return;
+ }
if (value < 1<strip[pos] = OP(p->strip[pos]) | value;
@@ -1454,8 +1547,9 @@ enlarge(struct parse *p, sopno size)
{
sop *sp;
- if (p->ssize >= size)
+ if (p->ssize >= size) {
return;
+ }
sp = (sop *)realloc(p->strip, size*sizeof(sop));
if (!sp) {
@@ -1501,8 +1595,9 @@ findmust(struct parse *p, struct re_guts *g)
sopno i;
/* avoid making error situations worse */
- if (p->error != 0)
+ if (p->error != 0) {
return;
+ }
/* find the longest OCHAR sequence in strip */
newlen = 0;
@@ -1511,8 +1606,9 @@ findmust(struct parse *p, struct re_guts *g)
s = *scan++;
switch (OP(s)) {
case OCHAR: /* sequence member */
- if (newlen == 0) /* new sequence */
+ if (newlen == 0) { /* new sequence */
newstart = scan - 1;
+ }
newlen++;
break;
case OPLUS_: /* things that don't break one */
@@ -1543,8 +1639,9 @@ findmust(struct parse *p, struct re_guts *g)
}
} while (OP(s) != OEND);
- if (g->mlen == 0) /* there isn't one */
+ if (g->mlen == 0) { /* there isn't one */
return;
+ }
/* turn it into a character string */
g->must = malloc((size_t)g->mlen + 1);
@@ -1555,8 +1652,9 @@ findmust(struct parse *p, struct re_guts *g)
cp = g->must;
scan = start;
for (i = g->mlen; i > 0; i--) {
- while (OP(s = *scan++) != OCHAR)
+ while (OP (s = *scan++) != OCHAR) {
continue;
+ }
if (cp < g->must + g->mlen) {
*cp++ = (char)OPND(s);
}
@@ -1577,8 +1675,9 @@ pluscount(struct parse *p, struct re_guts *g)
sopno plusnest = 0;
sopno maxnest = 0;
- if (p->error != 0)
- return(0); /* there may not be an OEND */
+ if (p->error != 0) {
+ return (0); /* there may not be an OEND */
+ }
scan = g->strip + 1;
do {
@@ -1588,13 +1687,15 @@ pluscount(struct parse *p, struct re_guts *g)
plusnest++;
break;
case O_PLUS:
- if (plusnest > maxnest)
+ if (plusnest > maxnest) {
maxnest = plusnest;
+ }
plusnest--;
break;
}
} while (OP(s) != OEND);
- if (plusnest != 0)
+ if (plusnest != 0) {
g->iflags |= BAD;
+ }
return(maxnest);
}
diff --git a/libr/util/regex/regerror.c b/libr/util/regex/regerror.c
index 2b8eefa9c4..f8385365f0 100644
--- a/libr/util/regex/regerror.c
+++ b/libr/util/regex/regerror.c
@@ -121,11 +121,14 @@ regatoi(const RRegex *preg, char *localbuf, int localbufsize)
{
struct rerr *r;
- for (r = rerrs; r->code != 0; r++)
- if (strcmp(r->name, preg->re_endp) == 0)
+ for (r = rerrs; r->code != 0; r++) {
+ if (strcmp (r->name, preg->re_endp) == 0) {
break;
- if (r->code == 0)
- return("0");
+ }
+ }
+ if (r->code == 0) {
+ return ("0");
+ }
(void)snprintf(localbuf, localbufsize, "%d", r->code);
return(localbuf);
diff --git a/libr/util/regex/regexec.c b/libr/util/regex/regexec.c
index 3e8ec4f356..28b0e56389 100644
--- a/libr/util/regex/regexec.c
+++ b/libr/util/regex/regexec.c
@@ -149,17 +149,21 @@ r_regex_exec(const RRegex *preg, const char *string, size_t nmatch,
#else
# define GOODFLAGS(f) ((f)&(R_REGEX_NOTBOL|R_REGEX_NOTEOL|R_REGEX_STARTEND))
#endif
- if (!preg || !string)
+ if (!preg || !string) {
return R_REGEX_ASSERT;
+ }
g = preg->re_g;
- if (preg->re_magic != MAGIC1 || g->magic != MAGIC2)
- return(R_REGEX_BADPAT);
- if (g->iflags&BAD) /* backstop for no-debug case */
- return(R_REGEX_BADPAT);
+ if (preg->re_magic != MAGIC1 || g->magic != MAGIC2) {
+ return (R_REGEX_BADPAT);
+ }
+ if (g->iflags & BAD) { /* backstop for no-debug case */
+ return (R_REGEX_BADPAT);
+ }
eflags = GOODFLAGS(eflags);
- if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags&R_REGEX_LARGE))
+ if (g->nstates <= CHAR_BIT * sizeof (states1) && !(eflags & R_REGEX_LARGE)) {
return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
- else
- return(lmatcher(g, (char *)string, nmatch, pmatch, eflags));
+ } else {
+ return (lmatcher (g, (char *)string, nmatch, pmatch, eflags));
+ }
}
diff --git a/libr/util/sandbox.c b/libr/util/sandbox.c
index 6d2a9db4a7..16fe416168 100644
--- a/libr/util/sandbox.c
+++ b/libr/util/sandbox.c
@@ -66,7 +66,9 @@ R_API bool r_sandbox_check_path (const char *path) {
return false;
}
// Properly check for directrory traversal using "..". First, does it start with a .. part?
- if (path[0]=='.' && path[1]=='.' && (path[2]=='\0' || path[2]=='/')) return 0;
+ if (path[0] == '.' && path[1] == '.' && (path[2] == '\0' || path[2] == '/')) {
+ return 0;
+ }
// Or does it have .. in some other position?
for (p = strstr (path, "/.."); p; p = strstr(p, "/..")) {
@@ -292,8 +294,12 @@ R_API FILE *r_sandbox_fopen (const char *path, const char *mode) {
R_API int r_sandbox_chdir (const char *path) {
if (enabled) {
// TODO: check path
- if (strstr (path, "../")) return -1;
- if (*path == '/') return -1;
+ if (strstr (path, "../")) {
+ return -1;
+ }
+ if (*path == '/') {
+ return -1;
+ }
return -1;
}
return chdir (path);
@@ -301,7 +307,9 @@ R_API int r_sandbox_chdir (const char *path) {
R_API int r_sandbox_kill(int pid, int sig) {
// XXX: fine-tune. maybe we want to enable kill for child?
- if (enabled) return -1;
+ if (enabled) {
+ return -1;
+ }
#if __UNIX__
return kill (pid, sig);
#endif
@@ -332,8 +340,9 @@ R_API HANDLE r_sandbox_opendir (const char *path, WIN32_FIND_DATAW *entry) {
}
#else
R_API DIR* r_sandbox_opendir (const char *path) {
- if (!path)
+ if (!path) {
return NULL;
+ }
if (r_sandbox_enable (0)) {
if (path && !r_sandbox_check_path (path)) {
return NULL;
diff --git a/libr/util/skiplist.c b/libr/util/skiplist.c
index 31d6a044ad..ad5561178b 100644
--- a/libr/util/skiplist.c
+++ b/libr/util/skiplist.c
@@ -85,7 +85,9 @@ static bool delete_element(RSkipList* list, void* data, bool by_data) {
// update forward links for all `update` points,
// by removing the element from the list in each level
for (i = 0; i <= list->list_level; i++) {
- if (update[i]->forward[i] != x) break;
+ if (update[i]->forward[i] != x) {
+ break;
+ }
update[i]->forward[i] = x->forward[i];
}
r_skiplist_node_free (list, x);
@@ -165,7 +167,9 @@ R_API RSkipListNode* r_skiplist_insert(RSkipList* list, void* data) {
}
// randomly choose the number of levels the new node will be put in
- for (x_level = 0; rand() < RAND_MAX/2 && x_level < SKIPLIST_MAX_DEPTH; x_level++);
+ for (x_level = 0; rand () < RAND_MAX / 2 && x_level < SKIPLIST_MAX_DEPTH; x_level++) {
+ ;
+ }
// update the `update` array with default values when the current node
// has a level greater than the current one
diff --git a/libr/util/slist.c b/libr/util/slist.c
index 4254efa250..362a404f89 100644
--- a/libr/util/slist.c
+++ b/libr/util/slist.c
@@ -5,7 +5,9 @@
R_API RSList *r_slist_new() {
RSList *s = R_NEW0 (RSList);
- if (!s) return NULL;
+ if (!s) {
+ return NULL;
+ }
s->list = r_list_new ();
if (!s->list) {
r_slist_free (s);
@@ -22,10 +24,12 @@ R_API void r_slist_free(RSList *s) {
}
R_API int r_slist_get_slot(RSList *s, ut64 addr) {
- if (s->min == 0 && s->min == s->max)
+ if (s->min == 0 && s->min == s->max) {
return -1;
- if (addr < s->min || addr > s->max)
+ }
+ if (addr < s->min || addr > s->max) {
return -1;
+ }
return (addr - s->min) / s->mod;
}
@@ -38,7 +42,9 @@ R_API RSList *r_slist_add(RSList *s, void *data, ut64 from, ut64 to) {
ut64 at = from;
int slot, lastslot;
RSListItem *item = get_new_item ();
- if (!item) return NULL;
+ if (!item) {
+ return NULL;
+ }
//RSListItem **items;
// append to list
item->from = from;
@@ -112,10 +118,12 @@ R_API void r_slist_optimize(RSList *s) {
max = ptr->to;
begin = 0;
} else {
- if (ptr->from < min)
+ if (ptr->from < min) {
min = ptr->from;
- if (ptr->to > max)
+ }
+ if (ptr->to > max) {
max = ptr->to;
+ }
}
}
diff --git a/libr/util/stack.c b/libr/util/stack.c
index 7201ebc9dc..6d884fa953 100644
--- a/libr/util/stack.c
+++ b/libr/util/stack.c
@@ -43,8 +43,9 @@ R_API int r_stack_push(RStack *s, void *el) {
/* reallocate the stack */
s->n_elems *= 2;
s->elems = realloc (s->elems, s->n_elems * sizeof (void *));
- if (!s->elems)
+ if (!s->elems) {
return false;
+ }
}
s->top++;
diff --git a/libr/util/str.c b/libr/util/str.c
index d5916899db..13465bd00d 100644
--- a/libr/util/str.c
+++ b/libr/util/str.c
@@ -197,7 +197,9 @@ R_API ut64 r_str_bits_from_string(const char *buf, const char *bitz) {
/* return the numberic value associated to a string (rflags) */
for (; *buf; buf++) {
char *ch = strchr (bitz, toupper ((const unsigned char)*buf));
- if (!ch) ch = strchr (bitz, tolower ((const unsigned char)*buf));
+ if (!ch) {
+ ch = strchr (bitz, tolower ((const unsigned char)*buf));
+ }
if (ch) {
int bit = (int)(size_t)(ch - bitz);
out |= (ut64)(1LL << bit);
@@ -567,10 +569,16 @@ R_API int r_str_word_count(const char *string) {
const char *text, *tmp;
int word;
- for (text = tmp = string; *text && IS_SEPARATOR (*text); text++);
+ for (text = tmp = string; *text && IS_SEPARATOR (*text); text++) {
+ ;
+ }
for (word = 0; *text; word++) {
- for (;*text && !IS_SEPARATOR (*text); text++);
- for (tmp = text; *text && IS_SEPARATOR (*text); text++);
+ for (; *text && !IS_SEPARATOR (*text); text++) {
+ ;
+ }
+ for (tmp = text; *text && IS_SEPARATOR (*text); text++) {
+ ;
+ }
}
return word;
}
@@ -611,7 +619,9 @@ R_API const char *r_sub_str_lchr(const char *str, int start, int end, char chr)
/* find the first char chr in the substring str[start:end] with end not included */
R_API const char *r_sub_str_rchr(const char *str, int start, int end, char chr) {
- while (str[start] != chr && start < end) start++;
+ while (str[start] != chr && start < end) {
+ start++;
+ }
return str[start] == chr ? &str[start] : NULL;
}
@@ -755,8 +765,12 @@ R_API int r_str_cmp(const char *a, const char *b, int len) {
if ((a == b) || (!a && !b)) {
return 0;
}
- if (!a && b) return -1;
- if (a && !b) return 1;
+ if (!a && b) {
+ return -1;
+ }
+ if (a && !b) {
+ return 1;
+ }
if (len < 0) {
return strcmp (a, b);
}
@@ -776,7 +790,9 @@ R_API int r_str_ccpy(char *dst, char *src, int ch) {
R_API char *r_str_word_get_first(const char *text) {
char *ret;
int len = 0;
- for (;*text && IS_SEPARATOR (*text); text++);
+ for (; *text && IS_SEPARATOR (*text); text++) {
+ ;
+ }
/* strdup */
len = strlen (text);
ret = (char *)malloc (len + 1);
@@ -1353,7 +1369,9 @@ R_API int r_str_ansi_len(const char *str) {
while (str[i]) {
ch = str[i];
if (ch == 0x1b && str[i + 1] == '[') {
- for (++i; str[i] && str[i] != 'J' && str[i] != 'm' && str[i] != 'H'; i++);
+ for (++i; str[i] && str[i] != 'J' && str[i] != 'm' && str[i] != 'H'; i++) {
+ ;
+ }
} else {
len++;
#if 0
@@ -1464,7 +1482,9 @@ R_API const char *r_str_ansi_chrn(const char *str, int n) {
int len, i, li;
for (li = i = len = 0; str[i] && (n!=len); i++) {
if (str[i] == 0x1b && str[i + 1] == '[') {
- for (++i; str[i] && str[i] != 'J' && str[i] != 'm' && str[i] != 'H'; i++);
+ for (++i; str[i] && str[i] != 'J' && str[i] != 'm' && str[i] != 'H'; i++) {
+ ;
+ }
} else {
if ((str[i] & 0xc0) != 0x80) {
len++;
@@ -1508,8 +1528,9 @@ R_API int r_str_ansi_filter(char *str, char **out, int **cposs, int len) {
for (i = j = 0; i < len; i++) {
if ((i + 1) < len && tmp[i] == 0x1b && tmp[i + 1] == '[') {
- for (i += 2; i < len && str[i] != 'J'
- && str[i] != 'm' && str[i] != 'H'; i++);
+ for (i += 2; i < len && str[i] != 'J' && str[i] != 'm' && str[i] != 'H'; i++) {
+ ;
+ }
} else {
str[j] = tmp[i];
cps[j] = i;
@@ -2011,7 +2032,9 @@ R_API void r_str_range_foreach(const char *r, RStrRangeCallback cb, void *u) {
} else {
fprintf (stderr, "Invalid range\n");
}
- for (r++; *r && *r!=','&& *r!='-'; r++);
+ for (r++; *r && *r != ',' && *r != '-'; r++) {
+ ;
+ }
p = r;
}
}
@@ -2050,7 +2073,9 @@ R_API bool r_str_range_in(const char *r, ut64 addr) {
} else {
fprintf (stderr, "Invalid range\n");
}
- for (r++; *r && *r!=','&& *r!='-'; r++);
+ for (r++; *r && *r != ',' && *r != '-'; r++) {
+ ;
+ }
p = r;
}
}
@@ -2275,7 +2300,9 @@ R_API int r_print_format_length(const char *fmt) {
/* get times */
times = atoi (arg);
if (times > 0) {
- while ((*arg>='0'&&*arg<='9')) arg++;
+ while ((*arg >= '0' && *arg <= '9')) {
+ arg++;
+ }
}
bracket = strchr (arg,'{');
if (bracket) {
diff --git a/libr/util/str_trim.c b/libr/util/str_trim.c
index 2923c92b89..68783ac996 100644
--- a/libr/util/str_trim.c
+++ b/libr/util/str_trim.c
@@ -86,7 +86,9 @@ R_API char *r_str_trim(char *str) {
// TODO: rename to r_str_trim_head_ro()
R_API const char *r_str_trim_ro(const char *str) {
if (str) {
- for (; *str && IS_WHITECHAR (*str); str++);
+ for (; *str && IS_WHITECHAR (*str); str++) {
+ ;
+ }
}
return str;
}
@@ -95,7 +97,9 @@ R_API const char *r_str_trim_ro(const char *str) {
// TODO: rename to r_str_trim_head_wp()
R_API const char *r_str_trim_wp(const char *str) {
if (str) {
- for (; *str && !IS_WHITESPACE (*str); str++);
+ for (; *str && !IS_WHITESPACE (*str); str++) {
+ ;
+ }
}
return str;
}
@@ -172,11 +176,10 @@ R_API int r_str_ansi_trim(char *str, int str_len, int n) {
i += 18;
}
} else if (ch2 == '[') {
- for (++i; (i < str_len) && str[i]
- && str[i] != 'J'
- && str[i] != 'm'
- && str[i] != 'H';
- i++);
+ for (++i; (i < str_len) && str[i] && str[i] != 'J' && str[i] != 'm' && str[i] != 'H';
+ i++) {
+ ;
+ }
}
} else if ((str[i] & 0xc0) != 0x80) {
len++;
diff --git a/libr/util/strbuf.c b/libr/util/strbuf.c
index cdee504a82..1a00b86232 100644
--- a/libr/util/strbuf.c
+++ b/libr/util/strbuf.c
@@ -66,8 +66,9 @@ R_API bool r_strbuf_setf(RStrBuf *sb, const char *fmt, ...) {
char string[1024];
va_list ap, ap2;
- if (!sb || !fmt)
+ if (!sb || !fmt) {
return false;
+ }
va_start (ap, fmt);
va_copy (ap2, ap);
rc = vsnprintf (string, sizeof (string), fmt, ap);
@@ -116,7 +117,9 @@ R_API int r_strbuf_append_n(RStrBuf *sb, const char *s, int l) {
allocated = false;
}
if (allocated) {
- if (!p) return false;
+ if (!p) {
+ return false;
+ }
sb->ptr = p;
sb->ptrlen = newlen;
}
diff --git a/libr/util/strpool.c b/libr/util/strpool.c
index 401636ed8a..f6a8a0f7b3 100644
--- a/libr/util/strpool.c
+++ b/libr/util/strpool.c
@@ -8,7 +8,9 @@ R_API RStrpool* r_strpool_new (int sz) {
eprintf ("Malloc failed!\n");
return NULL;
}
- if (sz < 1) sz = 1024;
+ if (sz < 1) {
+ sz = 1024;
+ }
p->str = malloc (sz);
if (!p->str) {
eprintf ("Malloc failed!\n");
diff --git a/libr/util/tree.c b/libr/util/tree.c
index cdae132688..c408e1ca4e 100644
--- a/libr/util/tree.c
+++ b/libr/util/tree.c
@@ -8,22 +8,27 @@ static void tree_dfs_node (RTreeNode *r, RTreeVisitor *vis) {
RTreeNode *n;
s = r_stack_new (16);
- if (!s) return;
+ if (!s) {
+ return;
+ }
r_stack_push (s, r);
while (!r_stack_is_empty (s)) {
RTreeNode *el = (RTreeNode *)r_stack_pop (s);
- if (vis->pre_visit)
+ if (vis->pre_visit) {
vis->pre_visit (el, vis);
+ }
r_list_foreach_prev (el->children, it, n) {
- if (vis->discover_child)
+ if (vis->discover_child) {
vis->discover_child (n, vis);
+ }
r_stack_push (s, n);
}
- if (vis->post_visit)
+ if (vis->post_visit) {
vis->post_visit (el, vis);
+ }
}
r_stack_free (s);
@@ -31,8 +36,9 @@ static void tree_dfs_node (RTreeNode *r, RTreeVisitor *vis) {
static void r_tree_node_free (RTreeNode *n) {
r_list_free (n->children);
- if (n->free)
+ if (n->free) {
n->free (n->data);
+ }
free (n);
}
@@ -52,7 +58,9 @@ static void update_depth (RTreeNode *n, RTreeVisitor *vis) {
static RTreeNode *node_new (RTree *t, void *data) {
RTreeNode *n = R_NEW0 (RTreeNode);
- if (!n) return NULL;
+ if (!n) {
+ return NULL;
+ }
n->children = r_list_new ();
n->data = data;
n->tree = t;
@@ -64,16 +72,18 @@ R_API RTree *r_tree_new (void) {
}
R_API void r_tree_free (RTree* t) {
- if (!t)
+ if (!t) {
return;
+ }
free_all_children (t);
free (t);
}
R_API void r_tree_reset (RTree *t) {
- if (!t)
+ if (!t) {
return;
+ }
free_all_children (t);
t->root = NULL;
@@ -89,8 +99,9 @@ R_API RTreeNode *r_tree_add_node (RTree *t, RTreeNode *node, void *child_data) {
RTreeVisitor vis = { 0 };
/* a NULL node is allowed only the first time, to set the root */
- if (!t || (node && node->tree != t) || (t->root && !node))
+ if (!t || (node && node->tree != t) || (t->root && !node)) {
return NULL;
+ }
child = node_new (t, child_data);
if (!node && !t->root) {
@@ -109,8 +120,9 @@ R_API RTreeNode *r_tree_add_node (RTree *t, RTreeNode *node, void *child_data) {
}
R_API void r_tree_dfs (RTree *t, RTreeVisitor *vis) {
- if (!t || !t->root)
+ if (!t || !t->root) {
return;
+ }
tree_dfs_node (t->root, vis);
}
@@ -118,11 +130,14 @@ R_API void r_tree_dfs (RTree *t, RTreeVisitor *vis) {
R_API void r_tree_bfs (RTree *t, RTreeVisitor *vis) {
RQueue *q;
- if (!t || !t->root)
+ if (!t || !t->root) {
return;
+ }
q = r_queue_new (16);
- if (!q) return;
+ if (!q) {
+ return;
+ }
r_queue_enqueue (q, t->root);
while (!r_queue_is_empty (q)) {
RTreeNode *el = (RTreeNode *)r_queue_dequeue (q);
@@ -133,17 +148,20 @@ R_API void r_tree_bfs (RTree *t, RTreeVisitor *vis) {
RTreeNode *n;
RListIter *it;
- if (vis->pre_visit)
+ if (vis->pre_visit) {
vis->pre_visit (el, vis);
+ }
r_list_foreach (el->children, it, n) {
- if (vis->discover_child)
+ if (vis->discover_child) {
vis->discover_child (n, vis);
+ }
r_queue_enqueue (q, n);
}
- if (vis->post_visit)
+ if (vis->post_visit) {
vis->post_visit (el, vis);
+ }
}
r_queue_free (q);
diff --git a/libr/util/trie.c b/libr/util/trie.c
index 95c2454fbb..f4b15de295 100644
--- a/libr/util/trie.c
+++ b/libr/util/trie.c
@@ -2,9 +2,15 @@
#include "r_util/r_trie.h"
static int c2_idx(char c) {
- if (c <= 'Z' && c >= 'A') return c-'A';
- if (c <= 'z' && c >= 'a') return c-'a'+26;
- if (c <= '9' && c >= '0') return c-'0'+26*2;
+ if (c <= 'Z' && c >= 'A') {
+ return c - 'A';
+ }
+ if (c <= 'z' && c >= 'a') {
+ return c - 'a' + 26;
+ }
+ if (c <= '9' && c >= '0') {
+ return c - '0' + 26 * 2;
+ }
return 26*2 + 10;
}
diff --git a/libr/util/ubase64.c b/libr/util/ubase64.c
index d28589d8b2..4308f821ff 100644
--- a/libr/util/ubase64.c
+++ b/libr/util/ubase64.c
@@ -18,7 +18,9 @@ static const char cb64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
static const char cd64[] = "|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq";
static void b64_encode(const ut8 in[3], char out[4], int len) {
- if (len < 1) return;
+ if (len < 1) {
+ return;
+ }
out[0] = cb64[in[0] >> 2];
out[1] = cb64[((in[0] & 0x03) << 4) | ((len > 1)? ((in[1] & 0xf0) >> 4): 0)];
out[2] = (len > 1? cb64[((in[1] & 0x0f) << 2) | (len > 2? ((in[2] & 0xc0) >> 6): 0)]: '=');
@@ -80,11 +82,13 @@ R_API ut8 *r_base64_decode_dyn(const char *in, int len) {
R_API int r_base64_encode(char *bout, const ut8 *bin, int len) {
int in, out;
- if (len < 0)
+ if (len < 0) {
len = strlen ((const char *)bin);
- for (in = out = 0; in < len; in += 3, out += 4)
+ }
+ for (in = out = 0; in < len; in += 3, out += 4) {
b64_encode (bin + in, (char *)bout + out,
- (len - in) > 3? 3: len - in);
+ (len - in) > 3 ? 3 : len - in);
+ }
bout[out] = 0;
return out;
}
@@ -106,9 +110,10 @@ R_API char *r_base64_encode_dyn(const char *str, int len) {
if (!bout) {
return NULL;
}
- for (in = out = 0; in < len; in += 3, out += 4)
+ for (in = out = 0; in < len; in += 3, out += 4) {
b64_encode ((const ut8 *)str + in, (char *)bout + out,
- (len - in) > 3? 3: len - in);
+ (len - in) > 3 ? 3 : len - in);
+ }
bout[out] = 0;
return bout;
}
diff --git a/libr/util/uleb128.c b/libr/util/uleb128.c
index b2d7b36bd8..9878f4525e 100644
--- a/libr/util/uleb128.c
+++ b/libr/util/uleb128.c
@@ -8,7 +8,9 @@ R_API const ut8 *r_uleb128(const ut8 *data, int datalen, ut64 *v) {
ut8 c;
ut64 s, sum = 0;
const ut8 *data_end;
- if (v) *v = 0LL;
+ if (v) {
+ *v = 0LL;
+ }
if (datalen == ST32_MAX) {
// WARNING; possible overflow
datalen = 0xffff;
@@ -22,13 +24,17 @@ R_API const ut8 *r_uleb128(const ut8 *data, int datalen, ut64 *v) {
for (s = 0; data < data_end; s += 7) {
c = *(data++) & 0xff;
sum |= ((ut32) (c & 0x7f) << s);
- if (!(c & 0x80)) break;
+ if (!(c & 0x80)) {
+ break;
+ }
}
} else {
data++;
}
}
- if (v) *v = sum;
+ if (v) {
+ *v = sum;
+ }
return data;
}
@@ -45,8 +51,12 @@ R_API const ut8 *r_uleb128_decode(const ut8 *data, int *datalen, ut64 *v) {
s += 7;
l++;
} while (c & 0x80);
- if (v) *v = sum;
- if (datalen) *datalen = l;
+ if (v) {
+ *v = sum;
+ }
+ if (datalen) {
+ *datalen = l;
+ }
return data;
}
@@ -65,10 +75,14 @@ R_API const ut8 *r_uleb128_encode(const ut64 s, int *len) {
c = 0; //May not be necessary
c = source & 0x7f;
source >>= 7;
- if (source) c |= 0x80;
+ if (source) {
+ c |= 0x80;
+ }
*(target) = c;
} while (source);
- if (len) *len = l;
+ if (len) {
+ *len = l;
+ }
return otarget;
}
@@ -80,13 +94,17 @@ R_API const ut8 *r_leb128(const ut8 *data, st64 *v) {
c = *(data++) & 0x0ff;
sum |= ((st64) (c & 0x7f) << s);
s += 7;
- if (!(c & 0x80)) break;
+ if (!(c & 0x80)) {
+ break;
+ }
}
}
if ((s < (8 * sizeof (sum))) && (c & 0x40)) {
sum |= -((st64)1 << s);
}
- if (v) *v = sum;
+ if (v) {
+ *v = sum;
+ }
return data;
}
diff --git a/libr/util/unum.c b/libr/util/unum.c
index 486208df22..c6edb663e4 100644
--- a/libr/util/unum.c
+++ b/libr/util/unum.c
@@ -375,7 +375,9 @@ R_API ut64 r_num_math(RNum *num, const char *str) {
#if R_NUM_USE_CALC
ut64 ret;
const char *err = NULL;
- if (!str) return 0LL;
+ if (!str) {
+ return 0LL;
+ }
//if (!str || !*str) return 0LL;
if (num) {
num->dbz = 0;
@@ -458,11 +460,17 @@ R_API double r_num_get_float(RNum *num, const char *str) {
R_API int r_num_to_bits (char *out, ut64 num) {
int size = 64, i;
- if (num>>32) size = 64;
- else if (num&0xff000000) size = 32;
- else if (num&0xff0000) size = 24;
- else if (num&0xff00) size = 16;
- else if (num&0xff) size = 8;
+ if (num >> 32) {
+ size = 64;
+ } else if (num & 0xff000000) {
+ size = 32;
+ } else if (num & 0xff0000) {
+ size = 24;
+ } else if (num & 0xff00) {
+ size = 16;
+ } else if (num & 0xff) {
+ size = 8;
+ }
if (out) {
int pos = 0;
int realsize = 0;
@@ -477,8 +485,9 @@ R_API int r_num_to_bits (char *out, ut64 num) {
realsize = size-i;
}
}
- if (realsize==0)
- out[realsize++] = '0';
+ if (realsize == 0) {
+ out[realsize++] = '0';
+ }
out[realsize] = '\0'; //Maybe not nesesary?
}
@@ -504,7 +513,9 @@ R_API int r_num_to_trits (char *out, ut64 num) {
}
R_API ut64 r_num_chs (int cylinder, int head, int sector, int sectorsize) {
- if (sectorsize<1) sectorsize = 512;
+ if (sectorsize < 1) {
+ sectorsize = 512;
+ }
return (ut64)cylinder * (ut64)head * (ut64)sector * (ut64)sectorsize;
}
@@ -515,17 +526,23 @@ R_API int r_num_conditional(RNum *num, const char *str) {
p = s;
do {
t = strchr (p, ',');
- if (t) *t = 0;
+ if (t) {
+ *t = 0;
+ }
lgt = strchr (p, '<');
if (lgt) {
*lgt = 0;
a = r_num_math (num, p);
if (lgt[1]=='=') {
b = r_num_math (num, lgt+2);
- if (a>b) goto fail;
+ if (a > b) {
+ goto fail;
+ }
} else {
b = r_num_math (num, lgt+1);
- if (a>=b) goto fail;
+ if (a >= b) {
+ goto fail;
+ }
}
} else {
lgt = strchr (p, '>');
@@ -534,10 +551,14 @@ R_API int r_num_conditional(RNum *num, const char *str) {
a = r_num_math (num, p);
if (lgt[1]=='=') {
b = r_num_math (num, lgt+2);
- if (a>= 8;
diff --git a/libr/util/utf8.c b/libr/util/utf8.c
index 6fad121591..3a4bb99f98 100644
--- a/libr/util/utf8.c
+++ b/libr/util/utf8.c
@@ -491,16 +491,24 @@ R_API int r_utf8_decode (const ut8 *ptr, int ptrlen, RRune *ch) {
return 0;
}
if (ptrlen > 0 && ptr[0] < 0x80) {
- if (ch) *ch = (ut32)ptr[0];
+ if (ch) {
+ *ch = (ut32)ptr[0];
+ }
return 1;
} else if (ptrlen>1 && (ptr[0]&0xe0) == 0xc0 && (ptr[1]&0xc0) == 0x80) {
- if (ch) *ch = (ptr[0] & 0x1f) << 6 | (ptr[1] & 0x3f);
+ if (ch) {
+ *ch = (ptr[0] & 0x1f) << 6 | (ptr[1] & 0x3f);
+ }
return 2;
} else if (ptrlen>2 && (ptr[0]&0xf0) == 0xe0 && (ptr[1]&0xc0) == 0x80 && (ptr[2]&0xc0) == 0x80) {
- if (ch) *ch = (ptr[0] & 0xf) << 12 | (ptr[1] & 0x3f) << 6 | (ptr[2] & 0x3f);
+ if (ch) {
+ *ch = (ptr[0] & 0xf) << 12 | (ptr[1] & 0x3f) << 6 | (ptr[2] & 0x3f);
+ }
return 3;
} else if (ptrlen>3 && (ptr[0]&0xf8) == 0xf0 && (ptr[1]&0xc0) == 0x80 && (ptr[2]&0xc0) == 0x80 && (ptr[3]&0xc0) == 0x80) {
- if (ch) *ch = (ptr[0] & 7) << 18 | (ptr[1] & 0x3f) << 12 | (ptr[2] & 0x3f) << 6 | (ptr[3] & 0x3f);
+ if (ch) {
+ *ch = (ptr[0] & 7) << 18 | (ptr[1] & 0x3f) << 12 | (ptr[2] & 0x3f) << 6 | (ptr[3] & 0x3f);
+ }
return 4;
}
return 0;
@@ -537,10 +545,13 @@ R_API int r_utf8_encode (ut8 *ptr, const RRune ch) {
R_API int r_utf8_encode_str (const RRune *str, ut8 *dst, const int dst_length) {
int i, pos = 0;
- if (!str || !dst) return -1;
+ if (!str || !dst) {
+ return -1;
+ }
- for (i = 0; i < sizeof (str) - 1 && str[i] && pos < dst_length - 1; i++)
+ for (i = 0; i < sizeof (str) - 1 && str[i] && pos < dst_length - 1; i++) {
pos += r_utf8_encode (&dst[pos], str[i]);
+ }
dst[pos++] = '\0';
return pos;
diff --git a/libr/util/vector.c b/libr/util/vector.c
index 7f7fa9359a..0fb1eb5dec 100644
--- a/libr/util/vector.c
+++ b/libr/util/vector.c
@@ -262,17 +262,20 @@ R_API void *r_pvector_pop_front(RPVector *vec) {
// CLRS Quicksort. It is slow, but simple.
static void quick_sort(void **a, size_t n, RPVectorComparator cmp) {
- if (n <= 1) return;
+ if (n <= 1) {
+ return;
+ }
int i = rand() % n, j = 0;
void *t, *pivot = a[i];
a[i] = a[n - 1];
- for (i = 0; i < n - 1; i++)
+ for (i = 0; i < n - 1; i++) {
if (cmp (a[i], pivot) < 0) {
t = a[i];
a[i] = a[j];
a[j] = t;
j++;
}
+ }
a[n - 1] = a[j];
a[j] = pivot;
quick_sort (a, j, cmp);
diff --git a/libr/util/x509.c b/libr/util/x509.c
index f0b505572f..aa2fe8f24f 100644
--- a/libr/util/x509.c
+++ b/libr/util/x509.c
@@ -492,7 +492,9 @@ char* r_x509_extensions_dump (RX509Extensions* exts, char* buffer, ut32 length,
for (i = 0, p = 0, r = 0; i < exts->length; ++i) {
//RASN1String *s;
RX509Extension *e = exts->extensions[i];
- if (!e) continue;
+ if (!e) {
+ continue;
+ }
//TODO handle extensions..
//s = r_asn1_stringify_bytes (e->extnValue->sector, e->extnValue->length);
if (len < p) {
@@ -523,7 +525,9 @@ char* r_x509_tbscertificate_dump (RX509TBSCertificate* tbsc, char* buffer, ut32
pad = "";
}
pad2 = r_str_newf ("%s ", pad);
- if (!pad2) return NULL;
+ if (!pad2) {
+ return NULL;
+ }
r = snprintf (buffer, length, "%sVersion: v%u\n"
"%sSerial Number:\n%s %s\n"
"%sSignature Algorithm:\n%s %s\n"
@@ -696,7 +700,9 @@ char* r_x509_crl_dump (RX509CertificateRevocationList *crl, char* buffer, ut32 l
pad = "";
}
pad3 = r_str_newf ("%s ", pad);
- if (!pad3) return NULL;
+ if (!pad3) {
+ return NULL;
+ }
pad2 = pad3 + 2;
algo = crl->signature.algorithm;
last = crl->lastUpdate;
diff --git a/libr/util/zip.c b/libr/util/zip.c
index 335873f38e..c5c09d1faf 100644
--- a/libr/util/zip.c
+++ b/libr/util/zip.c
@@ -48,11 +48,13 @@ R_API ut8 *r_inflate(const ut8 *src, int srcLen, int *srcConsumed, int *dstLen)
do {
if (stream.avail_out == 0) {
- if (! (dst = realloc (dst, stream.total_out + srcLen*2)))
+ if (!(dst = realloc (dst, stream.total_out + srcLen * 2))) {
goto err_exit;
+ }
out_size += srcLen*2;
- if (out_size > MAXOUT)
+ if (out_size > MAXOUT) {
goto err_exit;
+ }
stream.next_out = dst + stream.total_out;
stream.avail_out = srcLen * 2;
}