aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/RandomNumberGenerator.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-10-11 18:17:26 +0000
committerZachary Turner <zturner@google.com>2016-10-11 18:17:26 +0000
commit76e007e7e388ba700b3adc1551d88f1ba442a30f (patch)
tree6cf2a60bcf115d1d0b45214b9e6d1f9a7a66a85b /llvm/lib/Support/RandomNumberGenerator.cpp
parent78f3fa774bbc4a41f42f974b693e643b65fc4eb0 (diff)
downloadllvm-76e007e7e388ba700b3adc1551d88f1ba442a30f.zip
llvm-76e007e7e388ba700b3adc1551d88f1ba442a30f.tar.gz
llvm-76e007e7e388ba700b3adc1551d88f1ba442a30f.tar.bz2
[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. llvm-svn: 283912
Diffstat (limited to 'llvm/lib/Support/RandomNumberGenerator.cpp')
-rw-r--r--llvm/lib/Support/RandomNumberGenerator.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/llvm/lib/Support/RandomNumberGenerator.cpp b/llvm/lib/Support/RandomNumberGenerator.cpp
index d340764..8ea02d7 100644
--- a/llvm/lib/Support/RandomNumberGenerator.cpp
+++ b/llvm/lib/Support/RandomNumberGenerator.cpp
@@ -47,11 +47,11 @@ RandomNumberGenerator::RandomNumberGenerator(StringRef Salt) {
// are using a 64-bit RNG. This isn't a problem since the Mersenne
// twister constructor copies these correctly into its initial state.
std::vector<uint32_t> Data;
- Data.reserve(2 + Salt.size());
- Data.push_back(Seed);
- Data.push_back(Seed >> 32);
+ Data.resize(2 + Salt.size());
+ Data[0] = Seed;
+ Data[1] = Seed >> 32;
- std::copy(Salt.begin(), Salt.end(), Data.end());
+ std::copy(Salt.begin(), Salt.end(), Data.begin() + 2);
std::seed_seq SeedSeq(Data.begin(), Data.end());
Generator.seed(SeedSeq);