1
0
mirror of https://git.savannah.gnu.org/git/coreutils.git synced 2026-10-24 02:08:57 +03:00

maint: basenc: use the COUNTED_BY attribute for the base58 buffer

* src/basenc.c (struct base58_context): Declare capacity before the buf
member and annotate buf with COUNTED_BY.
(base58_encode_ctx_finalize, base58_decode_ctx_finalize): Reset size and
capacity to zero when freeing buf and setting it to NULL, so the
counted-by invariant holds.
Copyright-paperwork-exempt: Yes

Link: https://github.com/coreutils/coreutils/pull/362
This commit is contained in:
Vidya m
2026-10-05 18:32:03 +05:30
committed by Collin Funk
parent a0cec995fa
commit d5ee8b245c

View File

@@ -288,9 +288,9 @@ struct z85_decode_context
struct base58_context
{
unsigned char *buf;
idx_t size;
idx_t capacity;
unsigned char *buf COUNTED_BY (capacity);
};
struct base2_decode_context
@@ -1316,6 +1316,8 @@ base58_encode_ctx_finalize (struct base_encode_context *ctx,
free (ctx->ctx.base58.buf);
ctx->ctx.base58.buf = NULL;
ctx->ctx.base58.size = 0;
ctx->ctx.base58.capacity = 0;
return true;
}
@@ -1430,6 +1432,8 @@ base58_decode_ctx_finalize (struct base_decode_context *ctx,
free (ctx->ctx.base58.buf);
ctx->ctx.base58.buf = NULL;
ctx->ctx.base58.size = 0;
ctx->ctx.base58.capacity = 0;
return ret;
}