diff options
author | James Peach <jpeach@samba.org> | 2006-02-08 23:44:17 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:51:52 -0500 |
commit | f9f55ad5fcda943f6747d6bef72f6d9d00a263c4 (patch) | |
tree | 7f08af3c76f1c0168c5f1877532632b659aadccc /source4/lib | |
parent | 56e097e99455d943c909153597d0179c8ce1f8bb (diff) | |
download | samba-f9f55ad5fcda943f6747d6bef72f6d9d00a263c4.tar.gz samba-f9f55ad5fcda943f6747d6bef72f6d9d00a263c4.tar.bz2 samba-f9f55ad5fcda943f6747d6bef72f6d9d00a263c4.zip |
r13397: Propagate the error return from vsnprintf to trap the case where
we aren't linked against a C99 vsnprintf.
(This used to be commit 23782f899aaa5fe488d86d5e67e91be99ff7a146)
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/talloc/talloc.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c index ac2fedebdc..6b3328420d 100644 --- a/source4/lib/talloc/talloc.c +++ b/source4/lib/talloc/talloc.c @@ -1011,7 +1011,9 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) VA_COPY(ap2, ap); - len = vsnprintf(NULL, 0, fmt, ap2); + if ((len = vsnprintf(NULL, 0, fmt, ap2)) <= 0) { + return NULL; + } ret = _talloc(t, len+1); if (ret) { @@ -1060,7 +1062,15 @@ 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; |