From: Vidya m <[email protected]>

* 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
---
 src/basenc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/basenc.c b/src/basenc.c
index 8e8f61c3a..a9c9f2f30 100644
--- a/src/basenc.c
+++ b/src/basenc.c
@@ -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;
 }
-- 
2.55.0


Reply via email to