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

Re: CVS update: subversion/subversion/libsvn_subr svn_error.h

From: Greg Stein <gstein_at_lyra.org>
Date: 2000-07-13 11:14:51 CEST

On Thu, Jul 13, 2000 at 12:05:59PM -0000, gstein@tigris.org wrote:
>...
> Modified: subversion/libsvn_subr svn_error.h
> Log:
> tweak the macros so they bind properly within an enclosing if/else construct
>...
> --- svn_error.h 2000/07/13 05:12:34 1.14
> +++ svn_error.h 2000/07/13 12:05:58 1.15
> @@ -62,10 +62,10 @@
>
> /* REALLY USEFUL macros for throwing errors quickly and easily! */
> #define SVN_RETURN_IF_ERROR(err) \
> -if (err) return (err)
> + if (err) return (err); else
>
> #define SVN_RETURN_WRAPPED_ERROR(err, msg) \
> -if (err) return (svn_quick_wrap_error((err),(msg)))
> + if (err) return (svn_quick_wrap_error((err),(msg))); else

These changes were made to prevent problems such as:

     if (whatever_test)
         SVN_RETURN_IF_ERROR(err);
     else
         do_something();

Without the extra "else" in the macro, then the "else" in the above code
would bind to the "if (err)" inside the macro. The expanded form now looks
like:

     if (whatever_test)
         if (err)
             return (err);
         else
             ; /* the semicolon after SVN_RETURN_IF_ERROR() */
     else
         do_something();

Of course, all this would be avoided by always using braces in if/else
blocks. But programmers tend to drop them if a single statement follows.
Better be on the safe side and fix the macro...

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/
Received on Sat Oct 21 14:36:05 2006

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.