[v2,02/31] cli/cli-script.c: Remove some dead NULL checks
Commit Message
gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
* cli/cli-script.c (execute_control_command): Assume insert_args
never returns NULL.
(insert_args): Assume xmalloc never returns NULL.
---
gdb/cli/cli-script.c | 10 ----------
1 file changed, 10 deletions(-)
Comments
On 2016-10-18 21:11, Pedro Alves wrote:
> @@ -853,8 +845,6 @@ insert_args (char *line)
>
> /* Allocate space for the new line and fill it in. */
> new_line = (char *) xmalloc (len + 1);
> - if (new_line == NULL)
> - return NULL;
>
> /* Restore pointer to beginning of old line. */
> line = save_line;
A few lines higher in insert_args, there is:
error (_("Missing argument %d in user function."), i);
return NULL;
That return NULL is also dead code and could be confusing, leading
someone to think insert_args can return NULL. I think you could remove
it at the same time.
On 10/19/2016 06:24 PM, Simon Marchi wrote:
> On 2016-10-18 21:11, Pedro Alves wrote:
>> @@ -853,8 +845,6 @@ insert_args (char *line)
>>
>> /* Allocate space for the new line and fill it in. */
>> new_line = (char *) xmalloc (len + 1);
>> - if (new_line == NULL)
>> - return NULL;
>>
>> /* Restore pointer to beginning of old line. */
>> line = save_line;
>
> A few lines higher in insert_args, there is:
>
> error (_("Missing argument %d in user function."), i);
> return NULL;
>
> That return NULL is also dead code and could be confusing, leading
> someone to think insert_args can return NULL. I think you could remove
> it at the same time.
Ah. Guess I missed it because that code disappears with patch
(patch #4). I wrote patches #2-#4 as a single patch, and
then missed that when I split them to ease review... :-)
I've changed this locally.
Thanks,
Pedro Alves
@@ -459,8 +459,6 @@ execute_control_command (struct command_line *cmd)
case simple_control:
/* A simple command, execute it and return. */
new_line = insert_args (cmd->line);
- if (!new_line)
- break;
make_cleanup (free_current_contents, &new_line);
execute_command (new_line, 0);
ret = cmd->control_type;
@@ -492,8 +490,6 @@ execute_control_command (struct command_line *cmd)
/* Parse the loop control expression for the while statement. */
new_line = insert_args (cmd->line);
- if (!new_line)
- break;
make_cleanup (free_current_contents, &new_line);
expr = parse_expression (new_line);
make_cleanup (free_current_contents, &expr);
@@ -560,8 +556,6 @@ execute_control_command (struct command_line *cmd)
print_command_trace (buffer);
new_line = insert_args (cmd->line);
- if (!new_line)
- break;
make_cleanup (free_current_contents, &new_line);
/* Parse the conditional for the if statement. */
expr = parse_expression (new_line);
@@ -605,8 +599,6 @@ execute_control_command (struct command_line *cmd)
/* Breakpoint commands list, record the commands in the
breakpoint's command list and return. */
new_line = insert_args (cmd->line);
- if (!new_line)
- break;
make_cleanup (free_current_contents, &new_line);
ret = commands_from_control_command (new_line, cmd);
break;
@@ -853,8 +845,6 @@ insert_args (char *line)
/* Allocate space for the new line and fill it in. */
new_line = (char *) xmalloc (len + 1);
- if (new_line == NULL)
- return NULL;
/* Restore pointer to beginning of old line. */
line = save_line;