mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-22 07:28:28 +00:00
rename __suppress_ubsan to FLATBUFFERS_SUPPRESS_UBSAN
This commit is contained in:
@@ -279,14 +279,14 @@ namespace flatbuffers {
|
|||||||
#endif // !FLATBUFFERS_LOCALE_INDEPENDENT
|
#endif // !FLATBUFFERS_LOCALE_INDEPENDENT
|
||||||
|
|
||||||
// Suppress Undefined Behavior Sanitizer (recoverable only). Usage:
|
// Suppress Undefined Behavior Sanitizer (recoverable only). Usage:
|
||||||
// - __suppress_ubsan__("undefined")
|
// - FLATBUFFERS_SUPPRESS_UBSAN("undefined")
|
||||||
// - __suppress_ubsan__("signed-integer-overflow")
|
// - FLATBUFFERS_SUPPRESS_UBSAN("signed-integer-overflow")
|
||||||
#if defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))
|
#if defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))
|
||||||
#define __suppress_ubsan__(type) __attribute__((no_sanitize(type)))
|
#define FLATBUFFERS_SUPPRESS_UBSAN(type) __attribute__((no_sanitize(type)))
|
||||||
#elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)
|
#elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)
|
||||||
#define __suppress_ubsan__(type) __attribute__((no_sanitize_undefined))
|
#define FLATBUFFERS_SUPPRESS_UBSAN(type) __attribute__((no_sanitize_undefined))
|
||||||
#else
|
#else
|
||||||
#define __suppress_ubsan__(type)
|
#define FLATBUFFERS_SUPPRESS_UBSAN(type)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// This is constexpr function used for checking compile-time constants.
|
// This is constexpr function used for checking compile-time constants.
|
||||||
@@ -422,7 +422,7 @@ template<typename T> T EndianScalar(T t) {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
|
// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
|
||||||
__suppress_ubsan__("alignment")
|
FLATBUFFERS_SUPPRESS_UBSAN("alignment")
|
||||||
T ReadScalar(const void *p) {
|
T ReadScalar(const void *p) {
|
||||||
return EndianScalar(*reinterpret_cast<const T *>(p));
|
return EndianScalar(*reinterpret_cast<const T *>(p));
|
||||||
}
|
}
|
||||||
@@ -436,13 +436,13 @@ T ReadScalar(const void *p) {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
|
// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
|
||||||
__suppress_ubsan__("alignment")
|
FLATBUFFERS_SUPPRESS_UBSAN("alignment")
|
||||||
void WriteScalar(void *p, T t) {
|
void WriteScalar(void *p, T t) {
|
||||||
*reinterpret_cast<T *>(p) = EndianScalar(t);
|
*reinterpret_cast<T *>(p) = EndianScalar(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> struct Offset;
|
template<typename T> struct Offset;
|
||||||
template<typename T> __suppress_ubsan__("alignment") void WriteScalar(void *p, Offset<T> t) {
|
template<typename T> FLATBUFFERS_SUPPRESS_UBSAN("alignment") void WriteScalar(void *p, Offset<T> t) {
|
||||||
*reinterpret_cast<uoffset_t *>(p) = EndianScalar(t.o);
|
*reinterpret_cast<uoffset_t *>(p) = EndianScalar(t.o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,7 +453,7 @@ template<typename T> __suppress_ubsan__("alignment") void WriteScalar(void *p, O
|
|||||||
// Computes how many bytes you'd have to pad to be able to write an
|
// Computes how many bytes you'd have to pad to be able to write an
|
||||||
// "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in
|
// "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in
|
||||||
// memory).
|
// memory).
|
||||||
__suppress_ubsan__("unsigned-integer-overflow")
|
FLATBUFFERS_SUPPRESS_UBSAN("unsigned-integer-overflow")
|
||||||
inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) {
|
inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) {
|
||||||
return ((~buf_size) + 1) & (scalar_size - 1);
|
return ((~buf_size) + 1) & (scalar_size - 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ inline void strtoval_impl(double *val, const char *str, char **endptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UBSAN: double to float is safe if numeric_limits<float>::is_iec559 is true.
|
// UBSAN: double to float is safe if numeric_limits<float>::is_iec559 is true.
|
||||||
__suppress_ubsan__("float-cast-overflow")
|
FLATBUFFERS_SUPPRESS_UBSAN("float-cast-overflow")
|
||||||
inline void strtoval_impl(float *val, const char *str, char **endptr) {
|
inline void strtoval_impl(float *val, const char *str, char **endptr) {
|
||||||
*val = __strtof_impl(str, endptr);
|
*val = __strtof_impl(str, endptr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
__suppress_ubsan__("unsigned-integer-overflow") bool VerifyTableStart(
|
FLATBUFFERS_SUPPRESS_UBSAN("unsigned-integer-overflow") bool VerifyTableStart(
|
||||||
const uint8_t *const table) {
|
const uint8_t *const table) {
|
||||||
// Check the vtable offset.
|
// Check the vtable offset.
|
||||||
const auto tableo = static_cast<size_t>(table - buf_);
|
const auto tableo = static_cast<size_t>(table - buf_);
|
||||||
|
|||||||
Reference in New Issue
Block a user