-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
3
-
Storage - Ra 2022-05-16
In the cppsuite, we use our random_generator to generate numbers using the generate_integer function at different places. There are places where it might be dangerous and lead to unexpected behavior, see this example in the update_operation function of the database_operation class:
/* Choose a random key to update. */ uint64_t key_id = random_generator::instance().generate_integer<uint64_t>(0, coll.get_key_count() - 1);
The function get_key_count returns a uint64_t, if this one is 0, we end up choosing among the whole uint64_t range which is not what we expect.
The goal of this ticket is to check where we generate random numbers and make sure it is safe. Suggested changes would be something along those lines:
- random_generator::instance().generate_integer<uint64_t>(0, coll.get_key_count() - 1); + random_generator::instance().generate_integer<uint64_t>(0, coll.get_key_count() > 0 ? coll.get_key_count() - 1 : 0);