diff options
author | Volker Lendecke <vl@samba.org> | 2022-11-28 10:19:54 +0100 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2022-12-14 04:32:34 +0000 |
commit | ccb5bafe93eb431ba53569b5176317bcbdeae322 (patch) | |
tree | 4fc192e27df56317aef51204c5109c26176dae84 /lib/talloc/talloc.c | |
parent | 7870e82cb4405a983f106a119203f1e193cb2f12 (diff) | |
download | samba-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.c | 23 |
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 */ |