Skip to content

Commit c9f56cc

Browse files
committed
scratch: save a couple bytes of unnecessarily-allocated memory
1 parent a4f523c commit c9f56cc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/scratch_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ static size_t secp256k1_scratch_max_allocation(const secp256k1_callback* error_c
5050
for (i = 0; i < scratch->frame; i++) {
5151
allocated += scratch->frame_size[i];
5252
}
53-
if (scratch->max_size - allocated <= objects * ALIGNMENT) {
53+
if (scratch->max_size - allocated <= objects * (ALIGNMENT - 1)) {
5454
return 0;
5555
}
56-
return scratch->max_size - allocated - objects * ALIGNMENT;
56+
return scratch->max_size - allocated - objects * (ALIGNMENT - 1);
5757
}
5858

5959
static int secp256k1_scratch_allocate_frame(const secp256k1_callback* error_callback, secp256k1_scratch* scratch, size_t n, size_t objects) {
@@ -65,7 +65,7 @@ static int secp256k1_scratch_allocate_frame(const secp256k1_callback* error_call
6565
}
6666

6767
if (n <= secp256k1_scratch_max_allocation(error_callback, scratch, objects)) {
68-
n += objects * ALIGNMENT;
68+
n += objects * (ALIGNMENT - 1);
6969
scratch->current_frame = scratch->data;
7070
scratch->data = (void *) ((char *) scratch->data + n);
7171
scratch->frame_size[scratch->frame] = n;

0 commit comments

Comments
 (0)