Skip to content

Commit 28ee957

Browse files
committed
fix neg reads
1 parent 6e55bf8 commit 28ee957

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

libr/core/casm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) {
508508
free (buf);
509509
return NULL;
510510
}
511-
if (!r_io_read_at (core->io, addr - (len / addrbytes), buf, len)) {
511+
if (!r_io_read_at (core->io, addr - len / addrbytes, buf, len)) {
512512
r_list_free (hits);
513513
free (buf);
514514
return NULL;

libr/core/cmd_print.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5710,22 +5710,21 @@ static int cmd_print(void *data, const char *input) {
57105710
r_print_init_rowoffsets (core->print);
57115711
tmpseek = core->offset;
57125712
l = len = core->blocksize;
5713+
bool must_read = false;
57135714
if (input[0] && input[1]) {
57145715
int idx = (input[0] == 'h')? 2: 1;
57155716
const char *p = strchr (input + idx, ' ');
57165717
if (!p) {
57175718
p = strchr (input, '-');
5718-
if (p) {
5719-
p--;
5720-
}
57215719
}
57225720
if (p) {
5723-
l = (int) r_num_math (core->num, p + 1);
5721+
l = (int) r_num_math (core->num, p);
57245722
/* except disasm and memoryfmt (pd, pm) and overlay (po) */
57255723
if (input[0] != 'd' && input[0] != 't' && input[0] != 'D' && input[0] != 'm' &&
57265724
input[0] != 'a' && input[0] != 'f' && input[0] != 'i' &&
57275725
input[0] != 'I' && input[0] != 'o') {
57285726
if (l < 0) {
5727+
must_read = true;
57295728
off = core->offset + l;
57305729
len = l = -l;
57315730
} else {
@@ -5737,34 +5736,37 @@ static int cmd_print(void *data, const char *input) {
57375736
}
57385737
}
57395738
} else {
5740-
len = l;
57415739
if (l < 0) {
5740+
must_read = true;
57425741
off = core->offset + l;
5742+
len = -len;
5743+
} else {
5744+
len = l;
57435745
}
57445746
}
57455747
}
57465748
}
57475749
int olen = len;
57485750
at = off;
5749-
if (len < 0) {
5750-
len = -len;
5751-
}
57525751
const int padding = core->blocksize + 256;
57535752
block = malloc (len + padding);
57545753
// if (!block) die
57555754
if (block) {
5756-
if (len > core->blocksize) {
5755+
if (!must_read && len > core->blocksize) {
57575756
memset (block, core->io->Oxff, len + padding);
57585757
r_io_read_at (core->io, off, block, len);
57595758
} else {
57605759
block = calloc (1, len + padding);
57615760
if (block) {
5761+
ut64 oo = core->offset;
5762+
core->offset = at;
57625763
r_core_block_read (core);
57635764
memset (block, core->io->Oxff, len + padding);
57645765
r_io_read_at (core->io, off, block, len);
57655766
if (off == core->offset) {
57665767
memcpy (block, core->block, R_MIN (core->blocksize, len));
57675768
}
5769+
core->offset = oo;
57685770
}
57695771
}
57705772
} else {

0 commit comments

Comments
 (0)