[scudo] Fix type mismatch on DefaultMaxEntrySize (#85897)

This commit is contained in:
ChiaHungDuan 2024-03-20 08:15:47 -07:00 committed by GitHub
parent 4095a326c0
commit aa8cffb958
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View File

@ -110,7 +110,7 @@ SECONDARY_REQUIRED_TEMPLATE_TYPE(CacheT)
SECONDARY_CACHE_OPTIONAL(const u32, EntriesArraySize, 0)
SECONDARY_CACHE_OPTIONAL(const u32, QuarantineSize, 0)
SECONDARY_CACHE_OPTIONAL(const u32, DefaultMaxEntriesCount, 0)
SECONDARY_CACHE_OPTIONAL(const u32, DefaultMaxEntrySize, 0)
SECONDARY_CACHE_OPTIONAL(const uptr, DefaultMaxEntrySize, 0)
SECONDARY_CACHE_OPTIONAL(const s32, MinReleaseToOsIntervalMs, INT32_MIN)
SECONDARY_CACHE_OPTIONAL(const s32, MaxReleaseToOsIntervalMs, INT32_MAX)

View File

@ -27,6 +27,19 @@ template <typename T> struct voidAdaptor {
using type = void;
};
// This is used for detecting the case that defines the flag with wrong type and
// it'll be viewed as undefined optional flag.
template <typename L, typename R> struct assertSameType {
template <typename, typename> struct isSame {
static constexpr bool value = false;
};
template <typename T> struct isSame<T, T> {
static constexpr bool value = true;
};
static_assert(isSame<L, R>::value, "Flag type mismatches");
using type = R;
};
} // namespace
namespace scudo {
@ -36,7 +49,8 @@ namespace scudo {
static constexpr removeConst<TYPE>::type getValue() { return DEFAULT; } \
}; \
template <typename Config> \
struct NAME##State<Config, decltype(Config::MEMBER)> { \
struct NAME##State< \
Config, typename assertSameType<decltype(Config::MEMBER), TYPE>::type> { \
static constexpr removeConst<TYPE>::type getValue() { \
return Config::MEMBER; \
} \