Fix null dereference in OFFSET macro
Applied same fix as done in 0e6a044
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/+/44508
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: James Price <jrprice@google.com>
This commit is contained in:
Родитель
98d2cab108
Коммит
45b25b229c
|
@ -201,7 +201,10 @@ inline constexpr float4 replicate(float 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
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче