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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ElenaTyuleneva
Copy link
Contributor

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 second chunk of the counter was overflowing, now introduced the high-level loop, which iterates through the other positions of the counter(3rd and 4th) 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.

// 0 1 2 3 overflow position
// 1 2 3 0 set-up counter position in engine
// 2 1 0 3 raw_counter_position
int raw_counter_position = (Engine::word_count - overflown_position - 2) % Engine::word_count;
Copy link
Contributor

Choose a reason for hiding this comment

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

please, check this line if Engine::word_count - overflown_position - 2 would overflow or is it expected?

also is -2 here only for Engine::word_count = 4?


// 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;

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