diff options
author | Dominic Chen <ddchen@apple.com> | 2022-04-19 01:05:23 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-04-19 01:05:23 +0000 |
commit | 1918656fbbd9f32094f463ab6b6ecf4580862241 (patch) | |
tree | 295e5549bdc711e6ea593ca30365111e4ed2e4de | |
parent | fb37ef04c942b578084c135ab033161ff44cc99b (diff) | |
parent | 77f8306724360364850172351ff904d1fa05c030 (diff) | |
download | scudo-1918656fbbd9f32094f463ab6b6ecf4580862241.tar.gz |
[scudo] Use template specialization on Quarantine to avoid zero-length array am: c69ff27cfb am: f603b0128e am: 77f8306724
Original change: https://android-review.googlesource.com/c/platform/external/scudo/+/2066948
Change-Id: If7d8269ebd1a485495e2e069d957e846068923fe
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | standalone/secondary.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/standalone/secondary.h b/standalone/secondary.h index abb58a2882a..f0468391dee 100644 --- a/standalone/secondary.h +++ b/standalone/secondary.h @@ -113,6 +113,19 @@ void mapSecondary(Options Options, uptr CommitBase, uptr CommitSize, } } +// Template specialization to avoid producing zero-length array +template <typename T, size_t Size> class NonZeroLengthArray { +public: + T &operator[](uptr Idx) { return values[Idx]; } + +private: + T values[Size]; +}; +template <typename T> class NonZeroLengthArray<T, 0> { +public: + T &operator[](uptr UNUSED Idx) { UNREACHABLE("Unsupported!"); } +}; + template <typename Config> class MapAllocatorCache { public: // Ensure the default maximum specified fits the array. @@ -395,7 +408,8 @@ private: atomic_s32 ReleaseToOsIntervalMs = {}; CachedBlock Entries[Config::SecondaryCacheEntriesArraySize] = {}; - CachedBlock Quarantine[Config::SecondaryCacheQuarantineSize] = {}; + NonZeroLengthArray<CachedBlock, Config::SecondaryCacheQuarantineSize> + Quarantine = {}; }; template <typename Config> class MapAllocator { |