* Fix segfault in OpenBSD when loading empty files

This commit is contained in:
pancake 2011-07-03 21:00:36 +02:00
parent e40e54984e
commit b8d4ff5552

View File

@ -34,7 +34,9 @@ R_API int r_buf_set_bits(RBuffer *b, int bitoff, int bitsize, ut64 value) {
R_API int r_buf_set_bytes(RBuffer *b, const ut8 *buf, int length) {
if (b->buf)
free (b->buf);
if (!(b->buf = malloc (length)))
if (length<0)
return R_FALSE;
if (!(b->buf = malloc (length+1)))
return R_FALSE;
memcpy (b->buf, buf, length);
b->length = length;