From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 126057 invoked by alias); 26 Oct 2015 14:11:49 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 125962 invoked by uid 89); 26 Oct 2015 14:11:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.2 X-HELO: usevmg20.ericsson.net Received: from usevmg20.ericsson.net (HELO usevmg20.ericsson.net) (198.24.6.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 26 Oct 2015 14:11:47 +0000 Received: from EUSAAHC008.ericsson.se (Unknown_Domain [147.117.188.96]) by usevmg20.ericsson.net (Symantec Mail Security) with SMTP id 39.14.32596.6C3DD265; Mon, 26 Oct 2015 08:18:30 +0100 (CET) Received: from [142.133.110.144] (147.117.188.8) by smtp-am.internal.ericsson.com (147.117.188.98) with Microsoft SMTP Server id 14.3.248.2; Mon, 26 Oct 2015 10:11:44 -0400 Subject: Re: [PATCH] tui: Simplify tui_alloc_content To: gdb-patches References: <1442877416-16659-1-git-send-email-simon.marchi@ericsson.com> From: Simon Marchi Message-ID: <562E34A0.6010802@ericsson.com> Date: Mon, 26 Oct 2015 16:59:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <1442877416-16659-1-git-send-email-simon.marchi@ericsson.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg00566.txt.bz2 On 15-09-21 07:16 PM, Simon Marchi wrote: > I stumbled upon this while doing some cxx-conversion work. Since the > x-family alloc functions throw on failure, it is useless to test their > result for failure. The else branch of != NULL is basically dead code. > > I changed the type of element_block_ptr to struct tui_win_element, which > seems obvious (this is actually what raised the flag, casting the result > of xmalloc to struct tui_win_element* wouldn't work). > > gdb/ChangeLog: > > * tui/tui-data.c (tui_alloc_content): Don't check xmalloc > result. Change type of element_block_ptr. Change allocation to > use XNEWVEC. > --- > gdb/tui/tui-data.c | 41 ++++++++++++++--------------------------- > 1 file changed, 14 insertions(+), 27 deletions(-) > > diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c > index 2fcd547..ca7502d 100644 > --- a/gdb/tui/tui-data.c > +++ b/gdb/tui/tui-data.c > @@ -573,40 +573,27 @@ tui_win_content > tui_alloc_content (int num_elements, enum tui_win_type type) > { > tui_win_content content; > - char *element_block_ptr; > + struct tui_win_element *element_block_ptr; > int i; > > content = XNEWVEC (struct tui_win_element *, num_elements); > - if (content != NULL) > + > + /* > + * All windows, except the data window, can allocate the > + * elements in a chunk. The data window cannot because items > + * can be added/removed from the data display by the user at any > + * time. > + */ > + if (type != DATA_WIN) > { > - /* > - * All windows, except the data window, can allocate the > - * elements in a chunk. The data window cannot because items > - * can be added/removed from the data display by the user at any > - * time. > - */ > - if (type != DATA_WIN) > + element_block_ptr = XNEWVEC (struct tui_win_element, num_elements); > + for (i = 0; i < num_elements; i++) > { > - element_block_ptr = > - xmalloc (sizeof (struct tui_win_element) * num_elements); > - if (element_block_ptr != NULL) > - { > - for (i = 0; i < num_elements; i++) > - { > - content[i] = (struct tui_win_element *) element_block_ptr; > - init_content_element (content[i], type); > - element_block_ptr += sizeof (struct tui_win_element); > - } > - } > - else > - { > - xfree (content); > - content = (tui_win_content) NULL; > - } > + content[i] = element_block_ptr; > + init_content_element (content[i], type); > + element_block_ptr++; > } > } > - > - return content; > } Ping.