aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-09-21 23:35:24 -0700
committerChris Robinson <[email protected]>2019-09-21 23:35:24 -0700
commit5f6a35c960da4174670640fc9a805186968694df (patch)
treeed5b5e7dfd5e33a85990c644c2e551dd8cd2fbc9
parent9325f1d507e20b90b799217a9faa7ed9d55b0be7 (diff)
Avoid storing an integer in a pointer
C++ does not guarantee that, given an int of sufficient size, converting int->ptr->int will result in the original value. A pointer may have more than one integer representation. Only ptr->int->ptr round trips are well-defined.
-rw-r--r--alc/effects/reverb.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp
index 4a85f640..6e56adf2 100644
--- a/alc/effects/reverb.cpp
+++ b/alc/effects/reverb.cpp
@@ -220,13 +220,16 @@ struct DelayLineI {
* of 2 to allow the use of bit-masking instead of a modulus for wrapping.
*/
size_t Mask{0u};
- std::array<float,NUM_LINES> *Line{nullptr};
+ union {
+ uintptr_t LineOffset{0u};
+ std::array<float,NUM_LINES> *Line;
+ };
/* Given the allocated sample buffer, this function updates each delay line
* offset.
*/
void realizeLineOffset(std::array<float,NUM_LINES> *sampleBuffer) noexcept
- { Line = &sampleBuffer[reinterpret_cast<ptrdiff_t>(Line)]; }
+ { Line = sampleBuffer + LineOffset; }
/* Calculate the length of a delay line and store its mask and offset. */
ALuint calcLineLength(const ALfloat length, const uintptr_t offset, const ALfloat frequency,
@@ -240,7 +243,7 @@ struct DelayLineI {
/* All lines share a single sample buffer. */
Mask = samples - 1;
- Line = reinterpret_cast<std::array<float,NUM_LINES>*>(offset);
+ LineOffset = offset;
/* Return the sample count for accumulation. */
return samples;