From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 54380 invoked by alias); 26 Oct 2015 16:33:56 -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 54337 invoked by uid 89); 26 Oct 2015 16:33:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_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 (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 26 Oct 2015 16:33:55 +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 (Postfix) with ESMTPS id EDAF518B32A; Mon, 26 Oct 2015 16:33:53 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9QGXq0X031984; Mon, 26 Oct 2015 12:33:53 -0400 Message-ID: <562E55F0.9050203@redhat.com> Date: Mon, 26 Oct 2015 22:05:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Simon Marchi , gdb-patches Subject: Re: [PATCH] tui: Simplify tui_alloc_content References: <1442877416-16659-1-git-send-email-simon.marchi@ericsson.com> <562E34A0.6010802@ericsson.com> In-Reply-To: <562E34A0.6010802@ericsson.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2015-10/txt/msg00575.txt.bz2 On 10/26/2015 02:11 PM, Simon Marchi wrote: > 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. > OK with the return statement kept. Thanks, Pedro Alves