On Sun, 11 Sep 2016 23:10:55 +0200
Giuseppe Scrivano <[email protected]> wrote:

> Matthew White <[email protected]> writes:
> 
> > +/*
> > +  Remove the quotation surrounding a string.
> > +
> > +  The string is permanently modified.
> > + */
> > +void
> > +dequote_metalink_string (char **str)
> > +{
> > +  char *new, *beg, *end;
> > +  size_t str_len, new_len;
> > +
> > +  if (!str || !*str)
> > +    return;
> > +
> > +  str_len = strlen (*str); /* current string length */
> > +
> > +  if (str_len < 2)
> > +    return;
> > +
> > +  new_len = str_len - 2;   /* predict dequoted length */
> > +
> > +  beg = *str;                 /* begin of current string */
> > +  end = *str + (str_len - 1); /* end of current string */
> > +
> > +  /* Verify if the current string is surrounded by quotes.  */
> > +  if (!(*beg == '\"' && *end == '\"') && !(*beg == '\'' && *end == '\''))
> > +    return;
> 
> could we just verify that (*str[0] == '\"' || *str[0] == '\'') and in
> case return before computing the strlen?

Yes we can.

Fixed, see below. Posting after final decisions are taken about open topics in 
this series of patches.

void
dequote_metalink_string (char **str)
{
  char *new;
  size_t str_len;

  if (!str || !*str || ((*str)[0] != '\"' && (*str)[0] != '\''))
    return;

  str_len = strlen (*str); /* current string length */

  /* Verify if the current string is surrounded by quotes.  */
  if (str_len < 2 || (*str)[0] != (*str)[str_len - 1])
    return;

  /* Dequoted string.  */
  new = xmemdup0 (*str + 1, str_len - 2);
  xfree (*str);
  *str = new;
}

WDYT?

> 
> Giuseppe

Regards,
Matthew

-- 
Matthew White <[email protected]>

Attachment: pgpsS9o_aiOV3.pgp
Description: PGP signature

Reply via email to