Skip to content

Commit cd684ac

Browse files
committed
replace local function with use of standard talloc API
1 parent 2f6348a commit cd684ac

4 files changed

Lines changed: 2 additions & 74 deletions

File tree

src/lib/server/cf_util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ void _cf_vlog_perr(fr_log_type_t type, CONF_ITEM const *ci, char const *file, in
21042104
char *first;
21052105

21062106
first = talloc_bstrdup(pool, prefix);
2107-
talloc_buffer_append_buffer(pool, first, f_rules->first_prefix);
2107+
MEM(talloc_strndup_append_buffer(first, f_rules->first_prefix, SIZE_MAX));
21082108

21092109
our_f_rules.first_prefix = first;
21102110
} else {
@@ -2118,7 +2118,7 @@ void _cf_vlog_perr(fr_log_type_t type, CONF_ITEM const *ci, char const *file, in
21182118
char *subsq;
21192119

21202120
subsq = talloc_bstrdup(pool, prefix);
2121-
talloc_buffer_append_buffer(pool, subsq, f_rules->subsq_prefix);
2121+
MEM(talloc_strndup_append_buffer(subsq, f_rules->subsq_prefix, SIZE_MAX));
21222122

21232123
our_f_rules.subsq_prefix = subsq;
21242124
} else {

src/lib/util/talloc.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -698,39 +698,6 @@ char *talloc_bstr_realloc(TALLOC_CTX *ctx, char *in, size_t inlen)
698698
return n;
699699
}
700700

701-
/** Concatenate to + from
702-
*
703-
* @param[in] ctx to allocate realloced buffer in.
704-
* @param[in] to talloc string buffer to append to.
705-
* @param[in] from talloc string buffer to append.
706-
* @return
707-
* - NULL if to or from are NULL or if the realloc fails.
708-
* Note: You'll still need to free to if this function
709-
* returns NULL.
710-
* - The concatenation of to + from. After this function
711-
* returns to may point to invalid memory and should
712-
* not be used.
713-
*/
714-
char *talloc_buffer_append_buffer(TALLOC_CTX *ctx, char *to, char const *from)
715-
{
716-
size_t to_len, from_len, total_len;
717-
char *out;
718-
719-
if (!to || !from) return NULL;
720-
721-
to_len = talloc_array_length(to);
722-
from_len = talloc_array_length(from);
723-
total_len = to_len + (from_len - 1);
724-
725-
out = talloc_realloc(ctx, to, char, total_len);
726-
if (!out) return NULL;
727-
728-
memcpy(out + (to_len - 1), from, from_len);
729-
out[total_len - 1] = '\0';
730-
731-
return out;
732-
}
733-
734701
/** Concatenate to + ...
735702
*
736703
* @param[in] ctx to allocate realloced buffer in.

src/lib/util/talloc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ char *talloc_bstr_append(TALLOC_CTX *ctx, char *to, char const *from, size_t fr
232232

233233
char *talloc_bstr_realloc(TALLOC_CTX *ctx, char *in, size_t inlen);
234234

235-
char *talloc_buffer_append_buffer(TALLOC_CTX *ctx, char *to, char const *from);
236-
237235
char *talloc_buffer_append_variadic_buffer(TALLOC_CTX *ctx, char *to, int argc, ...);
238236

239237
int talloc_memcmp_array(uint8_t const *a, uint8_t const *b);

src/lib/util/test/talloc_tests.c

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -943,42 +943,6 @@ static void test_talloc_typed_memdup(void)
943943
talloc_free(ctx);
944944
}
945945

946-
/*
947-
* talloc_buffer_append_buffer - concatenate talloc strings
948-
*/
949-
static void test_talloc_buffer_append_buffer(void)
950-
{
951-
TALLOC_CTX *ctx;
952-
char *a, *result;
953-
954-
ctx = talloc_init_const("test");
955-
956-
TEST_CASE("Concatenate two talloc strings");
957-
a = talloc_strdup(ctx, "hello ");
958-
{
959-
char *b = talloc_strdup(ctx, "world");
960-
result = talloc_buffer_append_buffer(ctx, a, b);
961-
TEST_ASSERT(result != NULL);
962-
TEST_CHECK(strcmp(result, "hello world") == 0);
963-
talloc_free(b);
964-
}
965-
966-
TEST_CASE("NULL first arg returns NULL");
967-
{
968-
char *b = talloc_strdup(ctx, "test");
969-
result = talloc_buffer_append_buffer(ctx, NULL, b);
970-
TEST_CHECK(result == NULL);
971-
talloc_free(b);
972-
}
973-
974-
TEST_CASE("NULL second arg returns NULL");
975-
a = talloc_strdup(ctx, "hello");
976-
result = talloc_buffer_append_buffer(ctx, a, NULL);
977-
TEST_CHECK(result == NULL);
978-
979-
talloc_free(ctx);
980-
}
981-
982946
/*
983947
* talloc_array_null_terminate / talloc_array_null_strip
984948
*/
@@ -1269,7 +1233,6 @@ TEST_LIST = {
12691233
{ "talloc_memcmp_array", test_talloc_memcmp_array },
12701234
{ "talloc_memcmp_bstr", test_talloc_memcmp_bstr },
12711235
{ "talloc_typed_memdup", test_talloc_typed_memdup },
1272-
{ "talloc_buffer_append_buffer", test_talloc_buffer_append_buffer },
12731236
{ "talloc_array_null_terminate", test_talloc_array_null_terminate },
12741237
{ "talloc_destructor_add", test_talloc_destructor_add },
12751238
{ "talloc_link_ctx", test_talloc_link_ctx },

0 commit comments

Comments
 (0)