Skip to content

Commit fb54c1b

Browse files
committed
rework to avoid intermediate function
1 parent 2f6348a commit fb54c1b

3 files changed

Lines changed: 8 additions & 37 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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ RCSIDH(talloc_h, "$Id$")
2828
extern "C" {
2929
#endif
3030

31+
#ifndef TALLOC_TYPE_SAFE
3132
#include <ctype.h>
3233

3334
#ifdef HAVE_WDOCUMENTATION
@@ -139,6 +140,7 @@ static inline size_t talloc_strlen(char const *s)
139140
char const *our_s = s;
140141
return talloc_array_length(our_s) - 1;
141142
}
143+
142144
#define talloc_strdup(_ctx, _str) talloc_typed_strdup((TALLOC_CTX *) (_ctx), _str)
143145
#define talloc_strndup(_ctx, _str, _len) talloc_typed_strndup((TALLOC_CTX *) (_ctx), _str, _len)
144146
#define talloc_asprintf talloc_typed_asprintf
@@ -212,6 +214,7 @@ void *_talloc_realloc_zero(const void *ctx, void *ptr, size_t elem_size, unsign
212214
(_type *)_talloc_realloc_zero((_ctx), (_ptr), sizeof(_type), _count, #_type)
213215

214216
/** @hidecallergraph */
217+
#ifndef TALLOC_TYPE_SAFE
215218
char *talloc_typed_strdup(TALLOC_CTX *ctx, char const *p);
216219

217220
char *talloc_typed_strdup_buffer(TALLOC_CTX *ctx, char const *p);
@@ -223,6 +226,7 @@ char *talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt, ...) CC_HINT(form
223226
char *talloc_typed_vasprintf(TALLOC_CTX *ctx, char const *fmt, va_list ap) CC_HINT(format (printf, 2, 0)) CC_HINT(nonnull (2));
224227

225228
uint8_t *talloc_typed_memdup(TALLOC_CTX *ctx, uint8_t const *in, size_t inlen);
229+
#endif
226230

227231
char *talloc_bstrdup(TALLOC_CTX *ctx, char const *in);
228232

@@ -232,8 +236,6 @@ char *talloc_bstr_append(TALLOC_CTX *ctx, char *to, char const *from, size_t fr
232236

233237
char *talloc_bstr_realloc(TALLOC_CTX *ctx, char *in, size_t inlen);
234238

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

239241
int talloc_memcmp_array(uint8_t const *a, uint8_t const *b);
@@ -265,6 +267,8 @@ typedef struct talloc_child_ctx_s TALLOC_CHILD_CTX;
265267
TALLOC_CHILD_CTX *talloc_child_ctx_init(TALLOC_CTX *ctx);
266268
TALLOC_CHILD_CTX *talloc_child_ctx_alloc(TALLOC_CHILD_CTX *parent) CC_HINT(nonnull);
267269

270+
#endif
271+
268272
#ifdef __cplusplus
269273
}
270274
#endif

0 commit comments

Comments
 (0)