ia64/xen-unstable

changeset 18527:40233384ffe3

vsprintf: Better size_t input checking, and fix return values of
[v]scnprintf() when size <= 0.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Sep 22 15:15:19 2008 +0100 (2008-09-22)
parents c0db74e41662
children 1c09b810f977
files xen/common/vsprintf.c
line diff
     1.1 --- a/xen/common/vsprintf.c	Mon Sep 22 14:37:31 2008 +0100
     1.2 +++ b/xen/common/vsprintf.c	Mon Sep 22 15:15:19 2008 +0100
     1.3 @@ -272,7 +272,7 @@ int vsnprintf(char *buf, size_t size, co
     1.4                                  /* 'z' changed to 'Z' --davidm 1/25/99 */
     1.5  
     1.6      /* Reject out-of-range values early */
     1.7 -    BUG_ON((int)size < 0);
     1.8 +    BUG_ON(((int)size < 0) || ((unsigned int)size != size));
     1.9  
    1.10      str = buf;
    1.11      end = buf + size - 1;
    1.12 @@ -504,8 +504,10 @@ int vscnprintf(char *buf, size_t size, c
    1.13  {
    1.14      int i;
    1.15  
    1.16 -    i=vsnprintf(buf,size,fmt,args);
    1.17 -    return (i >= size) ? (size - 1) : i;
    1.18 +    i = vsnprintf(buf,size,fmt,args);
    1.19 +    if (i >= size)
    1.20 +        i = size - 1;
    1.21 +    return (i > 0) ? i : 0;
    1.22  }
    1.23  
    1.24  EXPORT_SYMBOL(vscnprintf);
    1.25 @@ -772,7 +774,9 @@ int scnprintf(char * buf, size_t size, c
    1.26      va_start(args, fmt);
    1.27      i = vsnprintf(buf, size, fmt, args);
    1.28      va_end(args);
    1.29 -    return (i >= size) ? (size - 1) : i;
    1.30 +    if (i >= size)
    1.31 +        i = size - 1;
    1.32 +    return (i > 0) ? i : 0;
    1.33  }
    1.34  EXPORT_SYMBOL(scnprintf);
    1.35