[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: skip_uri_scheme question

From: Greg Hudson <ghudson_at_MIT.EDU>
Date: 2007-10-02 18:42:43 CEST

On Tue, 2007-10-02 at 07:00 -0700, Blair Zajac wrote:
> In this function:
>
> static const char *
> skip_uri_scheme(const char *path)
> {
> apr_size_t j;
>
> for (j = 0; path[j]; ++j)
> if (path[j] == ':' || path[j] == '/')
> break;
>
> if (j > 0 && path[j] == ':' && path[j+1] == '/' && path[j+2] == '/')
> return path + j + 3;
>
>
> Why do we check for a ':' and a '/' in the for loop to break out early but only
> return success if that first character is a ':' in the second if?

If the first loop terminates because we've reached the end of the
string, testing path[j+1] is a possible memory access error. (That may
or may not have already been clear to you; it's not clear from your
question which aspect of the function you're finding amiss.)

However, we could presumably test for just a ':' in the first loop,
perhaps using strchr() to knock off a few lines of code.

  const char *p;

  p = strchr(path, ':');
  return (p && p[1] == '/' && p[2] == '/') ? p + 3 : NULL;

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Oct 2 18:43:14 2007

This is an archived mail posted to the Subversion Dev mailing list.