From b6850182b99c6488c72a755b166d963ee8f1c247 Mon Sep 17 00:00:00 2001 From: pancake Date: Thu, 3 Jul 2014 11:54:58 +0200 Subject: [PATCH] Fix RReg.arena.size issue caused by missing parenthesis in BITS2BYTES --- libr/core/cmd_anal.c | 8 ++++++++ libr/include/r_types.h | 2 +- libr/reg/arena.c | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libr/core/cmd_anal.c b/libr/core/cmd_anal.c index 84f2c23b97..901902d879 100644 --- a/libr/core/cmd_anal.c +++ b/libr/core/cmd_anal.c @@ -727,6 +727,14 @@ void cmd_anal_reg(RCore *core, const char *str) { r_cons_printf ("0x%08"PFMT64x"\n", off); } else ar_show_help (core); break; + case 'S': + { + int sz; + ut8 *buf = r_reg_get_bytes ( + core->anal->reg, R_REG_TYPE_GPR, &sz); + r_cons_printf ("%d\n", sz); + } + break; case 'b': { // WORK IN PROGRESS // DEBUG COMMAND int len; diff --git a/libr/include/r_types.h b/libr/include/r_types.h index 13257a1712..d3e5f608a0 100644 --- a/libr/include/r_types.h +++ b/libr/include/r_types.h @@ -168,7 +168,7 @@ typedef void (*PrintfCallback)(const char *str, ...); #endif #endif -#define BITS2BYTES(x) ((x/8)+((x%8)?1:0)) +#define BITS2BYTES(x) (((x)/8)+(((x)%8)?1:0)) #define ZERO_FILL(x) memset (&x, 0, sizeof (x)) #define R_NEWS0(x,y) (x*)memset (malloc(sizeof(x)*y), 0, sizeof(x)*y); #define R_NEWS(x,y) (x*)malloc(sizeof(x)*y) diff --git a/libr/reg/arena.c b/libr/reg/arena.c index 616830c56b..f4d47857f7 100644 --- a/libr/reg/arena.c +++ b/libr/reg/arena.c @@ -7,6 +7,8 @@ R_API ut8* r_reg_get_bytes(RReg *reg, int type, int *size) { RRegArena *arena; int i, sz, osize; ut8 *buf; + if (size) + *size = 0; if (type == -1) { /* serialize ALL register types in a single buffer */ // owned buffer is returned @@ -113,6 +115,8 @@ R_API int r_reg_fit_arena(RReg *reg) { arena = reg->regset[i].arena; newsize = 0; r_list_foreach (reg->regset[i].regs, iter, r) { + int regsize_in_bytes = r->size / 8; + // XXX: bits2bytes doesnt seems to work fine size = BITS2BYTES (r->offset+r->size); newsize = R_MAX (size, newsize); }