Example #1
0
        void calculateRate(int a, int b)
        {
            int ll = doSomething(); // Noncompliant; variable not used later

            int i, j;
            i = a + b;
            i += i + 2; // Noncompliant; variable is overwritten in the following statement
            i = 5;
            j = i;
            i = doSomething();  // Noncompliant; retrieved value overwritten in for loop
            for (i = 0; i < j + 10; i++)
            {
                //  ...
            }

            if ((i = doSomething()) == 5 ||
                (i = doSomethingElse()) == 5)   //special case, where i is overwritten in the same statement (if) many times. All of them is ignored
            {
                i += 5; // Noncompliant, last use of i, and we are not in a loop
            }

            var resource = new Resource(); // Noncompliant; retrieved value not used
            using (resource = new Resource())
            {
                resource.DoSomething();
            }
        }
Example #2
0
        void calculateRate(int a, int b)
        {
            int ll = doSomething(); // Noncompliant; variable not used later

            int i, j;
            i = a + b;
            i += i + 2; // Noncompliant; variable is overwritten in the following statement
            i = 5;
            j = i;
            i = doSomething();  // Noncompliant; retrieved value overwritten in for loop
            for (i = 0; i < j + 10; i++)
            {
                //  ...
            }

            if ((i = doSomething()) == 5 ||
                (i = doSomethingElse()) == 5)   //special case, where i is overwritten in the same statement (if) many times. All of them is ignored
            {
                i += 5; // Noncompliant, last use of i, and we are not in a loop
            }

            var resource = new Resource(); // Noncompliant; retrieved value not used
            using (resource = new Resource())
            {
                resource.DoSomething();
            }

            var x = 0; // Noncompliant;
            x = 1;
            try
            {
                x = 11;
                x = 12;
                Console.Write(x);
                x = 13;
            }
            catch (Exception)
            {
                x = 21; // Noncompliant
                x = 22;
                Console.Write(x);
                x = 23; // Non-compliant, but not recognized
            }
            x = 31; // Noncompliant
        }
Example #3
0
        void calculateRate(int a, int b)
        {
            b = doSomething(); // Noncompliant {{Remove this useless assignment to local variable "b".}}
//            ^^^^^^^^^^^^^^^

            int i, j;
            i = a + 12;
            i += i + 2; // Noncompliant
            i = 5;
            j = i;
            i
                = doSomething(); // Noncompliant; retrieved value overwritten in for loop
            for (i = 0; i < j + 10; i++)
            {
                //  ...
            }

            if ((i = doSomething()) == 5 ||
                (i = doSomethingElse()) == 5)
            {
                i += 5; // Noncompliant
            }

            var resource = new Resource(); // Noncompliant; retrieved value not used
            using (resource = new Resource())
            {
                resource.DoSomething();
            }

            var x
                = 10; // Noncompliant
            var y =
                x = 11; // Noncompliant
            Console.WriteLine(y);

            int k = 12; // Noncompliant
            X(out k);   // Compliant, not reporting on out parameters
        }