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

Re: [tortoisesvn] r20596 committed - I can't see why, but adding brackets around the content of the if clau...

From: Lübbe Onken <luebbe.tortoisesvn_at_googlemail.com>
Date: Wed, 15 Dec 2010 09:50:47 +0100

Stefan wrote:

2010/12/12 Simon Large <simon.tortoisesvn_at_gmail.com>

> On 11 December 2010 15:04, <tortoisesvn_at_googlecode.com> wrote:
> > Revision: 20596
> > Author: tortoisesvn
> > Date: Sat Dec 11 07:04:12 2010
> > Log: I can't see why, but adding brackets around the content of the if
> > clause makes this work. Without them, the else path is never called.
> Maybe
> > I just can't see why, or this is in fact a bug in the compiler.
> > http://code.google.com/p/tortoisesvn/source/detail?r=20596
> >
> > Modified:
> > /trunk/src/Utils/TempFile.cpp
> >
> > =======================================
> > --- /trunk/src/Utils/TempFile.cpp Thu Nov 25 11:40:09 2010
> > +++ /trunk/src/Utils/TempFile.cpp Sat Dec 11 07:04:12 2010
> > @@ -99,8 +99,10 @@
> > {
> > DeleteFile(tempfile.GetWinPath());
> > if (CreateDirectory (tempfile.GetWinPath(), NULL) == FALSE)
> > + {
> > if (GetLastError() != ERROR_ALREADY_EXISTS)
> > return CTSVNPath();
> > + }
> > else
> > succeeded = true;
> > }
>
> It's known as the 'dangling else' problem. 'else' always attaches to
> the last 'if' unless there are braces to disambiguate, so the original
> expression looked like:
>
> if (CreateDirectory (tempfile.GetWinPath(), NULL) == FALSE)
> {
> if (GetLastError() != ERROR_ALREADY_EXISTS)
> {
> return CTSVNPath();
> }
> else
> {
> succeeded = true;
> }
> }
>
> Simon
>
> --
> : ___
> : oo // \\ "De Chelonian Mobile"
> : (_,\/ \_/ \ TortoiseSVN
> : \ \_/_\_/> The coolest Interface to (Sub)Version Control
> : /_/ \_\ http://tortoisesvn.net
>
> ------------------------------------------------------
>
> http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=757&dsMessageId=2690080
>
> To unsubscribe from this discussion, e-mail: [
> dev-unsubscribe_at_tortoisesvn.tigris.org].
>

That's why I always use automatic code formatters inside my IDE. A code
formatter would have indented the first statement like this:

if (CreateDirectory (tempfile.GetWinPath(), NULL) == FALSE)
    if (GetLastError() != ERROR_ALREADY_EXISTS)
        return CTSVNPath();
    else
        succeeded = true;

and you would have spotted the problem immediately. I actually use the code
formatter much more than the compiler :D

Cheers
- Lübbe

--
Please help me get more space on Dropbox :)
https://www.dropbox.com/referrals/NTIwMzcxNjI5
       ___
  oo  // \\      "De Chelonian Mobile"
 (_,\/ \_/ \     TortoiseSVN
   \ \_/_\_/>    The coolest Interface to (Sub)Version Control
   /_/   \_\     http://tortoisesvn.net  PGP Key ID 0x23F511AB
------------------------------------------------------
http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=757&dsMessageId=2690840
To unsubscribe from this discussion, e-mail: [dev-unsubscribe_at_tortoisesvn.tigris.org].
Received on 2010-12-15 09:50:54 CET

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