From 21c98d60ac2005ba9029b1c0febccd25284d5db4 Mon Sep 17 00:00:00 2001 From: Alexis Ehret <08a@riseup.net> Date: Tue, 19 Jan 2021 02:52:48 +0100 Subject: [PATCH] Remove all dead assignment detect by clang sa (#310) ##rizin --- libr/anal/dwarf_process.c | 10 ++++------ libr/core/agraph.c | 2 +- libr/core/cmd.c | 2 +- libr/core/core.c | 3 +-- libr/egg/egg_lang.c | 3 +-- libr/util/print.c | 2 +- shlr/java/code.c | 9 ++++++--- 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/libr/anal/dwarf_process.c b/libr/anal/dwarf_process.c index 7025d374a5..e91cc4fc9a 100644 --- a/libr/anal/dwarf_process.c +++ b/libr/anal/dwarf_process.c @@ -204,14 +204,13 @@ static ut64 get_die_size(const RBinDwarfDie *die) { * @return st32 -1 if error else 0 */ static st32 parse_array_type(Context *ctx, ut64 idx, RStrBuf *strbuf) { - const RBinDwarfDie *die = &ctx->all_dies[idx]; + const RBinDwarfDie *die = &ctx->all_dies[idx++]; if (die->has_children) { int child_depth = 1; - const RBinDwarfDie *child_die = &ctx->all_dies[++idx]; size_t j; for (j = idx; child_depth > 0 && j < ctx->count; j++) { - child_die = &ctx->all_dies[j]; + const RBinDwarfDie *child_die = &ctx->all_dies[j]; // right now we skip non direct descendats of the structure // can be also DW_TAG_suprogram for class methods or tag for templates if (child_depth == 1 && child_die->tag == DW_TAG_subrange_type) { @@ -1148,18 +1147,17 @@ static VariableLocation *parse_dwarf_location (Context *ctx, const RBinDwarfAttr } static st32 parse_function_args_and_vars(Context *ctx, ut64 idx, RStrBuf *args, RList/**/ *variables) { - const RBinDwarfDie *die = &ctx->all_dies[idx]; + const RBinDwarfDie *die = &ctx->all_dies[idx++]; if (die->has_children) { int child_depth = 1; - const RBinDwarfDie *child_die = &ctx->all_dies[++idx]; bool get_linkage_name = prefer_linkage_name (ctx->lang); bool has_linkage_name = false; int argNumber = 1; size_t j; for (j = idx; child_depth > 0 && j < ctx->count; j++) { - child_die = &ctx->all_dies[j]; + const RBinDwarfDie *child_die = &ctx->all_dies[j]; RStrBuf type; r_strbuf_init (&type); const char *name = NULL; diff --git a/libr/core/agraph.c b/libr/core/agraph.c index 651f6e261d..4952774e62 100644 --- a/libr/core/agraph.c +++ b/libr/core/agraph.c @@ -3244,7 +3244,6 @@ static void agraph_follow_innodes(RAGraph *g, bool in) { if (!an) { return; } - RGraphNode *gn = an->gnode; const RList *list = in? an->gnode->in_nodes: an->gnode->out_nodes; int nth = -1; if (r_list_length (list) == 0) { @@ -3252,6 +3251,7 @@ static void agraph_follow_innodes(RAGraph *g, bool in) { } r_cons_gotoxy (0, 2); r_cons_printf (in? "Input nodes:\n": "Output nodes:\n"); + RGraphNode *gn = an->gnode; RList *options = r_list_newf (NULL); RList *gnodes = in? an->gnode->in_nodes: an->gnode->out_nodes; r_list_foreach (gnodes, iter, gn) { diff --git a/libr/core/cmd.c b/libr/core/cmd.c index b4366e6460..92c152a09a 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -2990,7 +2990,7 @@ static int r_core_cmd_subst(RCore *core, char *cmd) { goto beach; } if (*icmd && !strchr (icmd, '"')) { - char *hash = icmd; + char *hash; for (hash = icmd + 1; *hash; hash++) { if (*hash == '\\') { hash++; diff --git a/libr/core/core.c b/libr/core/core.c index a23a902bfe..804ef34b0a 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -3575,10 +3575,9 @@ reaccept: if (cmd == 'G') { // silly http emulation over rap:// char line[256] = {0}; - char *cmd = line; r_socket_read_block (c, (ut8*)line, sizeof (line)); if (!strncmp (line, "ET /cmd/", 8)) { - cmd = line + 8; + char *cmd = line + 8; char *http = strstr (cmd, "HTTP"); if (http) { *http = 0; diff --git a/libr/egg/egg_lang.c b/libr/egg/egg_lang.c index 05109a7c68..99c22b56a2 100644 --- a/libr/egg/egg_lang.c +++ b/libr/egg/egg_lang.c @@ -1161,7 +1161,6 @@ static void rcc_next(REgg *egg) { if (*ptr) { eq = strchr (ptr, '='); if (eq) { - char *p = (char *) skipspaces (ptr); vs = egg->lang.varsize; *buf = *eq = '\x00'; e->mathop (egg, '=', vs, '$', "0", e->regs (egg, 1)); @@ -1172,7 +1171,7 @@ static void rcc_next(REgg *egg) { R_FREE (egg->lang.mathline); tmp = NULL; // following code block is too ugly, oh noes - p = r_egg_mkvar (egg, buf, ptr, 0); + char *p = r_egg_mkvar (egg, buf, ptr, 0); if (is_var (p)) { char *q = r_egg_mkvar (egg, buf, p, 0); if (q) { diff --git a/libr/util/print.c b/libr/util/print.c index fc22432981..81f8196b01 100644 --- a/libr/util/print.c +++ b/libr/util/print.c @@ -841,7 +841,6 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba const char *a, *b; int K = 0; bool hex_style = false; - int rowbytes = p->cols; if (step < len) { len = len - (len % step); } @@ -1026,6 +1025,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba // is this necessary? r_print_set_screenbounds (p, addr); + int rowbytes; int rows = 0; int bytes = 0; bool printValue = true; diff --git a/shlr/java/code.c b/shlr/java/code.c index a48ec008fc..9eb6fb3c59 100644 --- a/shlr/java/code.c +++ b/shlr/java/code.c @@ -55,9 +55,12 @@ static int enter_switch_op (ut64 addr, const ut8* bytes, int len) { return 0; } int sz = 4; - int sz2 = (4 - (addr+1) % 4) + (addr+1) % 4; - IFDBG eprintf ("Addr approach: 0x%04x and BYTES_CONSUMED approach: 0x%04"PFMT64x", BYTES_CONSUMED%%4 = 0x%04x\n", - sz2, BYTES_CONSUMED, sz); + + IFDBG { + int sz2 = (4 - (addr+1) % 4) + (addr+1) % 4; + eprintf ("Addr approach: 0x%04x and BYTES_CONSUMED approach: 0x%04"PFMT64x", BYTES_CONSUMED%%4 = 0x%04x\n", + sz2, BYTES_CONSUMED, sz); + } init_switch_op (); IN_SWITCH_OP = 1; SWITCH_OP.addr = addr;