Hello! While running static analysis on the codebase, an unreachable code warning was flagged in Options.cs inside the GetArgumentName method.
In the following block, the variable j is initialized to 0 and is not modified before the while condition is evaluated:
int start, j = 0;
do {
start = description.IndexOf (nameStart [i], j);
} while (start >= 0 && j != 0 ? description [j++ - 1] == '{' : false);
Because j is exactly 0 at the end of the first iteration, the ternary operator j != 0 ? ... : false always evaluates to false. This means the loop guarantees to exit after the first iteration, making the check description [j++ - 1] == '{' completely unreachable dead code.
Since this code is quite old, we are unsure if the do-while loop was originally intended to perform a deeper search (and a variable increment is missing), or if the loop is simply redundant and can be safely replaced with a single IndexOf call.
Could you please take a look and advise if this needs a logic fix or just a cleanup?
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Hello! While running static analysis on the codebase, an unreachable code warning was flagged in
Options.csinside theGetArgumentNamemethod.In the following block, the variable
jis initialized to0and is not modified before thewhilecondition is evaluated:Because
jis exactly 0 at the end of the first iteration, the ternary operatorj != 0 ? ... : falsealways evaluates to false. This means the loop guarantees to exit after the first iteration, making the check description[j++ - 1] == '{'completely unreachable dead code.Since this code is quite old, we are unsure if the do-while loop was originally intended to perform a deeper search (and a variable increment is missing), or if the loop is simply redundant and can be safely replaced with a single
IndexOfcall.Could you please take a look and advise if this needs a logic fix or just a cleanup?
Found by Linux Verification Center (linuxtesting.org) with SVACE.