Skip to content

Commit 8cbf70d

Browse files
committed
batch_create: move max_terms limit before ARG_CHECKS
1 parent 4a8d9ac commit 8cbf70d

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/modules/batch/main_impl.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ secp256k1_batch* secp256k1_batch_create(const secp256k1_context* ctx, size_t max
109109
secp256k1_batch* batch = (secp256k1_batch*)checked_malloc(&ctx->error_callback, batch_size);
110110
size_t batch_scratch_size;
111111
unsigned char zeros[16] = {0};
112+
/* max limit on scratch space size in a batch */
113+
if (max_terms > STRAUSS_MAX_TERMS_PER_BATCH) {
114+
max_terms = STRAUSS_MAX_TERMS_PER_BATCH;
115+
}
112116

113117
VERIFY_CHECK(ctx != NULL);
114118
ARG_CHECK(max_terms != 0);
@@ -120,12 +124,7 @@ secp256k1_batch* secp256k1_batch_create(const secp256k1_context* ctx, size_t max
120124
* and 64-bit platforms. */
121125
ARG_CHECK(max_terms < ((uint32_t)1 << 31));
122126

123-
/* scratch space size in a batch */
124-
if (max_terms > STRAUSS_MAX_TERMS_PER_BATCH) {
125-
max_terms = STRAUSS_MAX_TERMS_PER_BATCH;
126-
}
127127
batch_scratch_size = secp256k1_batch_scratch_size(2*max_terms);
128-
129128
if (batch != NULL) {
130129
/* create scratch space inside batch object, if that fails return NULL*/
131130
batch->data = secp256k1_scratch_create(&ctx->error_callback, batch_scratch_size);

0 commit comments

Comments
 (0)