From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11619 invoked by alias); 4 Apr 2003 14:54:09 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 11255 invoked from network); 4 Apr 2003 14:54:08 -0000 Received: from unknown (HELO ns2.uk.superh.com) (193.128.105.170) by sources.redhat.com with SMTP; 4 Apr 2003 14:54:08 -0000 Received: from sh-uk-ex01.uk.w2k.superh.com (sh-uk-ex01 [192.168.16.17]) by ns2.uk.superh.com (8.11.6+Sun/8.11.6) with ESMTP id h34EYDx19303; Fri, 4 Apr 2003 15:34:13 +0100 (BST) Received: from superh.com ([192.168.17.40]) by sh-uk-ex01.uk.w2k.superh.com with Microsoft SMTPSVC(5.0.2195.5329); Fri, 4 Apr 2003 15:54:11 +0100 Message-ID: <3E8D9C30.E2CA766E@superh.com> Date: Fri, 04 Apr 2003 14:54:00 -0000 From: Joern Rennecke Organization: SuperH UK Ltd. X-Accept-Language: en MIME-Version: 1.0 To: gdb@sources.redhat.com, newlib@sources.redhat.com, bug-glibc@gnu.org CC: stephen.thomas@superh.com, sean.mcgoogan@superh.com Subject: memset (0, 0, 0); Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 04 Apr 2003 14:54:11.0514 (UTC) FILETIME=[0D6159A0:01C2FABA] X-SW-Source: 2003-04/txt/msg00043.txt.bz2 On some processors, memset can be implemented more efficiently when you always read - and possibly also write back - the first memory word contained partially or in whole in the to-be-modified object This conflicts with gdb usage of memset (0, 0, 0); in some places. There are three practical questions here: - should gdb use this idiom? - should all target-specific variants of newlib's memset implement it? - should all target-specific variants of glibc's memset implement it? My understanding of the standard is that memset with an unmapped destination address always invokes undefined behavior. It says: 3.14: object: ... Except for bit-fields, objects are composed of contigous sequences of one or more bytes, ... 7.1.7: Use of library functions Each of the following statements apply unless explicitly stated otherwise in the detailed descriptions that follow. If an argument has an invalid value (such as a value outside the domain of the function, or a pointer outside the address space of the program, or a null pointer), the behaviour is undefined. If a function argument is described as being an array, the pointer actually passed to the function shall have a value such that all address computations and accesses to objects (that would be valid if the pointer did point to the first element of such an array) are in fact valid. ... 7.11.1 String function conventions The header declares one type and several functions, and defines one macro useful for manipulating arrays of character type and other objects treated as arrays of character type. ... in all cases a char * or a void * argument points to the initial (lowest addressed) character of the array. ... 7.11.6.1 The memset function ... void *memset (void *s, int c, size_t n); ... The memset function copies the value of c (converted to unsigned char) into each of the first n characters of the object pointed to by s. ... So, as i understand this, this means that the first argument of memset must point to an object, which contains at least one (the first) character. Passing a NULL pointer, or any other address which is outside the address space of the program, invokes undefined behaviour. -- -------------------------- SuperH (UK) Ltd. 2410 Aztec West / Almondsbury / BRISTOL / BS32 4QX T:+44 1454 465658