diff --git a/libr/util/buf.c b/libr/util/buf.c index 049302499b..e7084e8855 100644 --- a/libr/util/buf.c +++ b/libr/util/buf.c @@ -641,6 +641,12 @@ R_API st64 r_buf_fwrite_at(RBuffer *b, ut64 addr, const ut8 *buf, const char *fm return r; } +#if R2_600 +R_API ut64 r_buf_at(RBuffer *b) { + return r_buf_seek (b, 0, R_BUF_CUR); +} +#endif + R_API st64 r_buf_read_at(RBuffer *b, ut64 addr, ut8 *buf, ut64 len) { R_RETURN_VAL_IF_FAIL (b && buf, -1); st64 o_addr = r_buf_seek (b, 0, R_BUF_CUR); diff --git a/libr/util/buf_bytes.c b/libr/util/buf_bytes.c index fbe42c8d5c..a1683081d5 100644 --- a/libr/util/buf_bytes.c +++ b/libr/util/buf_bytes.c @@ -90,7 +90,8 @@ static st64 buf_bytes_read(RBuffer *b, ut8 *buf, ut64 len) { return 0; } ut64 real_len = priv->length < priv->offset? 0: R_MIN (priv->length - priv->offset, len); - memmove (buf, priv->buf + priv->offset, real_len); + // memmove (buf, priv->buf + priv->offset, real_len); + memcpy (buf, priv->buf + priv->offset, real_len); priv->offset += real_len; return real_len; } @@ -115,7 +116,7 @@ static ut64 buf_bytes_get_size(RBuffer *b) { static st64 buf_bytes_seek(RBuffer *b, st64 addr, int whence) { struct buf_bytes_priv *priv = get_priv_bytes (b); - if (addr < 0) { + if (R_UNLIKELY (addr < 0)) { if (addr > -UT48_MAX) { if (-addr > (st64)priv->offset) { return -1; @@ -124,17 +125,19 @@ static st64 buf_bytes_seek(RBuffer *b, st64 addr, int whence) { return -1; } } + ut64 po = priv->offset; if (R_LIKELY (whence == R_BUF_SET)) { // 50% - priv->offset = addr; + po = addr; } else if (whence == R_BUF_CUR) { // 20% - priv->offset += addr; + po += addr; } else { // 5% - priv->offset = priv->length + addr; + po = priv->length + addr; } - return priv->offset; + priv->offset = po; + return po; } static ut8 *buf_bytes_get_whole_buf(RBuffer *b, ut64 *sz) {