bug-wget
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-wget] [PATCH 16/25] Bugfix: Remove surrounding quotes from Meta


From: Matthew White
Subject: Re: [Bug-wget] [PATCH 16/25] Bugfix: Remove surrounding quotes from Metalink/HTTP key's value
Date: Tue, 13 Sep 2016 09:13:01 +0200

On Sun, 11 Sep 2016 23:10:55 +0200
Giuseppe Scrivano <address@hidden> wrote:

> Matthew White <address@hidden> 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 <address@hidden>

Attachment: pgp4ighz1XkZ5.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]