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:13:21 +0200
Delivery-date: Wed, 05 Oct 2005 11:10:58 +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=LZYex1oE+494pS9gAlS6fbGK5geUtIJldeFPYrNF2J3UbSOnYYYryia+XE7w9nOadQZDz2/nc7PlWNxxl1yBtnpVmyqNVuDCBK+OWtm9DJIspamDvybyXZb275bRMJLfS3kn04VsM+cGm+cjj1OX7NkMuEmta67C2mjn875KSys=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <C3077285E500D5118C7300508BB3D9170C10BDB4@xxxxxxxxxxxxxxxx>
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>
Reply-to: Jacob Gorm Hansen <jacobg@xxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
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

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

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