From b8d4ff55527fd20b24f3159deb68e61e5ba9e43c Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 3 Jul 2011 21:00:36 +0200 Subject: [PATCH] * Fix segfault in OpenBSD when loading empty files --- libr/util/buf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libr/util/buf.c b/libr/util/buf.c index 9e26f1bbe0..97a7ed079f 100644 --- a/libr/util/buf.c +++ b/libr/util/buf.c @@ -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;