Fix return value for RBuffer.sparse when reading beyond the end

This commit is contained in:
pancake 2018-04-24 13:15:25 +02:00
parent ab6aa52c23
commit cf7dcf07dc
3 changed files with 7 additions and 5 deletions

View File

@ -293,6 +293,10 @@ R_API bool r_anal_set_bits(RAnal *anal, int bits) {
R_API void r_anal_set_cpu(RAnal *anal, const char *cpu) {
free (anal->cpu);
anal->cpu = cpu ? strdup (cpu) : NULL;
int v = r_anal_archinfo (anal, R_ANAL_ARCHINFO_ALIGN);
if (v != -1) {
anal->pcalign = v;
}
}
R_API int r_anal_set_big_endian(RAnal *anal, int bigend) {

View File

@ -178,10 +178,7 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
}
Rihex *rih = fd->data;
memset (buf, io->Oxff, count);
if (r_buf_read_at (rih->rbuf, io->off, buf, count) != count) {
return -1; //should never happen with a sparsebuf..
}
return count;
return r_buf_read_at (rih->rbuf, io->off, buf, count);
}
static int __close(RIODesc *fd) {
@ -378,7 +375,7 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
if (!str) {
return NULL;
}
mal= R_NEW0 (Rihex);
mal = R_NEW0 (Rihex);
if (!mal) {
free (str);
return NULL;

View File

@ -498,6 +498,7 @@ static int r_buf_cpy(RBuffer *b, ut64 addr, ut8 *dst, const ut8 *src, int len, i
// read from sparse and write into dst
memset (dst, b->Oxff, len);
(void)sparse_read (b->sparse, addr, dst, len);
len = R_MIN (len , r_buf_size (b) - addr);
}
return len;
}