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 {
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 {
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.
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);
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
*/
{ "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 },