This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] tui: Simplify tui_alloc_content
- From: Andrew Burgess <andrew dot burgess at embecosm dot com>
- To: Simon Marchi <simon dot marchi at ericsson dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Tue, 22 Sep 2015 08:50:33 +0100
- Subject: Re: [PATCH] tui: Simplify tui_alloc_content
- Authentication-results: sourceware.org; auth=none
- References: <1442877416-16659-1-git-send-email-simon dot marchi at ericsson dot com>
* Simon Marchi <simon.marchi@ericsson.com> [2015-09-21 19:16:56 -0400]:
>
> 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;
> }
Doesn't that leave the function without a return?
Thanks,
Andrew