diff options
author | Abseil Team <absl-team@google.com> | 2023-12-28 11:32:04 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-12-28 11:32:54 -0800 |
commit | 1ac355bbb7e1e3c7916d812976127cf15c411bd3 (patch) | |
tree | 5a0de1ad8ce94aa23f61036becd82490ab4f07b9 /absl/base | |
parent | f9228ec834edef9b623d4824dd006890c203adc3 (diff) | |
download | abseil-1ac355bbb7e1e3c7916d812976127cf15c411bd3.tar.gz abseil-1ac355bbb7e1e3c7916d812976127cf15c411bd3.tar.bz2 abseil-1ac355bbb7e1e3c7916d812976127cf15c411bd3.zip |
Add compile-checks to ensure the parameter to absl::numbers_internal::FastIntToBuffer isn't provably insufficient
This performance-sensitive API is internal, and should not be used directly. Nevertheless, some do use it, so it's worth trying to block incorrect uses where we can.
PiperOrigin-RevId: 594289730
Change-Id: Ib5df39b450ef2ceda795082cde10ec2ba2642172
Diffstat (limited to 'absl/base')
-rw-r--r-- | absl/base/macros.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/absl/base/macros.h b/absl/base/macros.h index f33cd192..cd7cf498 100644 --- a/absl/base/macros.h +++ b/absl/base/macros.h @@ -138,4 +138,16 @@ ABSL_NAMESPACE_END #define ABSL_INTERNAL_RETHROW do {} while (false) #endif // ABSL_HAVE_EXCEPTIONS +// Requires the compiler to prove that the size of the given object is at least +// the expected amount. +#if ABSL_HAVE_ATTRIBUTE(diagnose_if) && ABSL_HAVE_BUILTIN(__builtin_object_size) +#define ABSL_INTERNAL_NEED_MIN_SIZE(Obj, N) \ + __attribute__((diagnose_if(__builtin_object_size(Obj, 0) < N, \ + "object size provably too small " \ + "(this would corrupt memory)", \ + "error"))) +#else +#define ABSL_INTERNAL_NEED_MIN_SIZE(Obj, N) +#endif + #endif // ABSL_BASE_MACROS_H_ |