summaryrefslogtreecommitdiff
path: root/lib/libssl
diff options
context:
space:
mode:
authorDoug Hogan <doug@cvs.openbsd.org>2015-06-13 09:11:58 +0000
committerDoug Hogan <doug@cvs.openbsd.org>2015-06-13 09:11:58 +0000
commit907b1c501a5fc3205f08f712676cc4d1ac114efd (patch)
tree142daeff5e49e411a6a5efd8a44b640bf79351b1 /lib/libssl
parent6f7122f73a3c7b8eaa25a3404de73af4cd336dbd (diff)
When initial capacity is 0, always use NULL buffer.
malloc(0) is implementation defined and there's no reason to introduce that ambiguity here. Added a few cosmetic changes in sizeof and free. ok miod@ jsing@
Diffstat (limited to 'lib/libssl')
-rw-r--r--lib/libssl/src/ssl/bs_cbb.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/libssl/src/ssl/bs_cbb.c b/lib/libssl/src/ssl/bs_cbb.c
index b766e850d33..29312e104b4 100644
--- a/lib/libssl/src/ssl/bs_cbb.c
+++ b/lib/libssl/src/ssl/bs_cbb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bs_cbb.c,v 1.8 2015/04/29 02:02:46 doug Exp $ */
+/* $OpenBSD: bs_cbb.c,v 1.9 2015/06/13 09:11:57 doug Exp $ */
/*
* Copyright (c) 2014, Google Inc.
*
@@ -36,7 +36,7 @@ cbb_init(CBB *cbb, uint8_t *buf, size_t cap)
base->cap = cap;
base->can_resize = 1;
- memset(cbb, 0, sizeof(CBB));
+ memset(cbb, 0, sizeof(*cbb));
cbb->base = base;
cbb->is_top_level = 1;
return 1;
@@ -45,11 +45,12 @@ cbb_init(CBB *cbb, uint8_t *buf, size_t cap)
int
CBB_init(CBB *cbb, size_t initial_capacity)
{
- uint8_t *buf;
+ uint8_t *buf = NULL;
- buf = malloc(initial_capacity);
- if (initial_capacity > 0 && buf == NULL)
- return 0;
+ if (initial_capacity > 0) {
+ if ((buf = malloc(initial_capacity)) == NULL)
+ return 0;
+ }
if (!cbb_init(cbb, buf, initial_capacity)) {
free(buf);
@@ -72,7 +73,7 @@ void
CBB_cleanup(CBB *cbb)
{
if (cbb->base) {
- if (cbb->base->buf && cbb->base->can_resize)
+ if (cbb->base->can_resize)
free(cbb->base->buf);
free(cbb->base);