From owner-freebsd-chat@FreeBSD.ORG Fri Jul 16 08:06:09 2010 Return-Path: Delivered-To: freebsd-chat@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 99F3F1065672 for ; Fri, 16 Jul 2010 08:06:09 +0000 (UTC) (envelope-from des@des.no) Received: from smtp.des.no (smtp.des.no [194.63.250.102]) by mx1.freebsd.org (Postfix) with ESMTP id 5C0B98FC1C for ; Fri, 16 Jul 2010 08:06:09 +0000 (UTC) Received: from ds4.des.no (des.no [84.49.246.2]) by smtp.des.no (Postfix) with ESMTP id 6A4B51FFC33; Fri, 16 Jul 2010 08:06:08 +0000 (UTC) Received: by ds4.des.no (Postfix, from userid 1001) id 07C62845D5; Fri, 16 Jul 2010 10:03:55 +0200 (CEST) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: d@delphij.net References: <4C3F8F2E.9080705@delphij.net> Date: Fri, 16 Jul 2010 10:03:54 +0200 In-Reply-To: <4C3F8F2E.9080705@delphij.net> (Xin LI's message of "Thu, 15 Jul 2010 15:43:58 -0700") Message-ID: <868w5bkg45.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: "deeptech71@gmail.com" , freebsd-chat@freebsd.org Subject: Re: is strlen()'s read-4-bytes-ahead a standard? X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Jul 2010 08:06:09 -0000 Xin LI writes: > deeptech71@gmail.com writes: > > Some C implementations use the read-4-bytes-ahead technique to speed > > up strlen(). Does the C standard state anything about strlen() being > > allowed to read past the terminating zero? > It's not 4-bytes-ahead, but read a whole (aligned) word at one time. > I think C standard does not dictate in this detail. My guess is that it invokes undefined behavior, but it doesn't matter in practice, because as long as you only read one aligned word at a time, and as long as the pointer you got is valid and points to a properly terminated string, you might read trash (which is expected), but you will never read unmapped memory. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no