Author: jra Date: 2006-03-13 04:27:53 +0000 (Mon, 13 Mar 2006) New Revision: 14292
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=14292 Log: 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 Modified: branches/SAMBA_3_0/source/lib/talloc.c Changeset: Modified: branches/SAMBA_3_0/source/lib/talloc.c =================================================================== --- branches/SAMBA_3_0/source/lib/talloc.c 2006-03-13 04:27:47 UTC (rev 14291) +++ branches/SAMBA_3_0/source/lib/talloc.c 2006-03-13 04:27:53 UTC (rev 14292) @@ -289,7 +289,11 @@ 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 @@ 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 @@ 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;