summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNiall O'Higgins <niallo@cvs.openbsd.org>2006-01-15 19:25:33 +0000
committerNiall O'Higgins <niallo@cvs.openbsd.org>2006-01-15 19:25:33 +0000
commit161afeac9f0f8ba065ff7fc1a6cb35735ee77f87 (patch)
treeab62281234d6a6b816e265103f9c349314cd99c1 /usr.bin
parent8370cbf416661b0a2b359bfaccf7e924d78b3a3c (diff)
- don't try to malloc 0 bytes of memory if an empty buffer is requested; delay
the malloc till cvs_buf_grow(). fixes PR4972. ok joris@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/cvs/buf.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/usr.bin/cvs/buf.c b/usr.bin/cvs/buf.c
index 8eeb11a4848..488a1cbebe1 100644
--- a/usr.bin/cvs/buf.c
+++ b/usr.bin/cvs/buf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.c,v 1.29 2006/01/10 14:57:53 niallo Exp $ */
+/* $OpenBSD: buf.c,v 1.30 2006/01/15 19:25:32 niallo Exp $ */
/*
* Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -62,8 +62,11 @@ cvs_buf_alloc(size_t len, u_int flags)
BUF *b;
b = (BUF *)xmalloc(sizeof(*b));
- b->cb_buf = xmalloc(len);
- memset(b->cb_buf, 0, len);
+ /* Postpone creation of zero-sized buffers */
+ if (len > 0) {
+ b->cb_buf = xmalloc(len);
+ memset(b->cb_buf, 0, len);
+ }
b->cb_flags = flags;
b->cb_size = len;
@@ -424,7 +427,11 @@ cvs_buf_grow(BUF *b, size_t len)
size_t diff;
diff = b->cb_cur - b->cb_buf;
- tmp = xrealloc(b->cb_buf, b->cb_size + len);
+ /* Buffer not allocated yet */
+ if (b->cb_size == 0)
+ tmp = xmalloc(len);
+ else
+ tmp = xrealloc(b->cb_buf, b->cb_size + len);
b->cb_buf = (u_char *)tmp;
b->cb_size += len;