Skip to content

Commit

Permalink
Fix handling of many seek history items and other edge cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
karliss authored and radare committed Dec 1, 2019
1 parent 164e2cc commit a50b3a6
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions libr/io/undo.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ R_API void r_io_sundo_push(RIO *io, ut64 off, int cursor) {
if (!io->undo.s_enable) {
return;
}
// the first insert
if (io->undo.idx > 0) {
undo = &io->undo.seek[io->undo.idx - 1];
// don't push duplicate seek
if (io->undo.undos > 0) {
undo = &io->undo.seek[(io->undo.idx - 1 + R_IO_UNDOS) % R_IO_UNDOS];
if (undo->off == off && undo->cursor == cursor) {
return;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ R_API RList *r_io_sundo_list(RIO *io, int mode) {

idx = io->undo.idx;
start = (idx - undos + R_IO_UNDOS) % R_IO_UNDOS;
end = (idx + redos + 1) % R_IO_UNDOS;
end = (idx + redos + 1 - 1) % R_IO_UNDOS; // +1 slot for current position, -1 due to inclusive end

j = 0;
switch (mode) {
Expand All @@ -139,24 +139,17 @@ R_API RList *r_io_sundo_list(RIO *io, int mode) {
break;
}
const char *comma = "";
for (i = start; i < end || j == 0; i = (i + 1) % R_IO_UNDOS) {
for (i = start;/* condition at the end of loop */; i = (i + 1) % R_IO_UNDOS) {
int idx = (j < undos)? undos - j - 1: j - undos - 1;
RIOUndos *undo = &io->undo.seek[i];
ut64 addr = undo->off;
ut64 notLast = (j + 1 < undos) && (i != end - 1);
bool notLast = (j + 1 < undos);
switch (mode) {
case '=':
if (j < undos) {
io->cb_printf ("0x%"PFMT64x"%s", addr, notLast? " > ": "");
}
break;
case 'j':
// XXX not used, because the code is in cmd_seek().. we may probably kill that
if (j < undos) {
io->cb_printf ("%"PFMT64d"%s", addr, notLast? ",": "");
comma = ",";
}
break;
case '*':
if (j < undos) {
io->cb_printf ("f undo_%d @ 0x%"PFMT64x"\n", idx, addr);
Expand All @@ -170,21 +163,25 @@ R_API RList *r_io_sundo_list(RIO *io, int mode) {
if (list) {
RIOUndos *u = R_NEW0 (RIOUndos);
if (u) {
memcpy (u, undo, sizeof (RIOUndos));
if (!(j == undos && redos == 0)) {
// Current position gets pushed before seek, so there
// is no valid offset when we are at the end of list.
memcpy (u, undo, sizeof (RIOUndos));
}
r_list_append (list, u);
}
}
break;
}
j++;
if (i == end) {
break;
}
}
switch (mode) {
case '=':
io->cb_printf ("\n");
break;
case 'j':
io->cb_printf ("%s%"PFMT64d"]\n", comma, io->off);
break;
}
return list;
}
Expand Down

0 comments on commit a50b3a6

Please sign in to comment.