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

[Coverity] Underflow error captured on concurrent_hash_map.h in coverity scan #1634

Open
ShinYanKokIntel opened this issue Feb 14, 2025 · 0 comments
Labels

Comments

@ShinYanKokIntel
Copy link

ShinYanKokIntel commented Feb 14, 2025

Summary

Underflow flagged in the Coverity scan due to variable type. However, it doesn't cause any functional issues or program failures.

Version

Example illustrated using v2021.2.5, but the issue should exists in all versions.

Environment

Environment set-up is not required.

Observed Behavior

The variable s is defined as segment_index_type Link, which is an alias for std::size_t Link, a long unsigned integer type.

The do-while loop executes for any initial value of s, and s reaches 0, underflow occurs. s will wrap around to its maximum representable value, ULONG_MAX.
However, since the loop condition is (s = 0 > 0), which evaluates to false, loop terminates. Therefore, despite the occurrence of underflow, the program's behavior should remain as expected.

Expected Behavior

Suggested modification:

void clear() {
  ...
  do {
    ...
  } while (s > 0 && s-- > 0);
  ...
}

Adding another condition check (s > 0) prior will prevent the execution of s-- when s is 0, but keeping the main loop executing for the case s is 0.

Steps To Reproduce

Compilation not required. Link to line

@ShinYanKokIntel ShinYanKokIntel changed the title Coverity issue captured on concurrent_hash_map.h [Coverity] Underflow error captured on concurrent_hash_map.h in coverity scan Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant