Skip to content

Conditional order of precedence (possible) bug in AxHost.CanAccessProperties #1989

@RussKie

Description

@RussKie
  • .NET Core Version: (e.g. 3.0 Preview1, or daily build number, use dotnet --info)
  • Have you experienced this same bug with .NET Framework?: Yes/No

Problem description:

Discovered as part of a review of #1955.
Having enabled SA1408 the analyser flagged the following issue:

        // NB: the snippet is re-formatted to increase readability

        internal override bool CanAccessProperties
        {
            get
            {
                int ocState = GetOcState();
                return axState[fOwnWindow] && (ocState > OC_RUNNING || (IsUserMode() && ocState >= OC_RUNNING)) || ocState >= OC_INPLACE;
            }
        }

internal override bool CanAccessProperties
{
get
{
int ocState = GetOcState();
return (axState[fOwnWindow] &&
(ocState > OC_RUNNING || (IsUserMode() && ocState >= OC_RUNNING)) ||
ocState >= OC_INPLACE);
}
}

Actual behavior:

The intent is unclear.

  • Is the following a correct expectation: ocState >= OC_INPLACE - OR - axState[fOwnWindow] && (ocState > OC_RUNNING || (IsUserMode() && ocState >= OC_RUNNING))?
  • In ocState > OC_RUNNING || (IsUserMode() && ocState >= OC_RUNNING) condition the second > is redundant, as if ocState > OC_RUNNING the condition will be true on the first operand

Expected behavior:

The code is written in a manner that clearly communicates the intent and a desired outcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    champion-requiredNeeds internal champion to shepherd issuecode cleanupcleanup code for unused apis/properties/comments - no functional changes.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions