Skip to content

Conditionally include stdio.h and stdlib.h #1148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/secp256k1.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,34 +116,42 @@ secp256k1_context* secp256k1_context_preallocated_create(void* prealloc, unsigne
}

secp256k1_context* secp256k1_context_create(unsigned int flags) {
secp256k1_context* ctx = NULL;

#ifndef PREALLOC_INTERFACE_ONLY
size_t const prealloc_size = secp256k1_context_preallocated_size(flags);
secp256k1_context* ctx = (secp256k1_context*)checked_malloc(&default_error_callback, prealloc_size);
ctx = (secp256k1_context*)checked_malloc(&default_error_callback, prealloc_size);
if (EXPECT(secp256k1_context_preallocated_create(ctx, flags) == NULL, 0)) {
free(ctx);
return NULL;
}

#endif
return ctx;
}

secp256k1_context* secp256k1_context_preallocated_clone(const secp256k1_context* ctx, void* prealloc) {
secp256k1_context* ret;
secp256k1_context* ret = NULL;

#ifndef PREALLOC_INTERFACE_ONLY
VERIFY_CHECK(ctx != NULL);
ARG_CHECK(prealloc != NULL);

ret = (secp256k1_context*)prealloc;
*ret = *ctx;
#endif
return ret;
}

secp256k1_context* secp256k1_context_clone(const secp256k1_context* ctx) {
secp256k1_context* ret;
secp256k1_context* ret = NULL;
size_t prealloc_size;

#ifndef PREALLOC_INTERFACE_ONLY
VERIFY_CHECK(ctx != NULL);
prealloc_size = secp256k1_context_preallocated_clone_size(ctx);
ret = (secp256k1_context*)checked_malloc(&ctx->error_callback, prealloc_size);
ret = secp256k1_context_preallocated_clone(ctx, ret);
#endif
return ret;
}

Expand Down
10 changes: 8 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
#include "libsecp256k1-config.h"
#endif

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <limits.h>

#if defined(VERIFY) || !defined(USE_EXTERNAL_DEFAULT_CALLBACKS)
#include <stdio.h>
#endif

#ifndef PREALLOC_INTERFACE_ONLY
#include <stdlib.h>
#endif

#define STR_(x) #x
#define STR(x) STR_(x)
#define DEBUG_CONFIG_MSG(x) "DEBUG_CONFIG: " x
Expand Down