/*
* Trim the final ", "
*/
- MEM(list = talloc_realloc_bstr(NULL, list, talloc_array_length(list) - 3));
+ MEM(list = talloc_bstr_realloc(NULL, list, talloc_array_length(list) - 3));
cf_log_err(cp, "Invalid value \"%s\". Expected one of %s", cf_pair_value(cp), list);
* Shrink the buffer
*/
if ((node->xlat->buf_len > 0) && (slen > 0)) {
- MEM(str = talloc_realloc_bstr(ctx, str, (size_t)slen));
+ MEM(str = talloc_bstr_realloc(ctx, str, (size_t)slen));
}
/*
/*
* Shrink the buffer to the right size
*/
- MEM(start = talloc_realloc_bstr(ctx, start, node->len));
+ MEM(start = talloc_bstr_realloc(ctx, start, node->len));
node->fmt = start;
return p - fmt;
* ...and as pcre2_substitute just succeeded actual_len does not include \0.
*/
if (actual_len < (buff_len - 1)) {
- buff = talloc_realloc_bstr(ctx, buff, actual_len);
+ buff = talloc_bstr_realloc(ctx, buff, actual_len);
if (!buff) {
fr_strerror_printf("reallocing pcre2_substitute result buffer failed");
return -1;
*
* @param[in] ctx to realloc buffer into.
* @param[in] in string to trim. Will be invalid after
- * this function returns.
+ * this function returns. If NULL a new zero terminated
+ * buffer of inlen bytes will be allocated.
* @param[in] inlen Length to trim string to.
* @return
* - The realloced string on success. in then points to invalid memory.
* - NULL on failure. In will still be valid.
*/
-char *talloc_realloc_bstr(TALLOC_CTX *ctx, char *in, size_t inlen)
+char *talloc_bstr_realloc(TALLOC_CTX *ctx, char *in, size_t inlen)
{
char *n;
+ if (!in) {
+ n = talloc_array(ctx, char, inlen);
+ n[0] = '\0';
+ return n;
+ }
+
n = talloc_realloc_size(ctx, in, inlen + 1);
if (!n) return NULL;
char *talloc_bstr_append(TALLOC_CTX *ctx, char *to, char const *from, size_t from_len);
-char *talloc_realloc_bstr(TALLOC_CTX *ctx, char *in, size_t inlen);
+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 *n;
- n = talloc_realloc_bstr(ctx, plaintext, plaintext_len);
+ n = talloc_bstr_realloc(ctx, plaintext, plaintext_len);
if (unlikely(!n)) {
REDEBUG("Failed shrinking plaintext buffer");
talloc_free(plaintext);