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

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: Greg Stein <gstein_at_lyra.org>
Date: 2002-08-30 23:32:12 CEST

On Fri, Aug 30, 2002 at 03:01:13PM +0200, brane@xbc.nu wrote:
> Quoting Sander Striker <striker@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
Received on Fri Aug 30 23:27:48 2002

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

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.