WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH] Cleanup use of strlen() to check for empty strin

To: "Petersson, Mats" <mats.petersson@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: Re: [Xen-devel] [PATCH] Cleanup use of strlen() to check for empty string
From: Jacob Gorm Hansen <jacobg@xxxxxxx>
Date: Wed, 5 Oct 2005 13:16:48 +0200
Delivery-date: Wed, 05 Oct 2005 11:14:22 +0000
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=RHJIp++OhEZ5zy9/KgnSbTxwjaIk+MWrsGuHHHF1IhPFygn+vSHqaM7UpkgQzs7fdNQJV/1l/fEn3qrBpHRr8wX/RIY/BR4bhsmGAIVpFGHaPb1gsVcM0r8WL5b1bAC9tCZUOU92ubZPjdnYLNrYNJxCman2XxLV2rly4yHNLQE=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <e08041f30510050413r6b5c4fc3w4e66778992085439@xxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <C3077285E500D5118C7300508BB3D9170C10BDB4@xxxxxxxxxxxxxxxx> <e08041f30510050413r6b5c4fc3w4e66778992085439@xxxxxxxxxxxxxx>
Reply-to: Jacob Gorm Hansen <jacobg@xxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Oops sorry I take that back, gcc3 just produces different output...

Never mind then. Must get coffee.

Jacob

On 10/5/05, Jacob Gorm Hansen <jacobg@xxxxxxx> wrote:
> On 10/5/05, Petersson, Mats <mats.petersson@xxxxxxx> wrote:
>
> > I created a function:
> >
> > int foo(char *s)
> > {
> >         if (strlen(s)) return 1; else return 0;
> > }
> >
> > Compiled with gcc 4.0.0 as:
> > gcc -O3 -s x.c (or gcc -O2 ...)
> > Gives the following code:
> >
> > foo:
> >         xorl  %eax, %eax
> >         cmpb  $(0), (%rdi)
> >         sete  %al
> >         ret
>
> Cool, I am surprised gcc4 is able to fix this. gcc 3.3.4 which I am
> using is not, even with -O3. How does gcc4 behave without -O3?
>
> foo:
> push   %ebp
> mov    %esp,%ebp
> mov    0x8(%ebp),%edx
> pop    %ebp
> cmpb   $0x0,(%edx)
> setne  %dl
> movzbl %dl,%eax
> ret
>
> I guess I only reacted to this because I have seen worse examples
> resulting from the "strlen is constant-time" assumption (people
> iterating over a string in a while(strlen(s)) loop), and because I was
> bored with trying to get block devices running with xenbus. :-)
>
> Jacob
>


--
Save time and bandwidth with EDelta: http://www.diku.dk/~jacobg/edelta/

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>