Cleanup fixes

* For commit comments and compiler errors
* Fixes for PR comments
* fix some "infer fixes" commits

Signed-off-by: Riccardo Schirone <sirmy15@gmail.com>
This commit is contained in:
Sven Steinbauer 2016-05-19 16:20:35 +01:00 committed by Riccardo Schirone
parent 5cbcdf1da7
commit 8da8ad740f
25 changed files with 109 additions and 64 deletions

View File

@ -33,8 +33,8 @@ static int anal_all = 0;
static RCore* opencore(const char *f) {
const ut64 baddr = UT64_MAX;
RCore *c = r_core_new ();
r_core_loadlibs (c, R_CORE_LOADLIBS_ALL, NULL);
if (!c) return NULL;
r_core_loadlibs (c, R_CORE_LOADLIBS_ALL, NULL);
r_config_set_i (c->config, "io.va", useva);
r_config_set_i (c->config, "anal.split", true);
if (f) {

View File

@ -169,9 +169,10 @@ R_API void r_anal_bb_set_offset(RAnalBlock *bb, int i, ut16 v) {
// the offset of the instruction 0 is not stored because always 0
if (i > 0) {
if (i >= bb->n_op_pos) {
ut16 *tmp_op_pos = realloc (bb->op_pos, (i * 2) * sizeof (*bb->op_pos));
if (!tmp_op_pos) return;
bb->n_op_pos = i * 2;
bb->op_pos = realloc (bb->op_pos, bb->n_op_pos * sizeof (*bb->op_pos));
if (!bb->op_pos) return;
bb->op_pos = tmp_op_pos;
}
bb->op_pos[i - 1] = v;
}

View File

@ -12,7 +12,7 @@ NOTES
#include <r_anal.h>
R_API RAnalCC* r_anal_cc_new () {
RAnalCC *cc = R_NEW (RAnalCC);
RAnalCC *cc = R_NEW0 (RAnalCC);
if (!cc) return NULL;
r_anal_cc_init (cc);
return cc;

View File

@ -177,15 +177,15 @@ R_API RAnalData *r_anal_data_new_string(ut64 addr, const char *p, int len, int t
} else {
ad->str = malloc (len + 1);
if (!ad->str) {
r_anal_data_free(ad);
r_anal_data_free (ad);
return NULL;
}
memcpy (ad->str, p, len);
ad->str[len] = 0;
ad->buf = malloc (len + 1);
if (!ad->buf) {
r_anal_data_free(ad);
eprintf ("Cannot allocate %"PFMT64d" bytes\n", len + 1);
r_anal_data_free (ad);
eprintf ("Cannot allocate %d bytes\n", len + 1);
return NULL;
}
memcpy (ad->buf, ad->str, len + 1);

View File

@ -192,33 +192,33 @@ static int reil_eq(RAnalEsil *esil) {
src_type = src->type;
// Check if the src is an internal var. If it is, we need to resolve it.
if (src_type == ARG_ESIL_INTERNAL) {
reil_flag_spew_inst(esil, src->name + 1);
reil_flag_spew_inst (esil, src->name + 1);
R_FREE (src);
src = reil_pop_arg(esil);
src = reil_pop_arg (esil);
} else if (src_type == ARG_REG) {
// No direct register to register transfer.
ins = R_NEW0 (RAnalReilInst);
if (!ins) return false;
ins->opcode = REIL_STR;
ins->arg[0] = src;
ins->arg[1] = R_NEW0(RAnalReilArg);
ins->arg[1] = R_NEW0 (RAnalReilArg);
if (!ins->arg[1]) {
reil_free_inst (ins);
return false;
}
ins->arg[2] = R_NEW0(RAnalReilArg);
if (!ins->arg[2]) {
reil_free_inst(ins);
reil_free_inst (ins);
return false;
}
reil_make_arg(esil, ins->arg[1], " ");
get_next_temp_reg(esil, tmp_buf);
reil_make_arg(esil, ins->arg[2], tmp_buf);
reil_make_arg (esil, ins->arg[1], " ");
get_next_temp_reg (esil, tmp_buf);
reil_make_arg (esil, ins->arg[2], tmp_buf);
ins->arg[2]->size = ins->arg[0]->size;
reil_print_inst(esil, ins);
reil_push_arg(esil, ins->arg[2]);
reil_free_inst(ins);
src = reil_pop_arg(esil);
reil_print_inst (esil, ins);
reil_push_arg( esil, ins->arg[2]);
reil_free_inst (ins);
src = reil_pop_arg (esil);
}
// First, make a copy of the dst. We will need this to set the flags later on.
@ -264,14 +264,14 @@ static int reil_eq(RAnalEsil *esil) {
reil_make_arg (esil, ins->arg[1], " ");
ins->arg[2] = src;
reil_print_inst (esil, ins);
reil_free_inst(ins);
reil_free_inst (ins);
R_FREE (dst);
return true;
}
reil_cast_size(esil, src, dst);
reil_cast_size (esil, src, dst);
ins->opcode = REIL_STR;
ins->arg[0] = reil_pop_arg(esil);
ins->arg[0] = reil_pop_arg (esil);
if (!ins->arg[0]) {
R_FREE (dst);
reil_free_inst (ins);
@ -279,10 +279,10 @@ static int reil_eq(RAnalEsil *esil) {
}
ins->arg[2] = dst;
ins->arg[1] = R_NEW0(RAnalReilArg);
reil_make_arg(esil, ins->arg[1], " ");
reil_print_inst(esil, ins);
reil_free_inst(ins);
ins->arg[1] = R_NEW0 (RAnalReilArg);
reil_make_arg (esil, ins->arg[1], " ");
reil_print_inst (esil, ins);
reil_free_inst (ins);
return true;
}
@ -302,10 +302,18 @@ static int reil_binop(RAnalEsil *esil, RAnalReilOpcode opcode) {
}
ins = R_NEW0 (RAnalReilInst);
if (!ins) {
R_FREE (op1);
R_FREE (op2);
return false;
}
ins->opcode = opcode;
ins->arg[0] = op2;
ins->arg[1] = op1;
if (!ins->arg[1]) return false;
if (!ins->arg[1]) {
reil_free_inst (ins);
return false;
}
ins->arg[2] = R_NEW0(RAnalReilArg);
if (!ins->arg[2]) {
reil_free_inst (ins);
@ -752,6 +760,7 @@ static int reil_poken(RAnalEsil *esil, ut8 n) {
ins->arg[1] = R_NEW0 (RAnalReilArg);
if (!ins->arg[1]) {
reil_free_inst (ins);
return false;
}
reil_make_arg(esil, ins->arg[1], " ");
reil_print_inst(esil, ins);

View File

@ -1249,7 +1249,7 @@ R_API int r_anal_str_to_fcn(RAnal *a, RAnalFunction *f, const char *sig) {
/* Add 'function' keyword */
str = malloc (strlen(sig) + 10);
if (!str) {
eprintf ("Cannot allocate %"PFMT64d" bytes\n", strlen(sig) + 10);
eprintf ("Cannot allocate %d bytes\n", strlen(sig) + 10);
return false;
}
strcpy (str, "function ");

View File

@ -436,7 +436,7 @@ static int meta_print_item(void *user, const char *k, const char *v) {
it.str = (char *)sdb_decode ((const char*)it.str+1, 0);
else {
it.str = strdup (it.str? it.str: ""); // don't break in free
if (!it.str) goto beach
if (!it.str) goto beach;
}
printmetaitem (ui->anal, &it, ui->rad);
free (it.str);
@ -489,7 +489,6 @@ static int meta_enumerate_cb(void *user, const char *k, const char *v) {
} else {
free(it);
goto beach;
}
//printmetaitem (ui->anal, &it, ui->rad);
r_list_append (list, it);

View File

@ -12,7 +12,7 @@ R_API RAnalValue *r_anal_value_new_from_string(const char *str) {
}
R_API RAnalValue *r_anal_value_copy (RAnalValue *ov) {
RAnalValue *v = R_NEW (RAnalValue);
RAnalValue *v = R_NEW0 (RAnalValue);
if (!v) return NULL;
memcpy (v, ov, sizeof (RAnalValue));
// reference to reg and regdelta should be kept

View File

@ -221,7 +221,7 @@ R_API RAnalVar *r_anal_var_get (RAnal *a, ut64 addr, char kind, int scope, int d
sdb_fmt_tobin (vardef, SDB_VARTYPE_FMT, &vt);
av = R_NEW0 (RAnalVar);
if (!av) return NULL
if (!av) return NULL;
av->addr = addr;
av->scope = scope;
av->delta = delta;
@ -393,7 +393,11 @@ R_API RList *r_anal_var_list(RAnal *a, RAnalFunction *fcn, int kind) {
sdb_fmt_tobin (vardef, SDB_VARTYPE_FMT, &vt);
RAnalVar *av;
av = R_NEW0 (RAnalVar);
if (!av) return NULL;
if (!av) {
free (varlist);
r_list_free (list);
return NULL;
}
av->delta = delta;
av->kind = kind;
av->name = strdup (vt.name);

View File

@ -53,21 +53,23 @@ static int buf_fprintf(void *stream, const char *format, ...) {
flen = strlen (format);
glen = strlen (buf_global);
tmp = malloc (flen + glen + 2);
if (!tmp) {
return 0;
} else {
if (strchr (buf_global, '%')) {
char *buf_local = strdup (buf_global);
if (!buf_local) {
free (tmp);
return 0;
}
escaped = r_str_replace (buf_local, "%", "%%", true);
} else {
escaped = strdup (buf_global);
if (!tmp) return 0;
if (strchr (buf_global, '%')) {
char *buf_local = strdup (buf_global);
if (!buf_local) {
free (tmp);
return 0;
}
escaped = r_str_replace (buf_local, "%", "%%", true);
} else {
escaped = strdup (buf_global);
if (!escaped) {
free (tmp);
return 0;
}
glen = strlen (escaped);
}
glen = strlen (escaped);
if (escaped) {
memcpy (tmp, escaped, glen);

View File

@ -109,6 +109,7 @@ R_API char *r_bin_demangle_msvc(const char *str) {
SDemangler *mangler = 0;
create_demangler (&mangler);
if (!mangler) return NULL;
if (init_demangler (mangler, (char *)str) == eDemanglerErrOK) {
mangler->demangle (mangler, &out/*demangled_name*/);
}

View File

@ -1426,7 +1426,7 @@ RBinSection *getsection(RBin *a, const char *sn) {
r_list_foreach (o->sections, iter, section) {
if (strstr (section->name, sn)) {
return section;
}
}
}
}
return NULL;
@ -1502,11 +1502,9 @@ R_API RList *r_bin_dwarf_parse_line(RBin *a, int mode) {
return NULL;
}
buf = calloc (1, len+1);
if (!buf) return NULL;
ret = r_buf_read_at (binfile->buf, section->paddr, buf, len);
if (!ret) {
free (buf);
return NULL;
}
list = r_list_new (); // always return empty list wtf
list->free = r_bin_dwarf_row_free;
r_bin_dwarf_parse_line_raw2 (a, buf, len, mode);

View File

@ -291,7 +291,7 @@ int get_namespace_and_name( char *buf, STypeCodeStr *type_code_str,
{
int i = 0;
str_info = (SStrInfo *) malloc(sizeof(SStrInfo));
if (!str_info) break;d
if (!str_info) break;
i = get_template(buf + 1, str_info);
if (!i) {
R_FREE(str_info);

View File

@ -781,10 +781,12 @@ void build_command_field(ELeafType lt, char **command_field) {
case eLF_STRUCTURE:
case eLF_UNION:
*command_field = (char *) malloc(strlen("pf") + 1);
if (!(*command_field)) break;
strcpy(*command_field, "pf");
break;
case eLF_ENUM:
*command_field = (char *) malloc(strlen("\"td enum") + 1);
if (!(*command_field)) break;
strcpy(*command_field, "\"td enum");
break;
default:

View File

@ -1099,7 +1099,7 @@ static void get_array_print_type(void *type, char **name)
name_len += strlen (tmp_name);
*name = (char *) malloc (name_len + 1);
if (!(*name)) {
if (tmp_name) free (tmp_name);
free (tmp_name);
return;
}
// name[name_len] = '\0';
@ -1137,7 +1137,7 @@ static void get_pointer_print_type(void *type, char **name)
name_len += strlen (tmp_name);
*name = (char *) malloc (name_len + 1);
if (!(*name)) {
if (tmp_name) free (tmp_name);
free (tmp_name);
return;
}
// name[name_len] = '\0';
@ -1175,7 +1175,7 @@ static void get_modifier_print_type(void *type, char **name)
name_len += strlen (tmp_name);
*name = (char *) malloc(name_len + 1);
if (!(*name)) {
if (tmp_name) free (tmp_name);
free (tmp_name);
return;
}
// name[name_len] = '\0';
@ -1249,6 +1249,7 @@ static void get_fieldlist_print_type(void *type, char **name)
name_len = strlen ("fieldlist ");
*name = (char *) malloc (name_len + 1);
if (!(*name)) return;
// name[name_len] = '\0';
strcpy (*name, "fieldlist ");
}
@ -1526,9 +1527,12 @@ static void get_member_print_type(void *type, char **name)
if (tmp_name)
name_len += strlen (tmp_name);
*name = (char *) malloc (name_len + 1);
if (!(*name)) return;
if (!(*name)) {
if (need_to_free) R_FREE (tmp_name);
return;
}
// name[name_len] = '\0';
strcp y(*name, "(member) ");
strcpy(*name, "(member) ");
if (tmp_name)
strcat (*name, tmp_name);
@ -1578,6 +1582,7 @@ void init_scstring(SCString *cstr, unsigned int size, char *name)
{
cstr->size = size;
cstr->name = (char *) malloc (size);
if (!cstr->name) return;
strcpy (cstr->name, name);
}
@ -1969,11 +1974,11 @@ static void init_stype_info(STypeInfo *type_info)
#define PARSE_LF2(lf_type, lf_func_name, type) { \
STypeInfo *type_info = (STypeInfo *) malloc (sizeof (STypeInfo)); \
if (!type_info) return; \
if (!type_info) return 0; \
lf_type *lf = (lf_type *) malloc (sizeof (lf_type)); \
if (!lf) { \
free (type_info); \
return; \
return 0; \
} \
curr_read_bytes = parse_##lf_func_name (lf, p, read_bytes, len); \
type_info->type_info = (void *) lf; \
@ -2170,7 +2175,7 @@ static int parse_lf_arglist(SLF_ARGLIST *lf_arglist, unsigned char *leaf_data, u
READ (*read_bytes, 4, len, lf_arglist->count, leaf_data, unsigned int);
lf_arglist->arg_type = (unsigned int *) malloc (lf_arglist->count * 4);
if (!lf_arglist->arg_typ) return 0;
if (!lf_arglist->arg_type) return 0;
memcpy (lf_arglist->arg_type, leaf_data, lf_arglist->count * 4);
leaf_data += (lf_arglist->count * 4);
*read_bytes += (lf_arglist->count * 4);
@ -2271,7 +2276,7 @@ static int parse_lf_vtshape(SLF_VTSHAPE *lf_vtshape, unsigned char *leaf_data, u
size = (4 * lf_vtshape->count + (lf_vtshape->count % 2) * 4) / 8;
lf_vtshape->vt_descriptors = (char *) malloc (size);
if (!lf_vtshape) return;
if (!lf_vtshape->vt_descriptors) return 0;
memcpy (lf_vtshape->vt_descriptors, leaf_data, size);
leaf_data += size;
*read_bytes += size;
@ -2284,7 +2289,7 @@ static int parse_lf_vtshape(SLF_VTSHAPE *lf_vtshape, unsigned char *leaf_data, u
#define PARSE_LF(lf_type, lf_func) { \
lf_type *lf = (lf_type *) malloc(sizeof(lf_type)); \
if (!lf) return; \
if (!lf) return 0; \
parse_##lf_func(lf, leaf_data + 2, &read_bytes, type->length); \
type->type_data.type_info = (void *) lf; \
init_stype_info(&type->type_data); \
@ -2328,7 +2333,7 @@ static int parse_tpi_stypes(R_STREAM_FILE *stream, SType *type) {
if (!lf) { \
free (leaf_data); \
return 0; \
}
} \
parse_lf_pointer(lf, leaf_data + 2, &read_bytes, type->length); \
type->type_data.type_info = (void *) lf; \
init_stype_info(&type->type_data); \

View File

@ -14,6 +14,7 @@ R_API void r_bp_traptrace_free(void *ptr) {
R_API RList *r_bp_traptrace_new() {
RList *list = r_list_new();
if (!list) return NULL;
list->free = &r_bp_traptrace_free;
return list;
}

View File

@ -19,6 +19,7 @@ R_API RConfigNode *r_config_node_new(const char *name, const char *value) {
R_API RConfigNode *r_config_node_clone(RConfigNode *n) {
RConfigNode *cn = R_NEW0 (RConfigNode);
if (!cn) return NULL;
cn->name = strdup (n->name);
cn->desc = n->desc? strdup (n->desc): NULL;
cn->hash = n->hash;
@ -411,10 +412,14 @@ R_API int r_config_readonly(RConfig *cfg, const char *key) {
}
R_API RConfig *r_config_new(void *user) {
RConfig *cfg = R_NEW (RConfig);
RConfig *cfg = R_NEW0 (RConfig);
if (!cfg) return NULL;
cfg->ht = r_hashtable_new ();
cfg->nodes = r_list_new ();
if (!cfg->nodes) {
R_FREE (cfg);
return NULL;
}
cfg->nodes->free = r_config_node_free;
cfg->user = user;
cfg->num = NULL;

View File

@ -366,6 +366,7 @@ R_API void r_cons_canvas_fill(RConsCanvas *c, int x, int y, int w, int h, char c
if (w < 0) return;
row = malloc (w + 1);
if (!row) return;
memset (row, ch, w);
row[w] = 0;

View File

@ -343,8 +343,9 @@ R_API void r_cons_fill_line() {
char *p, white[1024];
int cols = I.columns-1;
if (cols<1) return;
p = (cols>=sizeof (white))?
p = (cols >= sizeof (white))?
malloc (cols+1): white;
if (!p) return;
memset (p, ' ', cols);
p[cols] = 0;
r_cons_strcat (p);
@ -424,6 +425,7 @@ R_API void r_cons_push() {
backup_len = I.buffer_len;
backup_size = I.buffer_sz;
I.buffer = malloc (I.buffer_sz);
if (!I.buffer) return;
memcpy (I.buffer, backup, I.buffer_len);
I.buffer_len = 0;
}
@ -849,6 +851,7 @@ R_API void r_cons_set_cup(int enable) {
R_API void r_cons_column(int c) {
char *b = malloc (I.buffer_len+1);
if (!b) return;
memcpy (b, I.buffer, I.buffer_len);
b[I.buffer_len] = 0;
r_cons_reset ();
@ -900,6 +903,7 @@ R_API void r_cons_highlight (const char *word) {
I.highlight = strdup (word);
}
rword = malloc (word_len + linv[0] + linv[1] + 1);
if (!rword) return;
strcpy (rword, inv[0]);
strcpy (rword + linv[0], word);
strcpy (rword + linv[0] + word_len, inv[1]);

View File

@ -280,7 +280,12 @@ R_API int r_cons_grep_line(char *buf, int len) {
size_t i;
in = calloc (1, len + 1);
if (!in) return 0;
out = calloc (1, len + 2);
if (!out) {
free (in);
return 0;
}
memcpy (in, buf, len);
if (cons->grep.nstrings > 0) {

View File

@ -20,6 +20,7 @@ R_API char *r_cons_hud_file(const char *f, const bool usecolor) {
// the lines starting with # )
R_API char *r_cons_hud_string(const char *s, const bool usecolor) {
char *os, *track, *ret, *o = strdup (s);
if (!o) return NULL;
RList *fl = r_list_new ();
int i;
if (!fl) {

View File

@ -479,6 +479,7 @@ R_API int r_cons_yesno(int def, const char *fmt, ...) {
R_API char *r_cons_input(const char *msg) {
char *oprompt = r_line_get_prompt (); //r_cons_singleton()->line->prompt);
if (!oprompt) return NULL;
char buf[1024];
if (msg) {
//r_cons_printf ("%s\n", msg);

View File

@ -48,6 +48,7 @@ static void printpage (const char *line, int *index, RList **mla,
return;
}
p = r_strpool_new (0);
if (!p) return;
for (i = from; i < to; i++) {
color_line (line + index[i], p, mla[i]);
r_strpool_ansi_chop (p, w);
@ -121,6 +122,7 @@ static int all_matches(const char *s, RRegex *rx, RList **mla,
m.rm_so = 0;
const char *loff = s + lines[l]; /* current line offset */
char *clean = strdup(loff);
if (!clean) return 0;
int *cpos;
r_str_ansi_filter(clean, NULL, &cpos, 0);
m.rm_eo = slen = strlen(clean);
@ -159,11 +161,13 @@ R_API int r_cons_less_str(const char *str, const char *exitkeys) {
if (str == NULL || str[0] == '\0') return 0;
char *p = strdup (str);
if (!p) return 0;
int *lines = splitlines (p, &lines_count);
if (lines_count<1) {
mla = NULL;
} else {
mla = calloc (lines_count, sizeof (RList *));
if (!mla) return 0;
}
for (i = 0; i < lines_count; i++)
mla[i] = r_list_new ();

View File

@ -152,6 +152,7 @@ R_API char *r_cons_pal_parse (const char *str) {
ut8 r, g, b;
char out[128];
char *s = strdup (str);
if (!s) return NULL;
char *p = strchr (s + 1, ' ');
out[0] = 0;
if (p) *p++ = 0;

View File

@ -149,6 +149,7 @@ R_API int r_cons_rgb_parse (const char *p, ut8 *r, ut8 *g, ut8 *b, int *is_bg) {
R_API char *r_cons_rgb_str (char *outstr, ut8 r, ut8 g, ut8 b, int is_bg) {
int fgbg = is_bg ? 48: 38;
if (!outstr) outstr = malloc (32);
if (!outstr) return NULL;
switch (r_cons_singleton ()->truecolor) {
case 1: // 256 color palette