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

Fixed coverity issue in Philox RNG engine #1905

Merged
merged 7 commits into from
Oct 22, 2024

Conversation

ElenaTyuleneva
Copy link
Contributor

@ElenaTyuleneva ElenaTyuleneva commented Oct 15, 2024

What introduces this PR:

  1. Fix for the incorrect counter incrementing in case w is not the recommended value (w!=32 and w!=64)
  2. discard_overflow_test was extended: previously only the first chunk of the counter was overflowing, now introduced the high-level loop, which iterates through the other positions of the counter(2nd and 3rd) and also checks for the overflow.
  3. Introduced a new unit test - counter_management_test.
    • The testing is based on comparing the work of two different methods of the engine - simple set_counter and more complicated increase_counter_internal(unsigned long long __z) which is called by discard
    • The test discards the engine by the increment which takes at least 2 chunks of the counter type(2*w) - this way increase_counter_internal will take __z that should be placed properly in the 1st chunk and propagated to the 2nd one. The right calculations are checked by referenceEngine which is based on simpler set_counter function.


// set the counter which value is 2-chunk bitsize
unsigned long long increment = ((unsigned long long)testedEngine.max() << Engine::word_size) | testedEngine.max();
unsigned long long counter_increment = increment / 4;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsigned long long counter_increment = increment / 4;
unsigned long long counter_increment = increment / Engine::word_count;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that! Fixed + all unit tests are also extended for Philox 2x*(except for set_counter_conformance_test as it expects 1955073260 and 3409172418970261260 numbers to be generated as 10000th)

* Other unit tests were extended to check Philox with word_count=2 as well
@ElenaTyuleneva ElenaTyuleneva marked this pull request as ready for review October 21, 2024 15:28
Copy link
Contributor

@aelizaro aelizaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you!

@ElenaTyuleneva ElenaTyuleneva merged commit deaff18 into main Oct 22, 2024
22 checks passed
@ElenaTyuleneva ElenaTyuleneva deleted the dev/etyulene/coverity_fix branch October 22, 2024 14:13
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 this pull request may close these issues.

2 participants