From: Pavel Filipenský Date: Wed, 3 Dec 2025 16:47:54 +0000 (+0100) Subject: lib/util: Refactor data_blob.{h,c} X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e53eba1e6963eb61e98ba208347b8edf4ce7eba3;p=thirdparty%2Fsamba.git lib/util: Refactor data_blob.{h,c} Makes data_blob_talloc_zero() use __location__ of the real caller Signed-off-by: Pavel Filipenský Reviewed-by: Andreas Schneider --- diff --git a/lib/util/data_blob.c b/lib/util/data_blob.c index 9372612d8a3..12f4173c5e6 100644 --- a/lib/util/data_blob.c +++ b/lib/util/data_blob.c @@ -31,15 +31,6 @@ const DATA_BLOB data_blob_null = { NULL, 0 }; * @brief Manipulation of arbitrary data blobs **/ -/** - construct a data blob, must be freed with data_blob_free() - you can pass NULL for p and get a blank data blob -**/ -_PUBLIC_ DATA_BLOB data_blob_named(const void *p, size_t length, const char *name) -{ - return data_blob_talloc_named(NULL, p, length, name); -} - /** construct a data blob, using supplied TALLOC_CTX **/ @@ -66,18 +57,6 @@ _PUBLIC_ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, si return ret; } -/** - construct a zero data blob, using supplied TALLOC_CTX. - use this sparingly as it initialises data - better to initialise - yourself if you want specific data in the blob -**/ -_PUBLIC_ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length) -{ - DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, length); - data_blob_clear(&blob); - return blob; -} - /** free a data blob **/ diff --git a/lib/util/data_blob.h b/lib/util/data_blob.h index 6577630e592..9309230aca1 100644 --- a/lib/util/data_blob.h +++ b/lib/util/data_blob.h @@ -52,7 +52,8 @@ typedef struct datablob { construct a data blob, must be freed with data_blob_free() you can pass NULL for p and get a blank data blob **/ -_PUBLIC_ DATA_BLOB data_blob_named(const void *p, size_t length, const char *name); +#define data_blob_named(ptr, size, name) \ + data_blob_talloc_named(NULL, (ptr), (size), name) /** construct a data blob, using supplied TALLOC_CTX @@ -64,7 +65,8 @@ _PUBLIC_ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, si use this sparingly as it initialises data - better to initialise yourself if you want specific data in the blob **/ -_PUBLIC_ DATA_BLOB data_blob_talloc_zero(TALLOC_CTX *mem_ctx, size_t length); +#define data_blob_talloc_zero(ctx, size) \ + _data_blob_talloc_zero((ctx), (size), "DATA_BLOB: " __location__) /** free a data blob @@ -81,6 +83,17 @@ free a data blob and clear its contents **/ _PUBLIC_ void data_blob_clear_free(DATA_BLOB *d); +static inline DATA_BLOB _data_blob_talloc_zero(TALLOC_CTX *ctx, + size_t size, + const char *name) +{ + DATA_BLOB b = data_blob_talloc_named(ctx, 0, size, name); + if (b.data != NULL) { + data_blob_clear(&b); + } + return b; +} + /** check if two data blobs are equal **/