Commit 45b25b22 by James Price

Fix null dereference in OFFSET macro

Applied same fix as done in 0e6a044d for the same macro in src/Common/Types.hpp (including copying the comment verbatim). Change-Id: I822db18f19a5473d9cf56ab57339ae91e96f458e Bug: b/155089897 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/44508Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarJames Price <jrprice@google.com>
parent 98d2cab1
...@@ -201,7 +201,10 @@ inline constexpr float4 replicate(float f) ...@@ -201,7 +201,10 @@ inline constexpr float4 replicate(float f)
return vector(f, f, f, f); return vector(f, f, f, f);
} }
#define OFFSET(s, m) (int)(size_t) & reinterpret_cast<const volatile char &>((((s *)0)->m)) // The OFFSET macro is a generalization of the offsetof() macro defined in <cstddef>.
// It allows e.g. getting the offset of array elements, even when indexed dynamically.
// We cast the address '32' and subtract it again, because null-dereference is undefined behavior.
#define OFFSET(s, m) ((int)(size_t) & reinterpret_cast<const volatile char &>((((s *)32)->m)) - 32)
} // namespace sw } // namespace sw
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment