This is a migrated thread and some comments may be shown as answers.

Decompile try/catch in condition is not correct

1 Answer 50 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 27 Jul 2011, 06:54 PM
Hi,

I came across some problems decompiling methods with try/catch blocks, I have narrowed it down to the following.

JustDecompile Version: 2011.1.719.9

Original Code:
public bool Test(bool test)
{
  if (test == true)
  {
    try
    {
      test = false;
    }
    catch
    {
    }
  }
  return test;
}

Decompiles to the following

public bool Test(bool test)
{
    if (test != 0)
    {
        test = 0;
    }
    try
    {
    }
    catch
    {
    }
    return test;
}

Here we see two problems

1. The bool argument test is not being tested against false, but against 0
2. The try/catch which wrap the assignment to test (again the type of test was not considered here) is outside of the conditional block.

If this helps, here is the IL as it is from ILDASM, but I confirmed and JD's IL is correct

.method public hidebysig instance bool  Test(bool test) cil managed
{
  // Code size       30 (0x1e)
  .maxstack  2
  .locals init ([0] bool CS$1$0000,
           [1] bool CS$4$0001)
  IL_0000:  nop
  IL_0001:  ldarg.1
  IL_0002:  ldc.i4.0
  IL_0003:  ceq
  IL_0005:  stloc.1
  IL_0006:  ldloc.1
  IL_0007:  brtrue.s   IL_0018
  IL_0009:  nop
  .try
  {
    IL_000a:  nop
    IL_000b:  ldc.i4.0
    IL_000c:  starg.s    test
    IL_000e:  nop
    IL_000f:  leave.s    IL_0016
  // end .try
  catch [mscorlib]System.Object
  {
    IL_0011:  pop
    IL_0012:  nop
    IL_0013:  nop
    IL_0014:  leave.s    IL_0016
  // end handler
  IL_0016:  nop
  IL_0017:  nop
  IL_0018:  ldarg.1
  IL_0019:  stloc.0
  IL_001a:  br.s       IL_001c
  IL_001c:  ldloc.0
  IL_001d:  ret
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Yordan Dikov
Telerik team
answered on 29 Jul 2011, 03:31 PM
Hello Chris,

 Thank you for the report. We are already aware of those problems and we'll definitely fix them. Please feel free to tell us about anything else you find or any features you might want to see.

Greetings,
Yordan Dikov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
General Discussions
Asked by
Chris
Top achievements
Rank 1
Answers by
Yordan Dikov
Telerik team
Share this question
or