Skip to content

Wrong place for variable declaration  #2033

@Nordlicht123

Description

@Nordlicht123

Hi,
thank you for this great tool.

I've a problem with wrong variable declaration In the attached file.
The first part in the file is the IL code with C#, the second part is the ILAst and at the end is the C# Code of the faulty function.

In the C# part I've comment the faulty declaration, calculation and usage of the variable d, num5 and d2. I illustrated the problem in the simplified code inserted below. In the ILAst part the variable d, num5 and d2 are declared and inititalized with "0" outside the foreach loop. In the wrong C# code the calculation is done and will be cleared in the following loop. In the following "else if" block the variable d, num5 and d2 are always "0", the correct calculates values from the previous loop are lost.

I hope my description was helpful.

Yours
Stefan

foreach (DataPoint point in series.Points)
{
...
  decimal d = default(decimal);			<--- Clear d (wrong)
  decimal num5 = default(decimal);		<--- Clear num5 (wrong)
  decimal d2 = default(decimal);		<--- Clear d2 (wrong)
   if (num2 + GlobalForm.ChartStartIndex == num)
   {
	...
	d = new decimal((absolutePoint2.Y - absolutePoint.Y) / (absolutePoint2.X - absolutePoint.X));	<--- Calculation of d, not use in this block anymore
	num5 = new decimal((absolutePoint4.Y - absolutePoint3.Y) / (absolutePoint4.X - absolutePoint3.X));	<--- Calculation of num5, not use in this block anymore
	d2 = new decimal((absolutePoint2.X - absolutePoint.X) / (float)(num4 - num3));				<--- Calculation of d2, not use in this block anymore
	ShowTarget(e, series, i, num2 + 1);
   }
   else if (num2 + GlobalForm.ChartStartIndex > num)
   {
      decimal num6 = new decimal(Convert.ToSingle(decimal.Multiply(decimal.Multiply(d, new decimal(num2 + 1 - num3)), d2)) + absolutePoint.Y);    <--- Use of d, d2 calculate above
      decimal d3 = new decimal(Convert.ToSingle(decimal.Multiply(decimal.Multiply(num5, new decimal(num2 + 1 - num3)), d2)) + absolutePoint3.Y);  <--- Use of num5, d2 calculate above
...
  }
}

Wrong variable declaration.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions