You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Sander Striker <st...@apache.org> on 2002/08/30 08:34:05 UTC

RE: svn commit: rev 3103 - trunk/subversion/include trunk/subversion/libsvn_wc trunk/subversion/libsvn_subr trunk/subversion/mod_dav_svn trunk/subversion/clients/cmdline

> From: kfogel@tigris.org [mailto:kfogel@tigris.org]
> Sent: 30 August 2002 08:51

> Author: kfogel
> Date: 2002-08-30 01:51:15 -0500 (Fri, 30 Aug 2002)
> New Revision: 3103

[...]
> Modified: trunk/subversion/libsvn_subr/validate.c
> ==============================================================================
> --- trunk/subversion/libsvn_subr/validate.c	(original)
> +++ trunk/subversion/libsvn_subr/validate.c	Fri Aug 30 01:51:19 2002

> @@ -59,6 +59,17 @@
>    }
>  
>    return SVN_NO_ERROR;
> +}
> +
> +
> +svn_boolean_t
> +svn_mime_type_is_binary (const char *mime_type)
> +{
> +  return (! (   (mime_type[0] == 't')
> +             && (mime_type[1] == 'e')
> +             && (mime_type[2] == 'x')
> +             && (mime_type[3] == 't')
> +             && (mime_type[4] == '/')));
>  }

Why not use strncmp?  And, is mime_type guaranteed to have at least
5 characters?


Sander


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: svn commit: rev 3103 - trunk/subversion/include trunk/subversion/libsvn_wc trunk/subversion/libsvn_subr trunk/subversion/mod_dav_svn trunk/subversion/clients/cmdline

Posted by Greg Stein <gs...@lyra.org>.
On Sat, Aug 31, 2002 at 01:30:46PM -0400, Greg Hudson wrote:
> On Fri, 2002-08-30 at 04:34, Sander Striker wrote:
> > Why not use strncmp?
> 
> Since the last answer fizzled, I'll try: because we have too much
> cycle-counting mentality in this project.

Yah :-)  But I also don't find it to be a problem.

IMO, our performance will mostly be bound by the I/O that we do (thus we
want to minimize the operation count), and by the overall system impact of
the working set size (i.e. we need to reduce our mem footprint).

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

RE: svn commit: rev 3103 - trunk/subversion/include trunk/subversion/libsvn_wc trunk/subversion/libsvn_subr trunk/subversion/mod_dav_svn trunk/subversion/clients/cmdline

Posted by Greg Hudson <gh...@MIT.EDU>.
On Fri, 2002-08-30 at 04:34, Sander Striker wrote:
> Why not use strncmp?

Since the last answer fizzled, I'll try: because we have too much
cycle-counting mentality in this project.

Admittedly, strncmp() has the problem that you can get bugs like:

  strncmp(mime_type[0], "text/", 6)

which are hard to see.  (There are disciplines which prevent such bugs,
but they're ugly as hell.)  I've never found it to be a real problem,
though.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: svn commit: rev 3103 - trunk/subversion/include trunk/subversion/libsvn_wc trunk/subversion/libsvn_subr trunk/subversion/mod_dav_svn trunk/subversion/clients/cmdline

Posted by Joe Orton <jo...@manyfish.co.uk>.
On Fri, Aug 30, 2002 at 03:01:13PM +0200, brane@xbc.nu wrote:
> > > +{
> > > +  return (! (   (mime_type[0] == 't')
> > > +             && (mime_type[1] == 'e')
> > > +             && (mime_type[2] == 'x')
> > > +             && (mime_type[3] == 't')
> > > +             && (mime_type[4] == '/')));
> > >  }
> > 
> > Why not use strncmp?  And, is mime_type guaranteed to have at least
> > 5 characters?
> 
> If you use strncmp, you have to check the length first, because the mime type
> _could_ be shorter than 5 chars.

Why must you check the length first? strncmp won't overrun a NUL, it's
defined to compare "at most N" not "exactly N" bytes.

joe


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: svn commit: rev 3103 - trunk/subversion/include trunk/subversion/libsvn_wc trunk/subversion/libsvn_subr trunk/subversion/mod_dav_svn trunk/subversion/clients/cmdline

Posted by Greg Stein <gs...@lyra.org>.
On Fri, Aug 30, 2002 at 03:01:13PM +0200, brane@xbc.nu wrote:
> Quoting Sander Striker <st...@apache.org>:
>...
> > > +svn_boolean_t
> > > +svn_mime_type_is_binary (const char *mime_type)
> > > +{
> > > +  return (! (   (mime_type[0] == 't')
> > > +             && (mime_type[1] == 'e')
> > > +             && (mime_type[2] == 'x')
> > > +             && (mime_type[3] == 't')
> > > +             && (mime_type[4] == '/')));
> > >  }
> > 
> > Why not use strncmp?  And, is mime_type guaranteed to have at least
> > 5 characters?
> 
> If you use strncmp, you have to check the length first, because the mime type
> _could_ be shorter than 5 chars. In this case, you can't miss because the first
> unexpected char (e.g., a null) will short-circuit out of the condition.
> 
> But you know that, it's just that your vacation was too long. :-)

Just to beat a dead horse... you would not have to check the length first.
strncmp() stops as soon as it hits a NUL character. You're probably thinking
of memcmp() which *would* require a length check.

But yes: Karl's test is entirely valid cuz it just stops once it hits a NUL,
so there is no potential for overrun.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

RE: svn commit: rev 3103 - trunk/subversion/include trunk/subversion/libsvn_wc trunk/subversion/libsvn_subr trunk/subversion/mod_dav_svn trunk/subversion/clients/cmdline

Posted by Sander Striker <st...@apache.org>.
> From: brane@xbc.nu [mailto:brane@xbc.nu]
> Sent: 30 August 2002 15:01

> Quoting Sander Striker <st...@apache.org>:
>> Why not use strncmp?  And, is mime_type guaranteed to have at least
>> 5 characters?
> 
> If you use strncmp, you have to check the length first, because the mime type
> _could_ be shorter than 5 chars. In this case, you can't miss because the first
> unexpected char (e.g., a null) will short-circuit out of the condition.
> 
> But you know that, it's just that your vacation was too long. :-)

Doh! :-P

Sander


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

RE: svn commit: rev 3103 - trunk/subversion/include trunk/subversion/libsvn_wc trunk/subversion/libsvn_subr trunk/subversion/mod_dav_svn trunk/subversion/clients/cmdline

Posted by br...@xbc.nu.
Quoting Sander Striker <st...@apache.org>:

> > From: kfogel@tigris.org [mailto:kfogel@tigris.org]
> > Sent: 30 August 2002 08:51
> 
> > Author: kfogel
> > Date: 2002-08-30 01:51:15 -0500 (Fri, 30 Aug 2002)
> > New Revision: 3103
> 
> [...]
> > Modified: trunk/subversion/libsvn_subr/validate.c
> >
> ==============================================================================
> > --- trunk/subversion/libsvn_subr/validate.c	(original)
> > +++ trunk/subversion/libsvn_subr/validate.c	Fri Aug 30 01:51:19 2002
> 
> > @@ -59,6 +59,17 @@
> >    }
> >  
> >    return SVN_NO_ERROR;
> > +}
> > +
> > +
> > +svn_boolean_t
> > +svn_mime_type_is_binary (const char *mime_type)
> > +{
> > +  return (! (   (mime_type[0] == 't')
> > +             && (mime_type[1] == 'e')
> > +             && (mime_type[2] == 'x')
> > +             && (mime_type[3] == 't')
> > +             && (mime_type[4] == '/')));
> >  }
> 
> Why not use strncmp?  And, is mime_type guaranteed to have at least
> 5 characters?

If you use strncmp, you have to check the length first, because the mime type
_could_ be shorter than 5 chars. In this case, you can't miss because the first
unexpected char (e.g., a null) will short-circuit out of the condition.

But you know that, it's just that your vacation was too long. :-)


    Brane

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org