Skip to content

Fix static analysis HRESULT / bool conversion warnings#54988

Merged
adityamandaleeka merged 1 commit intodotnet:mainfrom
GrabYourPitchforks:codeql_hresult
Apr 6, 2024
Merged

Fix static analysis HRESULT / bool conversion warnings#54988
adityamandaleeka merged 1 commit intodotnet:mainfrom
GrabYourPitchforks:codeql_hresult

Conversation

@GrabYourPitchforks
Copy link
Member

@GrabYourPitchforks GrabYourPitchforks commented Apr 6, 2024

The LOG_IF_FAILED macro takes an HRESULT input and returns an HRESULT. It shouldn't be used in an if statement to detect failure: use the FAILED_LOG macro instead. Additionally, it shouldn't be passed a BOOL: use the LOG_LAST_ERROR_IF macro instead (and invert the condition if needed).

This follows the pattern for other uses of the FAILED_LOG and LOG_LAST_ERROR_IF macros throughout the project. See e.g.:

if (FAILED_LOG(GetElementStringProperty(m_element, name.c_str(), &result.m_str)))
{
return std::nullopt;
}

LOG_LAST_ERROR_IF(!SetEvent(suspendedEventHandle));

Resolves two cpp/hresult-boolean-conversion CodeQL warnings we're seeing on our backend.

@ghost ghost added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Apr 6, 2024
@adityamandaleeka adityamandaleeka enabled auto-merge (squash) April 6, 2024 01:09
@adityamandaleeka adityamandaleeka merged commit bd18f56 into dotnet:main Apr 6, 2024
@dotnet-policy-service dotnet-policy-service bot added this to the 9.0-preview4 milestone Apr 6, 2024
@GrabYourPitchforks GrabYourPitchforks deleted the codeql_hresult branch April 6, 2024 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants