summaryrefslogtreecommitdiff
path: root/lib/talloc/talloc.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2022-11-28 10:19:54 +0100
committerJeremy Allison <jra@samba.org>2022-12-14 04:32:34 +0000
commitccb5bafe93eb431ba53569b5176317bcbdeae322 (patch)
tree4fc192e27df56317aef51204c5109c26176dae84 /lib/talloc/talloc.c
parent7870e82cb4405a983f106a119203f1e193cb2f12 (diff)
downloadsamba-ccb5bafe93eb431ba53569b5176317bcbdeae322.tar.gz
lib: Move talloc_asprintf_addbuf() to talloc
I wanted to use this in debug.c, but this would have meant to pollute debug's deps with a lot of stuff. Also, looking through uses of talloc_asprint_append(), very many of those don't do NULL checks properly and could benefit from the _addbuf() flavor. We can add a vasprintf variant later if the need shows up. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/talloc/talloc.c')
-rw-r--r--lib/talloc/talloc.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c
index 29da190880a..0189fa03be0 100644
--- a/lib/talloc/talloc.c
+++ b/lib/talloc/talloc.c
@@ -2752,6 +2752,29 @@ _PUBLIC_ char *talloc_asprintf_append_buffer(char *s, const char *fmt, ...)
return s;
}
+_PUBLIC_ void talloc_asprintf_addbuf(char **ps, const char *fmt, ...)
+{
+ va_list ap;
+ char *s = *ps;
+ char *t = NULL;
+
+ if (s == NULL) {
+ return;
+ }
+
+ va_start(ap, fmt);
+ t = talloc_vasprintf_append_buffer(s, fmt, ap);
+ va_end(ap);
+
+ if (t == NULL) {
+ /* signal failure to the next caller */
+ TALLOC_FREE(s);
+ *ps = NULL;
+ } else {
+ *ps = t;
+ }
+}
+
/*
alloc an array, checking for integer overflow in the array size
*/