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] Constify find_condition_and_thread


On 03/01/2013 06:18 PM, Keith Seitz wrote:
>        else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
>  	{
> -	  char *tmptok;
> +	  char *tmptok, *copy;
>  
>  	  tok = end_tok + 1;
> -	  tmptok = tok;
> -	  *task = strtol (tok, &tok, 0);
> -	  if (tok == tmptok)
> -	    error (_("Junk after task keyword."));
> +	  tmptok = copy = xstrdup (tok);
> +	  *task = strtol (copy, &copy, 0);
> +	  if (copy == tmptok)
> +	    {
> +	      xfree (tmptok);
> +	      error (_("Junk after task keyword."));
> +	    }

Why do we really need the xstrdups in this and the "task" cases?

> +const char *
> +skip_to_space_const (const char *chp)
> +{
> +  if (chp == NULL)
> +    return NULL;
> +  while (*chp && !isspace (*chp))
> +    chp++;
> +  return chp;
> +}

Note we in addition redo skip_to_space as:

char *
skip_to_space (char *chp)
{
  return (char *) skip_to_space_const (chp);
}

(or make that an inline function / #define)
-- 
Pedro Alves


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