mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-09 22:56:27 +00:00
Add 'fsanitize=address,undefined' to tests and flatc targets (#5009)
* Add '-fsanitize' optional flags to flattests and flatc targets Control: -DFLATBUFFERS_CODE_SANITIZE=(ON | OFF | "=memory,undefined") Travis-CI: building with -DFLATBUFFERS_CODE_SANITIZE=ON * Fix -pie flag * Cleanup
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
bd20a60d6a
commit
0fb1d44bc4
@@ -195,6 +195,15 @@
|
||||
#endif
|
||||
#endif // !FLATBUFFERS_HAS_NEW_STRTOD
|
||||
|
||||
// Suppress sanitizer directives.
|
||||
#if defined(__clang__)
|
||||
#define __no_sanitize_undefined__(reason) __attribute__((no_sanitize("undefined")))
|
||||
#elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 408)
|
||||
#define __no_sanitize_undefined__(reason) __attribute__((no_sanitize_undefined))
|
||||
#else
|
||||
#define __no_sanitize_undefined__(reason)
|
||||
#endif
|
||||
|
||||
/// @endcond
|
||||
|
||||
/// @file
|
||||
@@ -277,11 +286,15 @@ template<typename T> T EndianScalar(T t) {
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T> T ReadScalar(const void *p) {
|
||||
template<typename T>
|
||||
__no_sanitize_undefined__("C++ aliasing type rules, see std::bit_cast<>")
|
||||
T ReadScalar(const void *p) {
|
||||
return EndianScalar(*reinterpret_cast<const T *>(p));
|
||||
}
|
||||
|
||||
template<typename T> void WriteScalar(void *p, T t) {
|
||||
template<typename T>
|
||||
__no_sanitize_undefined__("C++ aliasing type rules, see std::bit_cast<>")
|
||||
void WriteScalar(void *p, T t) {
|
||||
*reinterpret_cast<T *>(p) = EndianScalar(t);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user