}
break;
case R_ANAL_OP_TYPE_UPUSH:
- if ((op->type & R_ANAL_OP_TYPE_REG) && last_is_reg_mov_lea && src0 && src0->reg
- && src0->reg && !strcmp (src0->reg, last_reg_mov_lea_name)) {
+ if ((op->type & R_ANAL_OP_TYPE_REG) && last_is_reg_mov_lea \
+ && (src0 && src0->reg && !strcmp (src0->reg, last_reg_mov_lea_name))) {
last_is_push = true;
last_push_addr = last_reg_mov_lea_val;
if (anal->iob.is_valid_offset (anal->iob.io, last_push_addr, 1)) {
static ut32 rev(ArmOp *op) {
ut32 data = UT32_MAX;
int k = 0;
- const bool reg64 = op->operands[0].reg_type & ARM_REG64 && op->operands[0].reg_type & ARM_REG64;
- const bool reg32 = op->operands[0].reg_type & ARM_REG32 && op->operands[0].reg_type & ARM_REG32;
+ const bool reg64 = op->operands[0].reg_type & ARM_REG64;
+ const bool reg32 = op->operands[0].reg_type & ARM_REG32;
check_cond (op->operands[0].type == ARM_GPR);
check_cond (op->operands[1].type == ARM_GPR);
#include "lua53.h"
typedef struct plugin_data_t {
- ut32 *current_write_prt;
+ ut32 instructions[256];
ut32 current_write_index;
} PluginData;
chars_skipped += j;
R_LOG_DEBUG ("Opcode %i Instruction %s", i, instruction_names[i]);
- SET_OPCODE (state->current_write_prt[state->current_write_index], i); // sets the opcode
+ SET_OPCODE (state->instructions[state->current_write_index], i); // sets the opcode
doParse1 (state, chars_skipped, parseParameters, str, i); // Parse parameters
}
switch (parameter) {
case PARAMETER_A:
- SETARG_A (state->current_write_prt[state->current_write_index], resultingNumber);
+ SETARG_A (state->instructions[state->current_write_index], resultingNumber);
break;
case PARAMETER_B:
- SETARG_B (state->current_write_prt[state->current_write_index], resultingNumber);
+ SETARG_B (state->instructions[state->current_write_index], resultingNumber);
break;
case PARAMETER_C:
- SETARG_C (state->current_write_prt[state->current_write_index], resultingNumber);
+ SETARG_C (state->instructions[state->current_write_index], resultingNumber);
break;
case PARAMETER_Ax:
- SETARG_Ax (state->current_write_prt[state->current_write_index], resultingNumber);
+ SETARG_Ax (state->instructions[state->current_write_index], resultingNumber);
break;
case PARAMETER_Bx:
- SETARG_Bx (state->current_write_prt[state->current_write_index], resultingNumber);
+ SETARG_Bx (state->instructions[state->current_write_index], resultingNumber);
break;
case PARAMETER_sBx:
- SETARG_sBx (state->current_write_prt[state->current_write_index], resultingNumber);
+ SETARG_sBx (state->instructions[state->current_write_index], resultingNumber);
break;
}
return skipped_chars;
char *c = "move 1 2\n forprep 13 -2";
int p = 0;
PluginData state = {0};
- state.current_write_prt = malloc (8);
eprintf ("Parsing String: %s\n", c);
eprintf ("-----------------------\n");
doParse0 (state, p, parseNextInstruction, c, (int) strlen (c));
eprintf ("Parsed Characters %i\n", p);
- eprintf ("%d %08x\n", state.current_write_index, current_write_prt[state.current_write_index - 1]);
+ eprintf ("%d %08x\n", state.current_write_index, state.instructions[state.current_write_index - 1]);
eprintf ("------------\n");
doParse0 (state, p, parseNextInstruction, c, (int) strlen (c));
eprintf ("Parsed Characters %i\n", p);
- eprintf ("%d %08x\n", state.current_write_index, current_write_prt[state.current_write_index - 1]);
+ eprintf ("%d %08x\n", state.current_write_index, state.instructions[state.current_write_index - 1]);
eprintf ("------------\n");
RAsmOp *asmOp = (RAsmOp *) malloc (sizeof (RAsmOp));
- int advanced = lua53dissasm (&state, asmOp, (const char *) current_write_prt, 4);
+ int advanced = lua53dissasm (&state, asmOp, (const ut8 *) state.instructions, 4);
eprintf ("%s\n", asmOp->buf_asm);
- lua53dissasm (&state, asmOp, (const char *) current_write_prt + advanced, 4);
+ lua53dissasm (&state, asmOp, (const ut8 *) state.instructions + advanced, 4);
eprintf ("%s\n", asmOp->buf_asm);
- free (state.current_write_prt);
return 0;
}
#endif // MAIN_ASM
PluginData *pd = as->data;
int parsed = 0;
- ut32 instruction;
- pd->current_write_prt = &instruction;
pd->current_write_index = 0;
doParse0 (pd, parsed, parseNextInstruction, op->mnemonic);
if (!op->bytes) {
return false;
}
- setInstruction (instruction, op->bytes);
+ setInstruction (pd->instructions[0], op->bytes);
- R_LOG_DEBUG ("parsed: %d instruction: %d", parsed, instruction);
+ R_LOG_DEBUG ("parsed: %d instruction: %d", parsed, pd->instructions[0]);
return true;
}
mnemonic_alu1[op], gpr_map[rt], gpr_map[ra], gpr_map[rb]);
return;
case 0x9: /* srli */
- if (ra ==0 && rb == 0 && rb==0)
- {
+ if (ra ==0 && rb == 0) {
func (stream, "nop");
return;
}
o.rd = get_operand_value (insn, type_descr, INSN_OPER_D);
o.ra = get_operand_value (insn, type_descr, INSN_OPER_A);
o.i = get_operand_value (insn, type_descr, INSN_OPER_I);
- if (regs->cpu_enable & (1 << o.ra) & regs->cpu_enable & (1 << o.rd)) {
+ if (regs->cpu_enable & (1 << o.ra) && regs->cpu_enable & (1 << o.rd)) {
regs->cpu[o.rd] = regs->cpu[o.ra] | o.i;
regs->cpu_enable |= (1 << o.rd);
op->ptr = regs->cpu[o.rd];
mem_base_reg_known = true;
mem_base_reg = 15;
}
- if ( enc->coding_method == tic6x_coding_mem_offset_noscale
- || enc->coding_method == tic6x_coding_mem_offset_noscale )
+ if (enc->coding_method == tic6x_coding_mem_offset_noscale)
mem_scaled = false;
}
break;
free (self);
}
-static bool dsc_header_get_field(RDSCHeader * self, const char * name, ut8 * out_value, size_t size) {
- ut64 cursor;
- ut64 data_len;
+static bool dsc_header_get_field(RDSCHeader *self, const char *name, ut8 *out_value, size_t size) {
const RDSCField * field;
ut8 tmp[32];
- data_len = r_buf_size (self->buf);
- cursor = 0;
-
+ ut64 data_len = r_buf_size (self->buf);
+ ut64 cursor = 0;
+ // Initialize out value to avoid UB
+ memset (out_value, 0, size);
for (field = self->fields; field->name != NULL && cursor < data_len; field++) {
st64 field_size = r_buf_fread_at (self->buf, cursor, tmp, field->format, 1);
if (field_size < 0) {
return false;
}
-
if (!strcmp (field->name, name)) {
if (size < field_size) {
return false;
memcpy (out_value, tmp, field_size);
return true;
}
-
cursor += field_size;
}
return false;
}
-static bool dsc_header_get_u64(RDSCHeader * self, const char * name, ut64 * out_value) {
+static bool dsc_header_get_u64(RDSCHeader *self, const char *name, ut64 *out_value) {
return dsc_header_get_field (self, name, (ut8 *) out_value, sizeof (ut64));
}
-static bool dsc_header_get_u32(RDSCHeader * self, const char * name, ut32 * out_value) {
+static bool dsc_header_get_u32(RDSCHeader *self, const char *name, ut32 *out_value) {
return dsc_header_get_field (self, name, (ut8 *) out_value, sizeof (ut32));
}
return false;
}
r_config_set (core->config, "asm.parser", node->value);
-
- if (core->anal->cur && ! (core->anal->config->bits & core->anal->config->bits)) {
- r_config_set_i (core->config, "asm.bits", bits);
- } else if (core->anal->cur && ! (core->rasm->config->bits & core->anal->config->bits)) {
+ if (core->anal->cur && ! (core->rasm->config->bits & core->anal->config->bits)) {
r_config_set_i (core->config, "asm.bits", bits);
}
-
r_debug_set_arch (core->dbg, node->value, bits);
if (!r_config_set (core->config, "anal.arch", node->value)) {
char *p, *s = strdup (node->value);
case 's': buf[i] -= str[j]; break;
case 'm': buf[i] *= str[j]; break;
case 'w': buf[i] = str[j]; break;
- case 'd': buf[i] = (str[j])? (buf[i] / str[j]): 0; break;
+ case 'd': {
+ ut8 divisor = str[j];
+ buf[i] = divisor ? (buf[i] / divisor) : 0;
+ break;
+ }
case 'r': buf[i] >>= str[j]; break;
case 'l': buf[i] <<= str[j]; break;
case 'o': buf[i] |= str[j]; break;
if (R_UNLIKELY (r_str_startswith (cmd, "GET /cmd/"))) {
memmove (cmd, cmd + 9, strlen (cmd + 9) + 1);
char *http = strstr (cmd, "HTTP");
- if (http) {
+ if (http && http > cmd) {
*http = 0;
http--;
if (*http == ' ') {
if (!r_str_ncpy (line, "ET /cmd/", 8)) {
char *cmd = line + 8;
char *http = strstr (cmd, "HTTP");
- if (http) {
+ if (http && http > cmd) {
*http = 0;
http--;
if (*http == ' ') {
static bool apfs_resolve_omap(ApfsFS *ctx, ut64 oid, ut64 *paddr) {
R_LOG_DEBUG ("apfs_resolve_omap: resolving OID %" PFMT64u ", omap_tree_oid=%" PFMT64u, oid, ctx->omap_tree_oid);
- if (!ctx->omap_tree_oid) {
+
+ if (ctx->omap_tree_oid) {
+ *paddr = 0;
+ } else {
// Direct mapping for simple cases
*paddr = oid;
R_LOG_DEBUG ("apfs_resolve_omap: direct mapping to paddr %" PFMT64u, *paddr);
int byte_len = 0;
const ut8 *bytes = r_muta_charset_lookup_encode (table, tok, &byte_len);
- if (!bytes || byte_len < 1) {
- ut8 q = unknown_byte;
- if (!r_muta_charset_outgrow (&out, &outcap, outpos + 1)) {
+ if (bytes && byte_len > 0) {
+ if (!r_muta_charset_outgrow (&out, &outcap, outpos + byte_len)) {
*out_len = 0;
return NULL;
}
- out[outpos++] = q;
+ memcpy (out + outpos, bytes, byte_len);
+ outpos += byte_len;
} else {
- if (!r_muta_charset_outgrow (&out, &outcap, outpos + byte_len)) {
+ ut8 q = unknown_byte;
+ if (!r_muta_charset_outgrow (&out, &outcap, outpos + 1)) {
*out_len = 0;
return NULL;
}
- memcpy (out + outpos, bytes, byte_len);
- outpos += byte_len;
+ out[outpos++] = q;
}
-
str += consumed;
}
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
/* Adapted code from:
- bdiff.c - efficient binary diff extension for Mercurial
+bdiff.c - efficient binary diff extension for Mercurial
- Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
+Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
- This software may be used and distributed according to the terms of
- the GNU General Public License, incorporated herein by reference.
+This software may be used and distributed according to the terms of
+the GNU General Public License, incorporated herein by reference.
- Based roughly on Python difflib
-*/
+Based roughly on Python difflib
+ */
#include <r_util.h>
static int splitlines(const char *a, int len, struct line **lr) {
int h, i;
const char *p, *b = a;
- const char * const plast = a + len - 1;
+ const char *const plast = a + len - 1;
struct line *l;
if (!a) {
}
}
- *lr = l = (struct line *)malloc(sizeof (struct line) * i);
+ *lr = l = (struct line *)malloc (sizeof (struct line) * i);
if (!l) {
return -1;
}
/* 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));
+ h = (struct pos *)malloc (scale * buckets * sizeof (struct pos));
if (h) {
break;
}
buckets = buckets * scale - 1;
/* clear the hash table */
+ memset (h, 0, (buckets + 1) * sizeof (struct pos));
for (i = 0; i <= buckets; i++) {
h[i].pos = INT_MAX;
- h[i].len = 0;
}
/* add lines to the hash table chains */
}
/* compute popularity threshold */
- t = (bn >= 4000) ? bn / 1000 : bn + 1;
+ t = (bn >= 4000)? bn / 1000: bn + 1;
/* match items in a to their equivalence class in b */
for (i = 0; i < an; i++) {
return 1;
}
-static int longest_match(struct line *a, struct line *b, struct pos *pos,
- int a1, int a2, int b1, int b2, int *omi, int *omj)
-{
+static int longest_match(struct line *a, struct line *b, struct pos *pos, int a1, int a2, int b1, int b2, int *omi, int *omj) {
int mi = a1, mj = b1, mk = 0, mb = 0, i, j, k;
for (i = a1; i < a2; i++) {
return mk + mb;
}
-static void recurse(struct line *a, struct line *b, struct pos *pos,
- int a1, int a2, int b1, int b2, struct hunklist *l)
-{
+static void recurse(struct line *a, struct line *b, struct pos *pos, int a1, int a2, int b1, int b2, struct hunklist *l) {
int i, j, k;
/* find the longest match in this chunk */
- k = longest_match(a, b, pos, a1, a2, b1, b2, &i, &j);
+ k = longest_match (a, b, pos, a1, a2, b1, b2, &i, &j);
if (!k) {
return;
}
/* and recurse on the remaining chunks on either side */
- recurse(a, b, pos, a1, i, b1, j, l);
+ recurse (a, b, pos, a1, i, b1, j, l);
if (l->head < l->end) {
l->head->a1 = i;
l->head->a2 = i + k;
l->head->b2 = j + k;
l->head++;
}
- recurse(a, b, pos, i + k, a2, j + k, b2, l);
+ recurse (a, b, pos, i + k, a2, j + k, b2, l);
}
static struct hunklist diff(struct line *a, int an, struct line *b, int bn) {
/* allocate and fill arrays */
t = equatelines (a, an, b, bn);
- pos = (struct pos *)calloc (bn ? bn : 1, sizeof (struct pos));
+ pos = (struct pos *)calloc (bn? bn: 1, sizeof (struct pos));
/* we can't have more matches than lines in the shorter file */
- l.head = l.base = (struct hunk *)malloc (sizeof (struct hunk)
- * ((an<bn ? an:bn) + 1));
- l.end = l.base + ((an<bn ? an:bn) + 1);
+ l.head = l.base = (struct hunk *)malloc (sizeof (struct hunk) *((an < bn? an: bn) + 1));
+ l.end = l.base + ((an < bn? an: bn) + 1);
if (pos && l.base && t) {
/* generate the matching block list */
- recurse(a, b, pos, 0, an, 0, bn, &l);
+ recurse (a, b, pos, 0, an, 0, bn, &l);
if (l.head < l.end) {
l.head->a1 = l.head->a2 = an;
l.head->b1 = l.head->b2 = bn;
/* normalize the hunk list, try to push each hunk towards the end */
for (curr = l.base; curr != l.head; curr++) {
- struct hunk *next = curr+1;
+ struct hunk *next = curr + 1;
int shift = 0;
if (next == l.head) {
int hits = -1;
an = splitlines ((const char *)sa, la, &al);
- if (an<0) {
+ if (an < 0) {
free (al);
return -1;
}
bn = splitlines ((const char *)sb, lb, &bl);
- if (bn<0) {
+ if (bn < 0) {
free (al);
free (bl);
return -1;
len = bl[h->b1].l - bl[lb].l;
offa = al[la].l - al->l;
offb = al[h->a1].l - al->l;
- rlen = offb-offa;
+ rlen = offb - offa;
if (d->callback) {
/* source file */
la = h->a2;
lb = h->b2;
}
- beach:
+beach:
free (al);
free (bl);
free (l.base);
return p;
}
-R_API char *r_str_scale(const char *s, int w, int h) {
+R_API char *r_str_scale(const char *s, const int w, const int h) {
R_RETURN_VAL_IF_FAIL (s && w > 0 && h > 0, NULL);
char *str = strdup (s);
RList *lines = r_str_split_list (str, "\n", 0);
int i, j;
- int rows = r_list_length (lines);
+ const int rows = r_list_length (lines);
RList *out = r_list_newf (free);
int curline = -1;
char *linetext = (char *)r_str_pad (NULL, 0, ' ', w);
for (i = 0; i < h; i++) {
- int zoomedline = (int) (i *((double)rows / h));
+ const int zoomedline = (int) (i *((double)rows / h));
const char *srcline = r_list_get_n (lines, zoomedline);
- int cols = strlen (srcline);
- for (j = 0; j < w; j++) {
- int zoomedcol = (int) (j *((double)cols / w));
- linetext[j] = srcline[zoomedcol];
+ const int cols = srcline ? strlen (srcline) : 0;
+ if (cols > 0) {
+ for (j = 0; j < w; j++) {
+ const int zoomedcol = (int) (j *((double)cols / w));
+ linetext[j] = srcline[zoomedcol];
+ }
}
if (curline != zoomedline) {
r_list_append (out, strdup (linetext));
}
if ((sb->len + l + 1) <= sizeof (sb->buf)) {
- memmove (&sb->buf[l], sb->buf, sb->len);
+ /* Guard to help static analyzers reason about bounds. */
+ R_RETURN_VAL_IF_FAIL (l < sizeof (sb->buf), false);
+ memmove (sb->buf + l, sb->buf, sb->len);
memcpy (sb->buf, s, l);
sb->buf[sb->len + l] = 0;
sb->len += l;
struct grub_hfsplus_extkey_internal *extkey_b = &keyb->extkey;
int diff;
- diff = grub_be_to_cpu32 (extkey_a->fileid) - extkey_b->fileid;
+ diff = (int)grub_be_to_cpu32 (extkey_a->fileid) - (int)extkey_b->fileid;
if (diff)
return diff;
- diff = grub_be_to_cpu32 (extkey_a->start) - extkey_b->start;
+ diff = (int)grub_be_to_cpu32 (extkey_a->start) - (int)extkey_b->start;
return diff;
}
void *closure)
{
struct grub_reiserfs_data *data = 0;
- struct grub_fshelp_node root, *found;
+ struct grub_fshelp_node root = {0}, *found;
struct grub_reiserfs_key root_key;
struct grub_reiserfs_dir_closure c;