Warn when invalid use of r_buf_buffer (#13240)

This commit is contained in:
radare 2019-03-03 21:26:03 +01:00 committed by GitHub
parent dae64a0cba
commit 7fdf247e34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -95,12 +95,11 @@ static ut8 gprobe_checksum_i2c (const ut8 *p, unsigned int size, ut8 initial) {
static void gprobe_frame_i2c (RBuffer *frame) {
ut8 size = r_buf_size (frame) + 1;
ut8 header[] = {0x51, 0x80 + size + 3, 0xc2, 0x00, 0x00};
ut8 checksum;
r_buf_prepend_bytes (frame, &size, 1);
r_buf_prepend_bytes (frame, header, sizeof (header));
checksum = gprobe_checksum_i2c (r_buf_buffer (frame), r_buf_size (frame), GPROBE_I2C_ADDR);
ut8 checksum = gprobe_checksum_i2c (r_buf_buffer (frame), r_buf_size (frame), GPROBE_I2C_ADDR);
r_buf_append_bytes (frame, &checksum, 1);
}

View File

@ -402,7 +402,10 @@ R_API RBuffer *r_buf_new() {
}
R_API const ut8 *r_buf_buffer (RBuffer *b) {
return (b && !b->sparse)? b->buf: NULL;
if (b && !b->sparse && b->fd == -1 && !b->mmap) {
return b->buf;
}
r_return_val_if_fail (false, NULL);
}
R_API ut64 r_buf_size (RBuffer *b) {