summaryrefslogtreecommitdiffstats
path: root/source/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2006-03-13 04:27:53 +0000
committerJeremy Allison <jra@samba.org>2006-03-13 04:27:53 +0000
commit2e9bebf47b8b7e47d4e9973914ec79f5c8b678e5 (patch)
tree9efcf4e48c1a6b6aa2d1a786e4ec23ebc24cc92f /source/lib
parentb9f2fd5b6777433be3044588a49a14684a329cd6 (diff)
downloadsamba-2e9bebf47b8b7e47d4e9973914ec79f5c8b678e5.tar.gz
samba-2e9bebf47b8b7e47d4e9973914ec79f5c8b678e5.tar.xz
samba-2e9bebf47b8b7e47d4e9973914ec79f5c8b678e5.zip
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
Diffstat (limited to 'source/lib')
-rw-r--r--source/lib/talloc.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/source/lib/talloc.c b/source/lib/talloc.c
index 445ae8f3e99..ba189199d71 100644
--- a/source/lib/talloc.c
+++ b/source/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;