Skip to content

Commit 59d0685

Browse files
cyanpencilradare
authored andcommitted
Fix radareorg#11427 - Crop output in vertical split in visual mode to avoid overflow
1 parent a12549c commit 59d0685

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

libr/core/visual.c

+25-10
Original file line numberDiff line numberDiff line change
@@ -3287,7 +3287,7 @@ static void scrollbar(RCore *core) {
32873287

32883288
static void visual_refresh(RCore *core) {
32893289
static ut64 oseek = UT64_MAX;
3290-
const char *vi, *vcmd;
3290+
const char *vi, *vcmd, *cmd_str;
32913291
if (!core) {
32923292
return;
32933293
}
@@ -3304,24 +3304,29 @@ static void visual_refresh(RCore *core) {
33043304
r_cons_flush ();
33053305
r_cons_print_clear ();
33063306

3307-
vi = r_config_get (core->config, "cmd.cprompt");
3307+
int hex_cols = r_config_get_i (core->config, "hex.cols");
3308+
int split_w = 12 + 4 + hex_cols + (hex_cols * 3);
33083309
bool ce = core->print->cur_enabled;
3309-
if (vi && *vi) {
3310+
3311+
vi = r_config_get (core->config, "cmd.cprompt");
3312+
bool vsplit = (vi && *vi);
3313+
3314+
if (vsplit) {
33103315
// XXX: slow
33113316
core->cons->blankline = false;
33123317
r_cons_clear00 ();
33133318
{
3314-
int hc = r_config_get_i (core->config, "hex.cols");
3315-
int nw = 12 + 4 + hc + (hc * 3);
3316-
if (nw > w) {
3319+
int hex_cols = r_config_get_i (core->config, "hex.cols");
3320+
int split_w = 12 + 4 + hex_cols + (hex_cols * 3);
3321+
if (split_w > w) {
33173322
// do not show column contents
33183323
} else {
33193324
r_cons_printf ("[cmd.cprompt=%s]\n", vi);
33203325
if (oseek != UT64_MAX) {
33213326
r_core_seek (core, oseek, 1);
33223327
}
33233328
r_core_cmd0 (core, vi);
3324-
r_cons_column (nw);
3329+
r_cons_column (split_w);
33253330
if (!strncmp (vi, "p=", 2) && core->print->cur_enabled) {
33263331
oseek = core->offset;
33273332
core->print->cur_enabled = false;
@@ -3349,7 +3354,7 @@ static void visual_refresh(RCore *core) {
33493354
// disable screen bounds when it's a user-defined command
33503355
// because it can cause some issues
33513356
core->print->screen_bounds = 0;
3352-
r_core_cmd (core, vcmd, 0);
3357+
cmd_str = vcmd;
33533358
} else {
33543359
if (splitView) {
33553360
static char debugstr[512];
@@ -3370,10 +3375,20 @@ static void visual_refresh(RCore *core) {
33703375
pxw, size, splitPtr,
33713376
pxw, size, core->offset);
33723377
core->print->screen_bounds = 1LL;
3373-
r_core_cmd0 (core, debugstr);
3378+
cmd_str = debugstr;
33743379
} else {
33753380
core->print->screen_bounds = 1LL;
3376-
r_core_cmd0 (core, zoom? "pz": printfmt[PIDX]);
3381+
cmd_str = (zoom ? "pz" : printfmt[PIDX]);
3382+
}
3383+
}
3384+
if (cmd_str && *cmd_str) {
3385+
if (vsplit) {
3386+
char *cmd_result;
3387+
cmd_result = r_core_cmd_str (core, cmd_str);
3388+
cmd_result = r_str_ansi_crop (cmd_result, 0, 0, split_w, -1);
3389+
r_cons_strcat (cmd_result);
3390+
} else {
3391+
r_core_cmd0 (core, cmd_str);
33773392
}
33783393
}
33793394
core->print->cur_enabled = ce;

0 commit comments

Comments
 (0)