From patchwork Fri Jun 13 19:10:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1497 Received: (qmail 32323 invoked by alias); 13 Jun 2014 19:10:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 32314 invoked by uid 89); 13 Jun 2014 19:10:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Jun 2014 19:10:40 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5DJAdxv006890 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 13 Jun 2014 15:10:39 -0400 Received: from barimba.redhat.com (ovpn-113-103.phx2.redhat.com [10.3.113.103]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5DJAcgb006054; Fri, 13 Jun 2014 15:10:39 -0400 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] make obstack object allocators more type-safe Date: Fri, 13 Jun 2014 13:10:33 -0600 Message-Id: <1402686633-7872-1-git-send-email-tromey@redhat.com> This changes OBSTACK_ZALLOC and OBSTACK_CALLOC to cast their value to the correct type. This is more type-safe and also is more in line with the other object-allocation macros in libiberty.h. Making this change revealed one trivial error in dwarf2read.c. On the whole that seems pretty good to me. Tested by rebuilding. 2014-06-13 Tom Tromey * dwarf2read.c (dw2_get_real_path): Use correct type in OBSTACK_CALLOC. * gdb_obstack.h (OBSTACK_ZALLOC, OBSTACK_CALLOC): Cast result. --- gdb/ChangeLog | 6 ++++++ gdb/dwarf2read.c | 2 +- gdb/gdb_obstack.h | 6 +++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 3e441dc..591eed7 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -3297,7 +3297,7 @@ dw2_get_real_path (struct objfile *objfile, { if (qfn->real_names == NULL) qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, - qfn->num_file_names, char *); + qfn->num_file_names, const char *); if (qfn->real_names[index] == NULL) qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); diff --git a/gdb/gdb_obstack.h b/gdb/gdb_obstack.h index 0b39400..ec2dd97 100644 --- a/gdb/gdb_obstack.h +++ b/gdb/gdb_obstack.h @@ -25,11 +25,11 @@ /* Utility macros - wrap obstack alloc into something more robust. */ #define OBSTACK_ZALLOC(OBSTACK,TYPE) \ - (memset (obstack_alloc ((OBSTACK), sizeof (TYPE)), 0, sizeof (TYPE))) + ((TYPE *) memset (obstack_alloc ((OBSTACK), sizeof (TYPE)), 0, sizeof (TYPE))) #define OBSTACK_CALLOC(OBSTACK,NUMBER,TYPE) \ - (memset (obstack_alloc ((OBSTACK), (NUMBER) * sizeof (TYPE)), \ - 0, (NUMBER) * sizeof (TYPE))) + ((TYPE *) memset (obstack_alloc ((OBSTACK), (NUMBER) * sizeof (TYPE)), \ + 0, (NUMBER) * sizeof (TYPE))) /* Unless explicitly specified, GDB obstacks always use xmalloc() and xfree(). */