From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH 1/4] common/vsprintf: Explicitly treat negative lengths as 'unlimited' Date: Thu, 28 Nov 2013 16:48:37 +0000 Message-ID: <529773E5.60309@citrix.com> References: <1385656665-12551-1-git-send-email-tim@xen.org> <1385656665-12551-2-git-send-email-tim@xen.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1385656665-12551-2-git-send-email-tim@xen.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Tim Deegan Cc: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On 28/11/13 16:37, Tim Deegan wrote: > 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 Reviewed-by: Andrew Cooper This CID was introduced as a side effect of my %ps/%pS series, which was basically code motion for this piece. The previous code was not exactly fantastic. > --- > xen/common/vsprintf.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c > index 43dc392..68553bb 100644 > --- a/xen/common/vsprintf.c > +++ b/xen/common/vsprintf.c > @@ -239,7 +239,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--) {