This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] (cli/cli-cmds.c) ARI fix: Avoid assignment inside if statement


Joel Brobecker <brobecker@adacore.com> writes:

>> Index: src/gdb/cli/cli-cmds.c
>> ===================================================================
>> RCS file: /cvs/src/src/gdb/cli/cli-cmds.c,v
>> retrieving revision 1.143
>> diff -u -p -r1.143 cli-cmds.c
>> --- src/gdb/cli/cli-cmds.c      18 Dec 2012 19:27:35 -0000      1.143
>> +++ src/gdb/cli/cli-cmds.c      20 Dec 2012 16:10:27 -0000
>> @@ -724,11 +724,13 @@ shell_escape (char *arg, int from_tty)
>>  #else /* Can fork.  */
>>    int status, pid;
>> 
>> -  if ((pid = vfork ()) == 0)
>> +  pid = vfork ();
>> +  if (pid == 0)
>>      {
>>        const char *p, *user_shell;
>> 
>> -      if ((user_shell = (char *) getenv ("SHELL")) == NULL)
>> +      user_shell = (char *) getenv ("SHELL");
>> +      if (user_shell == NULL)
>>         user_shell = "/bin/sh";
>> 
>>        /* Get the name of the shell for arg0.  */
>> @@ -837,7 +839,8 @@ edit_command (char *arg, int from_tty)
>>          error (_("No line number known for %s."), arg);
>>      }
>> 
>> -  if ((editor = (char *) getenv ("EDITOR")) == NULL)
>> +  editor = (char *) getenv ("EDITOR");
>
> According to POSIX, getenv returns char *, so I do not think
> that the cast is necessary. Let's try without and see what happens...

Even more so as editor should really be const char * (and user_shell
already is).

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]