]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
replace local function with use of standard talloc API
authorAlan T. DeKok <aland@freeradius.org>
Wed, 22 Apr 2026 00:47:42 +0000 (20:47 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 22 Apr 2026 00:52:53 +0000 (20:52 -0400)
src/lib/server/cf_util.c
src/lib/util/talloc.c
src/lib/util/talloc.h
src/lib/util/test/talloc_tests.c

index e19702aa6d5b655f97f42b42da123ede2c9a64af..f700ef46345e10305bad309267cbea623e2e300b 100644 (file)
@@ -2104,7 +2104,7 @@ void _cf_vlog_perr(fr_log_type_t type, CONF_ITEM const *ci, char const *file, in
                        char *first;
 
                        first = talloc_bstrdup(pool, prefix);
-                       talloc_buffer_append_buffer(pool, first, f_rules->first_prefix);
+                       MEM(talloc_strndup_append_buffer(first, f_rules->first_prefix, SIZE_MAX));
 
                        our_f_rules.first_prefix = first;
                } else {
@@ -2118,7 +2118,7 @@ void _cf_vlog_perr(fr_log_type_t type, CONF_ITEM const *ci, char const *file, in
                        char *subsq;
 
                        subsq = talloc_bstrdup(pool, prefix);
-                       talloc_buffer_append_buffer(pool, subsq, f_rules->subsq_prefix);
+                       MEM(talloc_strndup_append_buffer(subsq, f_rules->subsq_prefix, SIZE_MAX));
 
                        our_f_rules.subsq_prefix = subsq;
                } else {
index 8d33ecca1901ee5ef89f3928136f3522d38f1d3c..3ba27c63f6c5ce926868409eea8d8c856c8f4d8e 100644 (file)
@@ -698,39 +698,6 @@ char *talloc_bstr_realloc(TALLOC_CTX *ctx, char *in, size_t inlen)
        return n;
 }
 
-/** Concatenate to + from
- *
- * @param[in] ctx      to allocate realloced buffer in.
- * @param[in] to       talloc string buffer to append to.
- * @param[in] from     talloc string buffer to append.
- * @return
- *     - NULL if to or from are NULL or if the realloc fails.
- *       Note: You'll still need to free to if this function
- *       returns NULL.
- *     - The concatenation of to + from.  After this function
- *       returns to may point to invalid memory and should
- *       not be used.
- */
-char *talloc_buffer_append_buffer(TALLOC_CTX *ctx, char *to, char const *from)
-{
-       size_t to_len, from_len, total_len;
-       char *out;
-
-       if (!to || !from) return NULL;
-
-       to_len = talloc_array_length(to);
-       from_len = talloc_array_length(from);
-       total_len = to_len + (from_len - 1);
-
-       out = talloc_realloc(ctx, to, char, total_len);
-       if (!out) return NULL;
-
-       memcpy(out + (to_len - 1), from, from_len);
-       out[total_len - 1] = '\0';
-
-       return out;
-}
-
 /** Concatenate to + ...
  *
  * @param[in] ctx      to allocate realloced buffer in.
index 31f64bf1676026dd83fa7f9469e17590b4f0ede0..68423ff9a17678db90cea7b6c135064f148855ac 100644 (file)
@@ -232,8 +232,6 @@ char                *talloc_bstr_append(TALLOC_CTX *ctx, char *to, char const *from, size_t fr
 
 char           *talloc_bstr_realloc(TALLOC_CTX *ctx, char *in, size_t inlen);
 
-char           *talloc_buffer_append_buffer(TALLOC_CTX *ctx, char *to, char const *from);
-
 char           *talloc_buffer_append_variadic_buffer(TALLOC_CTX *ctx, char *to, int argc, ...);
 
 int            talloc_memcmp_array(uint8_t const *a, uint8_t const *b);
index 8ee735d954ebec82682a07bc8561f6f47cad2ee4..a134b00781d8f65fa48dcefd1056451bf8de287f 100644 (file)
@@ -943,42 +943,6 @@ static void test_talloc_typed_memdup(void)
        talloc_free(ctx);
 }
 
-/*
- *     talloc_buffer_append_buffer - concatenate talloc strings
- */
-static void test_talloc_buffer_append_buffer(void)
-{
-       TALLOC_CTX      *ctx;
-       char            *a, *result;
-
-       ctx = talloc_init_const("test");
-
-       TEST_CASE("Concatenate two talloc strings");
-       a = talloc_strdup(ctx, "hello ");
-       {
-               char *b = talloc_strdup(ctx, "world");
-               result = talloc_buffer_append_buffer(ctx, a, b);
-               TEST_ASSERT(result != NULL);
-               TEST_CHECK(strcmp(result, "hello world") == 0);
-               talloc_free(b);
-       }
-
-       TEST_CASE("NULL first arg returns NULL");
-       {
-               char *b = talloc_strdup(ctx, "test");
-               result = talloc_buffer_append_buffer(ctx, NULL, b);
-               TEST_CHECK(result == NULL);
-               talloc_free(b);
-       }
-
-       TEST_CASE("NULL second arg returns NULL");
-       a = talloc_strdup(ctx, "hello");
-       result = talloc_buffer_append_buffer(ctx, a, NULL);
-       TEST_CHECK(result == NULL);
-
-       talloc_free(ctx);
-}
-
 /*
  *     talloc_array_null_terminate / talloc_array_null_strip
  */
@@ -1269,7 +1233,6 @@ TEST_LIST = {
        { "talloc_memcmp_array",                test_talloc_memcmp_array },
        { "talloc_memcmp_bstr",                 test_talloc_memcmp_bstr },
        { "talloc_typed_memdup",                test_talloc_typed_memdup },
-       { "talloc_buffer_append_buffer",        test_talloc_buffer_append_buffer },
        { "talloc_array_null_terminate",        test_talloc_array_null_terminate },
        { "talloc_destructor_add",              test_talloc_destructor_add },
        { "talloc_link_ctx",                    test_talloc_link_ctx },