Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compared with null after type conversion using 'as' keyword #237

Closed
SviatoslavRazmyslov opened this issue Jan 2, 2016 · 0 comments
Closed

Comments

@SviatoslavRazmyslov
Copy link

V3019 Possibly an incorrect variable is compared to null after type conversion using 'as' keyword. Check variables 'value', 'valueExpression'. ExpressionMatcher.cs 62

public bool Matches(object value)
{
  var valueExpression = value as Expression;
  if (value == null) //<==
  {
    return false;
  }

  return ExpressionComparer.Default.Equals(this.expression, valueExpression);
}

It is most likely the object of the derived class that the programmer intended to check for null before using it. This is the fixed version of the code:

public bool Matches(object value)
{
  var valueExpression = value as Expression;
  if (valueExpression == null)
  {
    return false;
  }

  return ExpressionComparer.Default.Equals(this.expression, valueExpression);
}

This place is found by a static analyzer PVS-Studio.

stakx added a commit to stakx/moq that referenced this issue May 31, 2017
stakx added a commit to stakx/moq that referenced this issue May 31, 2017
stakx added a commit to stakx/moq that referenced this issue May 31, 2017
@stakx stakx closed this as completed Jun 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants