From patchwork Mon May 19 20:19:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1015 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx20.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id 21407360098 for ; Mon, 19 May 2014 13:19:55 -0700 (PDT) Received: by homiemail-mx20.g.dreamhost.com (Postfix, from userid 14314964) id C5B1341C5BAE9; Mon, 19 May 2014 13:19:54 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx20.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx20.g.dreamhost.com (Postfix) with ESMTPS id 2F1FB41C5BAD1 for ; Mon, 19 May 2014 13:19:54 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id; q=dns; s= default; b=p7Aj90pcxy0DFVdXv5TLzK77u6Gg5QwJuZoru5xXQ4xvBoyYB7+0b HSLfHmnez241zow5gLc3f6vGNDajGFYEZKhtjjXIkECJjpyeypX8McL4wAJxnEMQ Lqukv/Paq9N2gJlkJu3Uk75rlPr8UrSd9mKL4hb8l4rFBSp5K96ZN4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id; s=default; bh=8jFsPX25dSDKEyMiZORA7Zs2tX4=; b=MQ6mnfRMbpkaQ8iTuMNIUKMbsRN+ Aaysylgw7yAdp+B7TqFp+1qvz3IM9UZgmbBQ19PSgqGhQQ+MpI2GB+AtchLsuGmv 5m7oSJJv79cdNHvErlgFDSCBJcspVmUOQOMJ58KjZHn3rkf43d9dyWlvfcX8bjSE utfTI2k/79kYwgE= Received: (qmail 7850 invoked by alias); 19 May 2014 20:19:52 -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 7835 invoked by uid 89); 19 May 2014 20:19:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 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; Mon, 19 May 2014 20:19:49 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4JKJmVT008827 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 19 May 2014 16:19:48 -0400 Received: from barimba.redhat.com (ovpn-113-182.phx2.redhat.com [10.3.113.182]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s4JKJmTI028524; Mon, 19 May 2014 16:19:48 -0400 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] fix two latent type errors Date: Mon, 19 May 2014 14:19:45 -0600 Message-Id: <1400530785-29263-1-git-send-email-tromey@redhat.com> X-DH-Original-To: gdb@patchwork.siddhesh.in I'm checking this in as obvious. I was looking at instances of "alloc.*sizeof" and noticed a couple where the types in question are incorrect. In gdbtypes, the code allocates sizeof(int) to represent a struct rank. In mi-cmds, the code uses "struct mi_cmd **" -- one "*" too many. In both cases the problems are latent because in practice the sizes are the same as the sizes of the correct types. Still, it's better to be correct. I think gdb would be improved by a wholesale change from explicit sizeofs to using the libiberty.h allocation macros. In most cases they are both shorter and have better type safety. However, the resulting patch is rather large. Built and regtested on x86-64 Fedora 20. 2014-05-19 Tom Tromey * gdbtypes.c (rank_function): Use XNEWVEC. * mi/mi-cmds.c (build_table): Use XCNEWVEC. --- gdb/ChangeLog | 5 +++++ gdb/gdbtypes.c | 2 +- gdb/mi/mi-cmds.c | 4 +--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 8e6631a..d58193e 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -2582,7 +2582,7 @@ rank_function (struct type **parms, int nparms, bv = xmalloc (sizeof (struct badness_vector)); bv->length = nargs + 1; /* add 1 for the length-match rank. */ - bv->rank = xmalloc ((nargs + 1) * sizeof (int)); + bv->rank = XNEWVEC (struct rank, nargs + 1); /* First compare the lengths of the supplied lists. If there is a mismatch, set it to a high value. */ diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c index 87a536f..68f97f6 100644 --- a/gdb/mi/mi-cmds.c +++ b/gdb/mi/mi-cmds.c @@ -247,10 +247,8 @@ build_table (struct mi_cmd *commands) int nr_rehash = 0; int nr_entries = 0; struct mi_cmd *command; - int sizeof_table = sizeof (struct mi_cmd **) * MI_TABLE_SIZE; - mi_table = xmalloc (sizeof_table); - memset (mi_table, 0, sizeof_table); + mi_table = XCNEWVEC (struct mi_cmd *, MI_TABLE_SIZE); for (command = commands; command->name != 0; command++) { struct mi_cmd **entry = lookup_table (command->name);