]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/util: Refactor data_blob.{h,c}
authorPavel Filipenský <pfilipensky@samba.org>
Wed, 3 Dec 2025 16:47:54 +0000 (17:47 +0100)
committerPavel Filipensky <pfilipensky@samba.org>
Mon, 8 Dec 2025 17:18:29 +0000 (17:18 +0000)
Makes data_blob_talloc_zero() use __location__ of the real caller

Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/util/data_blob.c
lib/util/data_blob.h

index 9372612d8a3e4e12bb1f2fd06aa3300a057949e7..12f4173c5e66996ae4e2af7a9b7764fb6eb2428c 100644 (file)
@@ -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
 **/
index 6577630e592aabc03aabe5a26dbb89466aeb8868..9309230aca173163b0c67357f724ef03a00a11fb 100644 (file)
@@ -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
 **/