talloc: Fix size type and checks in _vasprintf_tc
authorAndreas Schneider <asn@samba.org>
Wed, 21 Mar 2018 10:55:45 +0000 (11:55 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 21 Mar 2018 12:11:14 +0000 (13:11 +0100)
This fixes compilation with -Wstrict-overflow=2

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/talloc/talloc.c

index cd159ef89c2eae848ca531cc210585133795b8e6..430ebc70f54cd38fc264bbed2b79cbe9cfc3423e 100644 (file)
@@ -2554,7 +2554,8 @@ static struct talloc_chunk *_vasprintf_tc(const void *t,
                                          const char *fmt,
                                          va_list ap)
 {
-       int len;
+       int vlen;
+       size_t len;
        char *ret;
        va_list ap2;
        struct talloc_chunk *tc;
@@ -2562,9 +2563,13 @@ static struct talloc_chunk *_vasprintf_tc(const void *t,
 
        /* this call looks strange, but it makes it work on older solaris boxes */
        va_copy(ap2, ap);
-       len = vsnprintf(buf, sizeof(buf), fmt, ap2);
+       vlen = vsnprintf(buf, sizeof(buf), fmt, ap2);
        va_end(ap2);
-       if (unlikely(len < 0)) {
+       if (unlikely(vlen < 0)) {
+               return NULL;
+       }
+       len = vlen;
+       if (unlikely(len + 1 < len)) {
                return NULL;
        }