Skip to content

Commit

Permalink
fix color crashes in panels
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanpencil authored and radare committed Jun 16, 2018
1 parent 2fee368 commit c3366d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
28 changes: 20 additions & 8 deletions libr/cons/canvas.c
Expand Up @@ -106,12 +106,24 @@ static void sort_attrs(RConsCanvas *c) {
}

static void stamp_attr(RConsCanvas *c, int loc, int length) {
if (!c->color) {
return;
}
int i;
const char **s;
s = attr_at (c, loc);

if (s) {
//If theres already an attr there, just replace it.
if (strlen (s) > 2 && *(*s + 2) == '0') {
if (strlen (c->attr) == 5 && *(c->attr + 2) != '0') {
char tmp[9];
memcpy (tmp, c->attr, 2);
strcpy (tmp + 2, "0;");
memcpy (tmp + 4, c->attr + 2, 3);
tmp[8] = 0;
c->attr = r_str_const (tmp);
}
}
*s = c->attr;
} else {
c->attrs[c->attrslen].loc = loc;
Expand All @@ -120,10 +132,10 @@ static void stamp_attr(RConsCanvas *c, int loc, int length) {
sort_attrs (c);
}

for (i = 0; i < length; i++) {
for (i = 1; i < length; i++) {
s = attr_at (c, loc + i);
if (s) {
*s = c->attr;
*s = '\0';
}
}
}
Expand Down Expand Up @@ -329,11 +341,6 @@ R_API void r_cons_canvas_write(RConsCanvas *c, const char *s) {
}
left = c->blen[c->y] - c->x;
slen = R_MIN (left, piece_len);
attr_len = slen <= 0 && s_part != s? 1: slen;

if (attr_len > 0 && attr_x < c->blen[c->y]) {
stamp_attr (c, c->y*c->w + attr_x, attr_len);
}

int real_len = r_str_nlen (s_part, slen);
int utf8_len = utf8len_fixed (s_part, slen);
Expand All @@ -346,6 +353,11 @@ R_API void r_cons_canvas_write(RConsCanvas *c, const char *s) {
memcpy (c->b[c->y] + c->x, s_part, slen);
}

attr_len = slen <= 0 && s_part != s? 1: utf8_len;
if (attr_len > 0 && attr_x < c->blen[c->y]) {
stamp_attr (c, c->y*c->w + attr_x, attr_len);
}

s = s_part;
if (ch == '\n') {
c->y++;
Expand Down
4 changes: 3 additions & 1 deletion libr/core/panels.c
Expand Up @@ -634,7 +634,9 @@ R_API void r_core_panels_refresh(RCore *core) {
}
if (panels->isResizing) {
panels->isResizing = false;
r_cons_canvas_resize (can, w, h);
if (!r_cons_canvas_resize (can, w, h)) {
return;
}
setRefreshAll (panels);
}
#if 0
Expand Down

0 comments on commit c3366d9

Please sign in to comment.