]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commitdiff
common/vsprintf: Explicitly treat negative lengths as 'unlimited'
authorTim Deegan <tim@xen.org>
Thu, 28 Nov 2013 14:33:06 +0000 (14:33 +0000)
committerTim Deegan <tim@xen.org>
Thu, 6 Mar 2014 10:12:38 +0000 (10:12 +0000)
The old code relied on implictly casting negative numbers to size_t
making a very large limit, which was correct but non-obvious.

Coverity CID 1128575

Signed-off-by: Tim Deegan <tim@xen.org>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Keir Fraser <keir@xen.org>
xen/common/vsprintf.c

index f7cb0f184f4f34ffcb8c47ea45120fcafe552768..8c432821b0310686515b275efc1e6d13dacb9113 100644 (file)
@@ -240,7 +240,7 @@ static char *number(
 static char *string(char *str, char *end, const char *s,
                     int field_width, int precision, int flags)
 {
-    int i, len = strnlen(s, precision);
+    int i, len = (precision < 0) ? strlen(s) : strnlen(s, precision);
 
     if (!(flags & LEFT)) {
         while (len < field_width--) {