[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: Simon Large <simon.tortoisesvn_at_gmail.com>
Date: Sun, 12 Dec 2010 09:53:59 +0000

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].
Received on 2010-12-12 10:54:09 CET

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