1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-26 01:49:31 +03:00

lib: Factor out ADD_TO_MALLOC_ARRAY()

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>
This commit is contained in:
Volker Lendecke
2024-09-30 10:34:17 +02:00
parent f3e7d450ea
commit 14a5336802
4 changed files with 25 additions and 15 deletions

View 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));

View 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;

View 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;

View 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;
}