From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.redhat.com (mail.redhat.com [199.183.24.239]) by listman.redhat.com (Postfix) with ESMTP id C26703035F for ; Mon, 26 Mar 2001 16:55:26 -0500 (EST) Received: (from mail@localhost) by mail.redhat.com (8.11.0/8.8.7) id f2QLv0P03244 for axp-list@listman.redhat.com; Mon, 26 Mar 2001 16:57:00 -0500 Received: from fuggles.cam.nist.gov (fuggles.cam.nist.gov [129.6.88.69]) by mail.redhat.com (8.11.0/8.8.7) with ESMTP id f2QLv0V03240 for ; Mon, 26 Mar 2001 16:57:00 -0500 Received: (from donahue@localhost) by fuggles.cam.nist.gov (8.9.3/8.9.3) id QAA06207; Mon, 26 Mar 2001 16:55:15 -0500 X-Authentication-Warning: fuggles.cam.nist.gov: donahue set sender to michael.donahue@nist.gov using -f From: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15039.47811.721618.932373@fuggles.cam.nist.gov> Date: Mon, 26 Mar 2001 16:55:15 -0500 To: axp-list@redhat.com Subject: Re: memchr bug? Request for enlightenment (lowercase 'e') In-Reply-To: <20010326143737.J13715@taarna.sector7.com> References: <15039.41702.809052.794191@fuggles.cam.nist.gov> <20010326143737.J13715@taarna.sector7.com> X-Mailer: VM 6.92 under Emacs 20.7.1 X-Loop: axp-list@redhat.com Sender: axp-list-admin@redhat.com Errors-To: axp-list-admin@redhat.com X-BeenThere: axp-list@redhat.com X-Mailman-Version: 2.0.1 Precedence: bulk Reply-To: axp-list@redhat.com X-Reply-To: michael.donahue@nist.gov (Michael Donahue) List-Help: List-Post: List-Subscribe: , List-Id: Linux and Red Hat on Alpha processors List-Unsubscribe: , List-Archive: Chris Eleveld writes: > Actually this may not be. You allocate 9 bytes. Memchr is probably >implemented using full word or longword fetches. As such it can be optimized >to 3 32bit fetches and bit shifts. Or even 2 64 bit on an alpha. Since you >lied and siad your buffer was 79 bytes long. If on the other hand you used >9 instead of 79 you could call this a bug. I believe you are right about the longword fetches. I'm a little surprised I haven't see this on other platforms, though. As regards the length of the buffer, the point is that this call may be buried inside a utility routine where I don't know the length of the incoming buffer. I have code similar to the printf example; I don't recall seeing an admonition about buffer sizes in the printf docs. In fact, the Linux fprintf man page says: If a precision is given, no null character need be present; if the precision is not specified, or is greater than the size of the array, the array must contain a terminating NUL character. The memchr man page states: The memchr() function scans the first n bytes of the memory area pointed to by s for the character c. The first byte to match c (interpreted as an unsigned character) stops the operation. This seems unclear. Does it scan n bytes, or does it stop at a match? Or is that left undefined? For myself, I can code around this as necessary, but if it is technically a bug in memchr(), it should be fixed for portability reasons. Just my $0.02, -m -- Michael J. Donahue National Institute of Standards and Technology Mathematical & Computational Sciences Division 100 Bureau Dr Stop 8910 Gaithersburg, MD 20899-8910 email: michael.donahue@nist.gov voice: (301) 975-5424 fax: (301) 990-4127 web: http://math.nist.gov/~MDonahue/