On Mon, Sep 26, 2011 at 10:52 AM, Abhijit Halder wrote: > On Sun, Sep 25, 2011 at 2:21 PM, Abhijit Halder > wrote: >> Hi, >> >> In the set remote exec-file command if we provide space at the end of >> the file-name the space is not being cleared. This behaviour is >> inconsistent across similar set commands like set logging file etc. My >> patch will fix that behaviour. Please review this patch. >> >> Further, I have found that there is a function in cli/cli-utils.c >> called remove_trailing_whitespace that never used. In many times we >> have removed trailing spaces and for that inline code is written. In >> my next patch I am planning to modify the remove_trailing_whitespace >> function and use it whenever possible in that. Since that patch will >> be relevant to current fix I am proposing, I have mentioned here that >> point. >> >> Thanks, >> Abhijit Halder >> > > Oops! A mistake. Correcting the same. > Index: gdb/cli/cli-setshow.c =================================================================== RCS file: /cvs/src/src/gdb/cli/cli-setshow.c,v retrieving revision 1.46 diff -a -p -u -r1.46 cli-setshow.c --- gdb/cli/cli-setshow.c 4 Aug 2011 19:10:13 -0000 1.46 +++ gdb/cli/cli-setshow.c 25 Sep 2011 08:28:52 -0000 @@ -181,6 +181,14 @@ do_setshow_command (char *arg, int from_ arg = ""; if (*(char **) c->var != NULL) xfree (*(char **) c->var); + { + /* Clear trailing whitespace of string. */ + char *ptr = arg + strlen (arg) - 1; + + while (ptr >= arg && (*ptr == ' ' || *ptr == '\t')) + ptr--; + *(ptr + 1) = '\0'; >>>>>>>>>>>>Here 'ptr' may point to a read-only memory when 'arg' is passed as NULL pointer. + } *(char **) c->var = xstrdup (arg); break; case var_optional_filename: This case contains same code block as the earlier case. We can fall through here from earlier case. @@ -188,6 +196,14 @@ do_setshow_command (char *arg, int from_ arg = ""; if (*(char **) c->var != NULL) xfree (*(char **) c->var); + { + /* Clear trailing whitespace of filename. */ + char *ptr = arg + strlen (arg) - 1; + + while (ptr >= arg && (*ptr == ' ' || *ptr == '\t')) + ptr--; + *(ptr + 1) = '\0'; + } *(char **) c->var = xstrdup (arg); break; case var_filename: I have made the corrections. Please ignore the earlier patch sent in hurry. Thanks, Abhijit Halder