From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7988 invoked by alias); 23 Oct 2004 18:28:21 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 7980 invoked from network); 23 Oct 2004 18:28:20 -0000 Received: from unknown (HELO Cantor.suse.de) (195.135.220.2) by sourceware.org with SMTP; 23 Oct 2004 18:28:20 -0000 Received: from hermes.suse.de (hermes-ext.suse.de [195.135.221.8]) (using TLSv1 with cipher EDH-RSA-DES-CBC3-SHA (168/168 bits)) (No client certificate requested) by Cantor.suse.de (Postfix) with ESMTP id 3B6B2E272AF for ; Sat, 23 Oct 2004 20:26:29 +0200 (CEST) To: gdb-patches@sources.redhat.com Subject: Fix aliasing violations From: Andreas Schwab X-Yow: My EARS are GONE!! Date: Sat, 23 Oct 2004 18:28:00 -0000 Message-ID: User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-SW-Source: 2004-10/txt/msg00384.txt.bz2 The macro GROW_VECT in ada-lang.h violates the C aliasing rules. Andreas. 2004-10-23 Andreas Schwab * ada-lang.c (grow_vect): Return the new array instead of expecting pointer to pointer to avoid violation of aliasing rules. * ada-lang.h (GROW_VECT): Adapt call to grow_vect. --- gdb/ada-lang.c 20 Oct 2004 01:01:25 +0200 1.59 +++ gdb/ada-lang.c 23 Oct 2004 20:12:45 +0200 @@ -319,20 +319,21 @@ extract_string (CORE_ADDR addr, char *bu while (buf[char_index - 1] != '\000'); } -/* Assuming *OLD_VECT points to an array of *SIZE objects of size +/* Assuming VECT points to an array of *SIZE objects of size ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects, - updating *OLD_VECT and *SIZE as necessary. */ + updating *SIZE as necessary and returning the (new) array. */ -void -grow_vect (void **old_vect, size_t * size, size_t min_size, int element_size) +void * +grow_vect (void *vect, size_t *size, size_t min_size, int element_size) { if (*size < min_size) { *size *= 2; if (*size < min_size) *size = min_size; - *old_vect = xrealloc (*old_vect, *size * element_size); + vect = xrealloc (vect, *size * element_size); } + return vect; } /* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing --- gdb/ada-lang.h 20 Oct 2004 01:01:25 +0200 1.13 +++ gdb/ada-lang.h 23 Oct 2004 20:13:27 +0200 @@ -171,9 +171,9 @@ extern struct task_entry *task_list; least M objects, updating V and S as necessary. */ #define GROW_VECT(v, s, m) \ - if ((s) < (m)) grow_vect ((void**) &(v), &(s), (m), sizeof(*(v))); + if ((s) < (m)) (v) = grow_vect (v, &(s), m, sizeof *(v)); -extern void grow_vect (void **, size_t *, size_t, int); +extern void *grow_vect (void *, size_t *, size_t, int); extern int ada_get_field_index (const struct type *type, const char *field_name, -- Andreas Schwab, SuSE Labs, schwab@suse.de SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."