summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2017-05-07 05:03:41 +0000
committerjsing <>2017-05-07 05:03:41 +0000
commitb238007c9db07d24cda00ffe301ec662ec5e1cc3 (patch)
tree4f5e65dc841d29bbac9f1fde247588e1d1bed3c3
parent2439ee31e965a96d3685f362e5a32d365a9e5eaa (diff)
downloadopenbsd-b238007c9db07d24cda00ffe301ec662ec5e1cc3.tar.gz
openbsd-b238007c9db07d24cda00ffe301ec662ec5e1cc3.tar.bz2
openbsd-b238007c9db07d24cda00ffe301ec662ec5e1cc3.zip
Instead of starting a 'zero-sized' CBB at the size of the first addition
to the CBB, then doubling, start with an initial size of 64 bytes. Almost all uses will exceed this size and we avoid multiple small recallocarray() calls during the initial usage. ok beck@
-rw-r--r--src/lib/libssl/bs_cbb.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/lib/libssl/bs_cbb.c b/src/lib/libssl/bs_cbb.c
index 154a7964e6..dd1dc73d09 100644
--- a/src/lib/libssl/bs_cbb.c
+++ b/src/lib/libssl/bs_cbb.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bs_cbb.c,v 1.15 2017/04/14 15:20:55 jsing Exp $ */ 1/* $OpenBSD: bs_cbb.c,v 1.16 2017/05/07 05:03:41 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -22,6 +22,8 @@
22 22
23#include "bytestring.h" 23#include "bytestring.h"
24 24
25#define CBB_INITIAL_SIZE 64
26
25static int 27static int
26cbb_init(CBB *cbb, uint8_t *buf, size_t cap) 28cbb_init(CBB *cbb, uint8_t *buf, size_t cap)
27{ 29{
@@ -49,10 +51,11 @@ CBB_init(CBB *cbb, size_t initial_capacity)
49 51
50 memset(cbb, 0, sizeof(*cbb)); 52 memset(cbb, 0, sizeof(*cbb));
51 53
52 if (initial_capacity > 0) { 54 if (initial_capacity == 0)
53 if ((buf = malloc(initial_capacity)) == NULL) 55 initial_capacity = CBB_INITIAL_SIZE;
54 return 0; 56
55 } 57 if ((buf = malloc(initial_capacity)) == NULL)
58 return 0;
56 59
57 if (!cbb_init(cbb, buf, initial_capacity)) { 60 if (!cbb_init(cbb, buf, initial_capacity)) {
58 free(buf); 61 free(buf);