summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2006-03-13 04:27:53 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:15:23 -0500
commit432490a4b8193d881259a687af1fdbf5a35278a8 (patch)
tree9c991e4f43fb378e77d81d239aaaae786eb59f57 /source3/lib
parent19879eba8378f58db403c27202b9cc0af60db559 (diff)
downloadsamba-432490a4b8193d881259a687af1fdbf5a35278a8.tar.gz
r14292: Janitor for tridge (samba3 talloc is almost identical
to Samba4 talloc). Jeremy - make the snprintf call in talloc portable to older solaris boxes - fixed an error found sing the beam analyser (This used to be commit 1e1bae7afd9cd0051878ff1810c8ddfc28129233)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/talloc.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/source3/lib/talloc.c b/source3/lib/talloc.c
index 445ae8f3e9..ba189199d7 100644
--- a/source3/lib/talloc.c
+++ b/source3/lib/talloc.c
@@ -289,7 +289,11 @@ static int talloc_unreference(const void *context, const void *ptr)
for (h=tc->refs;h;h=h->next) {
struct talloc_chunk *p = talloc_parent_chunk(h);
- if ((p==NULL && context==NULL) || TC_PTR_FROM_CHUNK(p) == context) break;
+ if (p == NULL) {
+ if (context == NULL) break;
+ } else if (TC_PTR_FROM_CHUNK(p) == context) {
+ break;
+ }
}
if (h == NULL) {
return -1;
@@ -1076,10 +1080,14 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap)
int len;
char *ret;
va_list ap2;
+ char c;
VA_COPY(ap2, ap);
- len = vsnprintf(NULL, 0, fmt, ap2);
+ /* this call looks strange, but it makes it work on older solaris boxes */
+ if ((len = vsnprintf(&c, 1, fmt, ap2)) < 0) {
+ return NULL;
+ }
ret = _talloc(t, len+1);
if (ret) {
@@ -1131,7 +1139,15 @@ static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
VA_COPY(ap2, ap);
s_len = tc->size - 1;
- len = vsnprintf(NULL, 0, fmt, ap2);
+ if ((len = vsnprintf(NULL, 0, fmt, ap2)) <= 0) {
+ /* Either the vsnprintf failed or the format resulted in
+ * no characters being formatted. In the former case, we
+ * ought to return NULL, in the latter we ought to return
+ * the original string. Most current callers of this
+ * function expect it to never return NULL.
+ */
+ return s;
+ }
s = talloc_realloc(NULL, s, char, s_len + len+1);
if (!s) return NULL;