Fix some more clang analyzer warnings and cleanup

This commit is contained in:
pancake 2016-05-24 14:54:34 +02:00
parent c36b299073
commit d9636a9738
6 changed files with 124 additions and 118 deletions

View File

@ -51,7 +51,7 @@ static int trace_hook_reg_write(RAnalEsil *esil, const char *name, ut64 val) {
}
static int trace_hook_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
char *hexbuf = malloc ((1+len)*3);
char *hexbuf = calloc ((1 + len), 4);
int ret = 0;
if (esil->cb.mem_read) {
ret = esil->cb.mem_read (esil, addr, buf, len);

View File

@ -994,8 +994,9 @@ struct section_t* MACH0_(get_sections)(struct MACH0_(obj_t)* bin) {
/* for core files */
if (bin->nsects <1 && bin->nsegs > 0) {
struct MACH0_(segment_command) *seg;
if (!(sections = malloc ((bin->nsegs + 1) * sizeof (struct section_t))))
if (!(sections = calloc ((bin->nsegs + 1), sizeof (struct section_t)))) {
return NULL;
}
for (i = 0; i < bin->nsegs; i++) {
seg = &bin->segs[i];
sections[i].addr = seg->vmaddr;

View File

@ -484,7 +484,11 @@ char *r_bin_demangle_swift(const char *s, int syscmd) {
}
q += len;
} else {
q++;
if (q) {
q++;
} else {
break;
}
char *n = strstr (q, "__");
if (n) {
q = n + 1;

View File

@ -50,9 +50,9 @@ static int demangle(RCore *core, const char *s) {
return 1;
}
p = strdup (s);
q = p + (ss-s);
q = p + (ss - s);
*q = 0;
demangle_internal (core, p, q+1);
demangle_internal (core, p, q + 1);
free (p);
return 1;
}

View File

@ -490,15 +490,15 @@ static int cmd_write(void *data, const char *input) {
break;
case 'e':
{
ut8 *bin_buf = malloc(str_len);
const int bin_len = r_hex_str2bin(str, bin_buf);
ut8 *bin_buf = malloc (str_len);
const int bin_len = r_hex_str2bin (str, bin_buf);
if (bin_len <= 0) {
fail = 1;
} else {
buf = malloc(str_len * 4 + 1);
len = r_base64_encode((char *)buf, bin_buf, bin_len);
buf = calloc (str_len + 1, 4);
len = r_base64_encode ((char *)buf, bin_buf, bin_len);
if(len == 0) {
free(buf);
free (buf);
fail = 1;
}
}
@ -510,11 +510,11 @@ static int cmd_write(void *data, const char *input) {
break;
}
}
if(!fail) {
if (!fail) {
r_core_write_at (core, core->offset, buf, len);
WSEEK (core, len);
r_core_block_read (core, 0);
free(buf);
free (buf);
} else {
eprintf ("Usage: w6[de] base64/hex\n");
}
@ -542,103 +542,103 @@ static int cmd_write(void *data, const char *input) {
char *input_shadow = NULL, *p = NULL;
switch (input[1]) {
case 'n':
if (input[2] == ' ') {
len = *input ? r_num_math (core->num, input+3) : 0;
if (len > 0){
const ut64 cur_off = core->offset;
cmd_suc = r_core_extend_at (core, core->offset, len);
core->offset = cur_off;
r_core_block_read (core, 0);
}
case 'n':
if (input[2] == ' ') {
len = *input ? r_num_math (core->num, input+3) : 0;
if (len > 0) {
const ut64 cur_off = core->offset;
cmd_suc = r_core_extend_at (core, core->offset, len);
core->offset = cur_off;
r_core_block_read (core, 0);
}
break;
case 'N':
if (input[2] == ' ') {
input += 3;
while (*input && *input == ' ') input++;
addr = r_num_math (core->num, input);
while (*input && *input != ' ') input++;
input++;
len = *input ? r_num_math (core->num, input) : 0;
if (len > 0){
ut64 cur_off = core->offset;
cmd_suc = r_core_extend_at (core, addr, len);
cmd_suc = r_core_seek (core, cur_off, 1);
core->offset = addr;
r_core_block_read (core, 0);
}
}
break;
case 'x':
if (input[2] == ' ') {
input+=2;
len = *input ? strlen (input) : 0;
bytes = len > 1? malloc (len+1) : NULL;
len = bytes ? r_hex_str2bin (input, bytes) : 0;
if (len > 0) {
ut64 cur_off = core->offset;
cmd_suc = r_core_extend_at (core, cur_off, len);
if (cmd_suc) {
r_core_write_at (core, cur_off, bytes, len);
}
core->offset = cur_off;
r_core_block_read (core, 0);
}
free (bytes);
}
break;
case 'X':
if (input[2] == ' ') {
addr = r_num_math (core->num, input+3);
input += 3;
while (*input && *input != ' ') input++;
input++;
len = *input ? strlen (input) : 0;
bytes = len > 1? malloc (len+1) : NULL;
len = bytes ? r_hex_str2bin (input, bytes) : 0;
if (len > 0) {
//ut64 cur_off = core->offset;
cmd_suc = r_core_extend_at (core, addr, len);
if (cmd_suc) {
r_core_write_at (core, addr, bytes, len);
}
core->offset = addr;
r_core_block_read (core, 0);
}
free (bytes);
}
break;
case 's':
input += 3;
}
break;
case 'N':
if (input[2] == ' ') {
input += 3;
while (*input && *input == ' ') input++;
len = strlen (input);
input_shadow = len > 0? malloc (len+1): 0;
// since the distance can be negative,
// the r_num_math will perform an unwanted operation
// the solution is to tokenize the string :/
if (input_shadow) {
strncpy (input_shadow, input, len+1);
p = strtok (input_shadow, " ");
addr = p && *p ? r_num_math (core->num, p) : 0;
p = strtok (NULL, " ");
dist = p && *p ? r_num_math (core->num, p) : 0;
p = strtok (NULL, " ");
b_size = p && *p ? r_num_math (core->num, p) : 0;
if (dist != 0){
r_core_shift_block (core, addr, b_size, dist);
r_core_seek (core, addr, 1);
cmd_suc = true;
}
addr = r_num_math (core->num, input);
while (*input && *input != ' ') input++;
input++;
len = *input ? r_num_math (core->num, input) : 0;
if (len > 0){
ut64 cur_off = core->offset;
cmd_suc = r_core_extend_at (core, addr, len);
cmd_suc = r_core_seek (core, cur_off, 1);
core->offset = addr;
r_core_block_read (core, 0);
}
free (input_shadow);
break;
case '?':
default:
cmd_suc = false;
}
break;
case 'x':
if (input[2] == ' ') {
input += 2;
len = *input ? strlen (input) : 0;
bytes = len > 1? malloc (len+1) : NULL;
len = bytes ? r_hex_str2bin (input, bytes) : 0;
if (len > 0) {
ut64 cur_off = core->offset;
cmd_suc = r_core_extend_at (core, cur_off, len);
if (cmd_suc) {
r_core_write_at (core, cur_off, bytes, len);
}
core->offset = cur_off;
r_core_block_read (core, 0);
}
free (bytes);
}
break;
case 'X':
if (input[2] == ' ') {
addr = r_num_math (core->num, input+3);
input += 3;
while (*input && *input != ' ') input++;
input++;
len = *input ? strlen (input) : 0;
bytes = len > 1? malloc (len+1) : NULL;
len = bytes ? r_hex_str2bin (input, bytes) : 0;
if (len > 0) {
//ut64 cur_off = core->offset;
cmd_suc = r_core_extend_at (core, addr, len);
if (cmd_suc) {
r_core_write_at (core, addr, bytes, len);
}
core->offset = addr;
r_core_block_read (core, 0);
}
free (bytes);
}
break;
case 's':
input += 3;
while (*input && *input == ' ') input++;
len = strlen (input);
input_shadow = len > 0? malloc (len+1): 0;
// since the distance can be negative,
// the r_num_math will perform an unwanted operation
// the solution is to tokenize the string :/
if (input_shadow) {
strncpy (input_shadow, input, len+1);
p = strtok (input_shadow, " ");
addr = p && *p ? r_num_math (core->num, p) : 0;
p = strtok (NULL, " ");
dist = p && *p ? r_num_math (core->num, p) : 0;
p = strtok (NULL, " ");
b_size = p && *p ? r_num_math (core->num, p) : 0;
if (dist != 0){
r_core_shift_block (core, addr, b_size, dist);
r_core_seek (core, addr, 1);
cmd_suc = true;
}
}
free (input_shadow);
break;
case '?':
default:
cmd_suc = false;
}

View File

@ -220,31 +220,32 @@ R_API int r_regex_comp(RRegex *preg, const char *pattern, int cflags) {
# define GOODFLAGS(f) ((f)&~R_REGEX_DUMP)
#endif
cflags = GOODFLAGS(cflags);
if ((cflags&R_REGEX_EXTENDED) && (cflags&R_REGEX_NOSPEC))
cflags = GOODFLAGS (cflags);
if ((cflags & R_REGEX_EXTENDED) && (cflags & R_REGEX_NOSPEC))
return R_REGEX_INVARG;
if (cflags&R_REGEX_PEND) {
if (cflags & R_REGEX_PEND) {
if (preg->re_endp < pattern)
return(R_REGEX_INVARG);
len = preg->re_endp - pattern;
} else len = strlen((char *)pattern);
} else len = strlen ((char *)pattern);
/* do the mallocs early so failure handling is easy */
g = (struct re_guts *)calloc(sizeof(struct re_guts) + (NC-1),sizeof(cat_t));
if (g == NULL)
g = (struct re_guts *)calloc (sizeof (struct re_guts) + (NC - 1), sizeof (cat_t));
if (!g) {
return R_REGEX_ESPACE;
}
preg->re_flags = cflags;
p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */
p->strip = (sop *)calloc(p->ssize, sizeof(sop));
p->ssize = len / (size_t)2 * (size_t)3 + (size_t)1; /* ugh */
p->strip = (sop *)calloc (p->ssize, sizeof(sop));
if (!p->strip) {
free((char *)g);
free ((char *)g);
return R_REGEX_ESPACE;
}
p->slen = 0;
if (p->strip == NULL) {
free((char *)g);
return(R_REGEX_ESPACE);
if (!p->strip) {
free ((char *)g);
return R_REGEX_ESPACE;
}
/* set things up */