llvm.org GIT mirror llvm / be78316
[Support] Fix undefined behavior in RandomNumberGenerator. This has existed pretty much forever AFAICT, but the code was never being exercised because nobody was using the class. A user of this class surfaced, and now we're breaking with UB. The code was obviously wrong, so it's fixed here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283912 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 4 years ago
1 changed file(s) with 4 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
4646 // are using a 64-bit RNG. This isn't a problem since the Mersenne
4747 // twister constructor copies these correctly into its initial state.
4848 std::vector Data;
49 Data.reserve(2 + Salt.size());
50 Data.push_back(Seed);
51 Data.push_back(Seed >> 32);
49 Data.resize(2 + Salt.size());
50 Data[0] = Seed;
51 Data[1] = Seed >> 32;
5252
53 std::copy(Salt.begin(), Salt.end(), Data.end());
53 std::copy(Salt.begin(), Salt.end(), Data.begin() + 2);
5454
5555 std::seed_seq SeedSeq(Data.begin(), Data.end());
5656 Generator.seed(SeedSeq);