From a7a164f2c604883dea8968bd4c71b9880cc34552 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Thu, 14 Mar 2019 14:41:03 +0000 Subject: [PATCH] scratch: rename `max_size` to `size`, document that extra will actually be allocated --- include/secp256k1.h | 5 +++-- src/scratch_impl.h | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/secp256k1.h b/include/secp256k1.h index 235e64290de25..278ea6178fb7e 100644 --- a/include/secp256k1.h +++ b/include/secp256k1.h @@ -285,11 +285,12 @@ SECP256K1_API void secp256k1_context_set_error_callback( * * Returns: a newly created scratch space. * Args: ctx: an existing context object (cannot be NULL) - * In: max_size: maximum amount of memory to allocate + * In: size: amount of memory to be available as scratch space. Some extra + * (<100 bytes) will be allocated for extra accounting. */ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space* secp256k1_scratch_space_create( const secp256k1_context* ctx, - size_t max_size + size_t size ) SECP256K1_ARG_NONNULL(1); /** Destroy a secp256k1 scratch space. diff --git a/src/scratch_impl.h b/src/scratch_impl.h index cbe119f2fc442..3a3991035a09f 100644 --- a/src/scratch_impl.h +++ b/src/scratch_impl.h @@ -10,15 +10,15 @@ #include "util.h" #include "scratch.h" -static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t max_size) { +static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t size) { const size_t base_alloc = ((sizeof(secp256k1_scratch) + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT; - void *alloc = checked_malloc(error_callback, base_alloc + max_size); + void *alloc = checked_malloc(error_callback, base_alloc + size); secp256k1_scratch* ret = (secp256k1_scratch *)alloc; if (ret != NULL) { memset(ret, 0, sizeof(*ret)); memcpy(ret->magic, "scratch", 8); ret->data = (void *) ((char *) alloc + base_alloc); - ret->max_size = max_size; + ret->max_size = size; } return ret; }