Pex: Overflow Exception when int.MinValue % -1 and Strange Path Condition

时间:2015-07-31 19:40:13

标签: pex

I have some questions about the path condition for an input that causes overflow exception in a method. The input is for the PUT for that method and the input is generated by pex. Here is the code of the method:

public static int GreatestCommonDenominator(int first, int second)
{
      return second == 0 ? first : GreatestCommonDenominator(second, first % second);   //Exception
}

Here is the PUT

[PexMethod]
public int GreatestCommonDenominatorTest(int first, int second)
{
      int result = GreatestCommonDenominator(first, second);
      return result;
}

The input to the PUT is (first: -1, second: intMin). The exception is triggered in the recursive call. The value of the parameters for that recursive call is (first: intMin second:-1) and the exception is triggered when computing first % second. However, I wrote and executed a method in a separate c# project to print out int.MinValue % -1 and it didn't throw any exception and returned 0. Then in the that method, I created an int variable int b = int.MinValue and computed b % -1. After this modification, the overflow exception is thrown on b % -1. I'm confused about why this happens?

I obtained the patch condition by using PexSymbolicValue.GetPathConditionString(); and the path condition for the input (first: -1, second: intMin) is return first % int.MinValue == -1 && second == int.MinValue && first % second == -1; I have trouble understanding this path condition. Does the first and second in the path condition corresponds to the input to the PUT/first invocation of GreatestCommonDenominator? Also, it seems like some predicates in the path condition is redundant since first % int.MinValue == -1 && second == int.MinValue implies first % second == -1.

0 个答案:

没有答案
相关问题