mirror of
https://github.com/xmrig/xmrig.git
synced 2024-10-30 04:57:39 +00:00
RandomX: fixed undefined behavior
Using an inactive member of a `union` is an undefined behavior in C++
This commit is contained in:
parent
5891f1f06b
commit
1252a4710e
1 changed files with 4 additions and 11 deletions
|
@ -167,16 +167,8 @@ void fillAes1Rx4(void *state, size_t outputSize, void *buffer) {
|
||||||
template void fillAes1Rx4<true>(void *state, size_t outputSize, void *buffer);
|
template void fillAes1Rx4<true>(void *state, size_t outputSize, void *buffer);
|
||||||
template void fillAes1Rx4<false>(void *state, size_t outputSize, void *buffer);
|
template void fillAes1Rx4<false>(void *state, size_t outputSize, void *buffer);
|
||||||
|
|
||||||
static const rx_vec_i128 inst_mask = []() {
|
static constexpr randomx::Instruction inst{ 0xFF, 7, 7, 0xFF, 0xFFFFFFFFU };
|
||||||
constexpr randomx::Instruction inst{ 0xFF, randomx::RegistersCount - 1, randomx::RegistersCount - 1, 0xFF, 0xFFFFFFFFU };
|
alignas(16) static const randomx::Instruction inst_mask[2] = { inst, inst };
|
||||||
|
|
||||||
union {
|
|
||||||
randomx::Instruction mask[2];
|
|
||||||
rx_vec_i128 vec;
|
|
||||||
} result = { inst, inst };
|
|
||||||
|
|
||||||
return result.vec;
|
|
||||||
}();
|
|
||||||
|
|
||||||
template<int softAes>
|
template<int softAes>
|
||||||
void fillAes4Rx4(void *state, size_t outputSize, void *buffer) {
|
void fillAes4Rx4(void *state, size_t outputSize, void *buffer) {
|
||||||
|
@ -227,7 +219,8 @@ void fillAes4Rx4(void *state, size_t outputSize, void *buffer) {
|
||||||
rx_store_vec_i128((rx_vec_i128*)outptr + 3, state3);
|
rx_store_vec_i128((rx_vec_i128*)outptr + 3, state3);
|
||||||
}
|
}
|
||||||
|
|
||||||
const rx_vec_i128 mask = inst_mask;
|
static_assert(sizeof(inst_mask) == sizeof(rx_vec_i128), "Incorrect inst_mask size");
|
||||||
|
const rx_vec_i128 mask = *reinterpret_cast<const rx_vec_i128*>(inst_mask);
|
||||||
|
|
||||||
while (outptr < outputEnd) {
|
while (outptr < outputEnd) {
|
||||||
TRANSFORM;
|
TRANSFORM;
|
||||||
|
|
Loading…
Reference in a new issue