Skip to content

Commit f7f5830

Browse files
committed
Do the same for cmd_prc
1 parent a099e01 commit f7f5830

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

libr/core/cmd_anal.inc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9625,7 +9625,7 @@ static void cmd_anal_opcode_bits(RCore *core, const char *arg, int mode) {
96259625
const char *color;
96269626
int idx;
96279627
} AobRow;
9628-
AobRow row[16] = {0};
9628+
AobRow row[16] = {{0}};
96299629
int rows = 0;
96309630
char *p;
96319631
char *s = r_strbuf_drain (sb);

libr/core/cmd_print.inc.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -953,16 +953,19 @@ static void cmd_prc(RCore *core, const ut8 *block, int len) {
953953
RInterval itv = { core->addr, (ut64)len };
954954
regions = r_io_bank_get_regions (core->io, core->io->bank, itv);
955955
}
956+
RStrBuf *sb = r_strbuf_new ("");
956957
if (cols < 1 || cols > 0xfffff) {
957958
cols = 32;
958959
}
959960
for (i = 0; i < len; i += cols) {
960961
if (show_section) {
961962
const char *name = r_core_get_section_name (core, core->addr + i);
962-
r_cons_printf (core->cons, "%20s ", r_str_get (name));
963+
r_strbuf_appendf (sb, "%20s ", r_str_get (name));
963964
}
964965
if (show_offset) {
965-
r_print_addr (core->print, core->addr + i);
966+
char addrbuf[64];
967+
r_print_addr_tostring (core->print, core->addr + i, addrbuf, sizeof (addrbuf));
968+
r_strbuf_append (sb, addrbuf);
966969
}
967970
for (j = i; j < i + cols; j++) {
968971
if (j >= len) {
@@ -976,7 +979,7 @@ static void cmd_prc(RCore *core, const ut8 *block, int len) {
976979
color_val);
977980
color = r_cons_pal_parse (core->cons, str, NULL);
978981
free (str);
979-
ch = (show_cursor && core->print->cur == j)?: '_': ' ';
982+
ch = (show_cursor && core->print->cur == j)? '_': ' ';
980983
} else {
981984
color = strdup ("");
982985
if (show_cursor && core->print->cur == j) {
@@ -1001,17 +1004,19 @@ static void cmd_prc(RCore *core, const ut8 *block, int len) {
10011004
} else {
10021005
ch2 = ch;
10031006
}
1004-
r_cons_printf (core->cons, "%s%c%c", color, ch, ch2);
1007+
r_strbuf_appendf (sb, "%s%c%c", color, ch, ch2);
10051008
} else {
1006-
r_cons_printf (core->cons, "%s%c", color, ch);
1009+
r_strbuf_appendf (sb, "%s%c", color, ch);
10071010
}
10081011
free (color);
10091012
}
10101013
if (show_color) {
1011-
r_cons_printf (core->cons, Color_RESET);
1014+
r_strbuf_append (sb, Color_RESET);
10121015
}
1013-
r_cons_newline (core->cons);
1016+
r_strbuf_append (sb, "\n");
10141017
}
1018+
r_cons_print (core->cons, r_strbuf_get (sb));
1019+
r_strbuf_free (sb);
10151020
RVecRIORegion_free (regions);
10161021
}
10171022

libr/util/print.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ R_API int r_print_addr_tostring(RPrint *p, ut64 addr, char *buf, size_t buf_size
397397
p->iob.p2v (p->iob.io, addr, &addr);
398398
}
399399
const char *pre = Color_GREEN;
400-
const char *fin = Color_RESET; // AITODO: confirm this is used only in `use_color` code paths, because maybe we can just inline the value or simplify this code a little bit more
401400
if (use_color && p) {
402401
RCons *cons = p->consb.cons;
403402
if (cons) {
@@ -411,31 +410,32 @@ R_API int r_print_addr_tostring(RPrint *p, ut64 addr, char *buf, size_t buf_size
411410
}
412411
}
413412
}
413+
// Note: Color_RESET is only needed in use_color paths, so it's inlined directly in those format strings
414414
if (use_segoff) {
415415
const ut32 a = addr & 0xffff;
416416
const ut32 s = (addr - a) >> ((p && p->config) ? p->config->seggrn : 4);
417417
if (dec) {
418418
if (use_color) {
419-
return snprintf (buf, buf_size, "%s%9d:%-5d%s%c", pre, s & 0xffff, a & 0xffff, fin, ch);
419+
return snprintf (buf, buf_size, "%s%9d:%-5d" Color_RESET "%c", pre, s & 0xffff, a & 0xffff, ch);
420420
}
421421
return snprintf (buf, buf_size, "%9d:%-5d%c", s & 0xffff, a & 0xffff, ch);
422422
}
423423
if (use_color) {
424-
return snprintf (buf, buf_size, "%s%04x:%04x%s%c", pre, s & 0xffff, a & 0xffff, fin, ch);
424+
return snprintf (buf, buf_size, "%s%04x:%04x" Color_RESET "%c", pre, s & 0xffff, a & 0xffff, ch);
425425
}
426426
return snprintf (buf, buf_size, "%04x:%04x%c", s & 0xffff, a & 0xffff, ch);
427427
}
428428
if (dec) {
429429
if (use_color) {
430-
return snprintf (buf, buf_size, "%s%10" PFMT64d "%s%c", pre, addr, fin, ch);
430+
return snprintf (buf, buf_size, "%s%10" PFMT64d Color_RESET "%c", pre, addr, ch);
431431
}
432432
return snprintf (buf, buf_size, "%10" PFMT64d "%c", addr, ch);
433433
}
434434
if (use_color) {
435435
if (p && p->wide_offsets) {
436-
return snprintf (buf, buf_size, "%s0x%016" PFMT64x "%s%c", pre, addr, fin, ch);
436+
return snprintf (buf, buf_size, "%s0x%016" PFMT64x Color_RESET "%c", pre, addr, ch);
437437
}
438-
return snprintf (buf, buf_size, "%s0x%08" PFMT64x "%s%c", pre, addr, fin, ch);
438+
return snprintf (buf, buf_size, "%s0x%08" PFMT64x Color_RESET "%c", pre, addr, ch);
439439
}
440440
if (p && p->wide_offsets) {
441441
return snprintf (buf, buf_size, "0x%016" PFMT64x "%c", addr, ch);

0 commit comments

Comments
 (0)