From 5f6a35c960da4174670640fc9a805186968694df Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 21 Sep 2019 23:35:24 -0700 Subject: 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. --- alc/effects/reverb.cpp | 9 ++++++--- 1 file 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 *Line{nullptr}; + union { + uintptr_t LineOffset{0u}; + std::array *Line; + }; /* Given the allocated sample buffer, this function updates each delay line * offset. */ void realizeLineOffset(std::array *sampleBuffer) noexcept - { Line = &sampleBuffer[reinterpret_cast(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*>(offset); + LineOffset = offset; /* Return the sample count for accumulation. */ return samples; -- cgit v1.2.3