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

Invalid random level in skip list with custom random level generator (the one than can return more than c_nMaxHeight) #137

Open
kazachkovaanna opened this issue Feb 4, 2019 · 0 comments

Comments

@kazachkovaanna
Copy link

unsigned int random_level()
{
// Random generator produces a number from range [0..31]
// We need a number from range [1..32]
return m_RandomLevelGen() + 1;
}

static unsigned int const c_nMaxHeight = std::conditional<
(random_level_generator::c_nUpperBound <= skip_list::c_nHeightLimit),
std::integral_constant< unsigned int, random_level_generator::c_nUpperBound >,
std::integral_constant< unsigned int, skip_list::c_nHeightLimit >
>::type::value;

Inside conditional minimum value is choosen, and in random_level max is bounded with 32. But, array index will be initialized with greater number from conditional. So it is possible to have array of 32 elements and index 99.
Possible resolution is to add assert or use min value from conditional for index

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

No branches or pull requests

1 participant