]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Factor out ADD_TO_MALLOC_ARRAY()
authorVolker Lendecke <vl@samba.org>
Mon, 30 Sep 2024 08:34:17 +0000 (10:34 +0200)
committerVolker Lendecke <vl@samba.org>
Wed, 2 Oct 2024 13:12:30 +0000 (13:12 +0000)
ADD_TO_ARRAY with an explicit NULL mem_ctx is only used in 3
places. I've checked the other places, and I think I made sure that the
mem_ctx being passed in is non-NULL everywhere else.

This makes the "legacy" use with SMB_REALLOC more obvious.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/include/smb_macros.h
source3/modules/vfs_hpuxacl.c
source3/modules/vfs_solarisacl.c
source3/utils/net_rpc_shell.c

index 4b3989dce933f80ac162e70978da2c83cdc5a429..bd7f1a115ad391382d833078a0da4bc6ffa45102 100644 (file)
@@ -273,15 +273,24 @@ copy an IP address from one buffer to another
 
 #endif
 
-#define ADD_TO_ARRAY(mem_ctx, type, elem, array, num) \
-do { \
-       *(array) = ((mem_ctx) != NULL) ? \
-               talloc_realloc(mem_ctx, (*(array)), type, (*(num))+1) : \
-               SMB_REALLOC_ARRAY((*(array)), type, (*(num))+1); \
-       SMB_ASSERT((*(array)) != NULL); \
-       (*(array))[*(num)] = (elem); \
-       (*(num)) += 1; \
-} while (0)
+#define ADD_TO_ARRAY(mem_ctx, type, elem, array, num)    \
+       do {                                             \
+               *(array) = talloc_realloc(mem_ctx,       \
+                                         (*(array)),    \
+                                         type,          \
+                                         (*(num)) + 1); \
+               SMB_ASSERT((*(array)) != NULL);          \
+               (*(array))[*(num)] = (elem);             \
+               (*(num)) += 1;                           \
+       } while (0)
+
+#define ADD_TO_MALLOC_ARRAY(type, elem, array, num)                           \
+       do {                                                                  \
+               *(array) = SMB_REALLOC_ARRAY((*(array)), type, (*(num)) + 1); \
+               SMB_ASSERT((*(array)) != NULL);                               \
+               (*(array))[*(num)] = (elem);                                  \
+               (*(num)) += 1;                                                \
+       } while (0)
 
 #define ADD_TO_LARGE_ARRAY(mem_ctx, type, elem, array, num, size) \
        add_to_large_array((mem_ctx), sizeof(type), &(elem), (void *)(array), (num), (size));
index 31903a1feca257e367a7281b8d98b441fb1a6eec..91801daca98fba2e9eecf59be4b7098d108d92f5 100644 (file)
@@ -727,8 +727,7 @@ static bool hpux_add_to_acl(HPUX_ACL_T *hpux_acl, int *count,
                if (!_IS_OF_TYPE(add_acl[i], type)) {
                        continue;
                }
-               ADD_TO_ARRAY(NULL, HPUX_ACE_T, add_acl[i],
-                            hpux_acl, count);
+               ADD_TO_MALLOC_ARRAY(HPUX_ACE_T, add_acl[i], hpux_acl, count);
                if (hpux_acl == NULL) {
                        DEBUG(10, ("error enlarging acl.\n"));
                        errno = ENOMEM;
index d31bda502333cdcfa6320aa9af383a7b0fc7414d..eb54c6183158075cb90992f37fc236d48e9b5b24 100644 (file)
@@ -609,8 +609,10 @@ static bool solaris_add_to_acl(SOLARIS_ACL_T *solaris_acl, int *count,
                if (!_IS_OF_TYPE(add_acl[i], type)) {
                        continue;
                }
-               ADD_TO_ARRAY(NULL, SOLARIS_ACE_T, add_acl[i], 
-                            solaris_acl, count);
+               ADD_TO_MALLOC_ARRAY(SOLARIS_ACE_T,
+                                   add_acl[i],
+                                   solaris_acl,
+                                   count);
                if (solaris_acl == NULL) {
                        DEBUG(10, ("error enlarging acl.\n"));
                        errno = ENOMEM;
index 1ea7080e35dfe11db47d29d59a18ee4c8ce51cf5..5b1285086f88890349eea12b1029edf6a4b2eb3a 100644 (file)
@@ -52,7 +52,7 @@ static char **completion_fn(const char *text, int start, int end)
                return NULL;
        }
 
-       ADD_TO_ARRAY(NULL, char *, SMB_STRDUP(text), &cmds, &n_cmds);
+       ADD_TO_MALLOC_ARRAY(char *, SMB_STRDUP(text), &cmds, &n_cmds);
 
        for (c = this_ctx->cmds; c->name != NULL; c++) {
                bool match = (strncmp(text, c->name, strlen(text)) == 0);
@@ -69,7 +69,7 @@ static char **completion_fn(const char *text, int start, int end)
                n_cmds -= 1;
        }
 
-       ADD_TO_ARRAY(NULL, char *, NULL, &cmds, &n_cmds);
+       ADD_TO_MALLOC_ARRAY(char *, NULL, &cmds, &n_cmds);
        return cmds;
 }