summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominic Chen <ddchen@apple.com>2022-04-19 01:38:44 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-04-19 01:38:44 +0000
commit1f4298f0d702bbdce4135ba31a7d216131cad9ce (patch)
tree295e5549bdc711e6ea593ca30365111e4ed2e4de
parent56ca92b4e24ccc8dd0133dbded6188552e66fddf (diff)
parent1918656fbbd9f32094f463ab6b6ecf4580862241 (diff)
downloadscudo-1f4298f0d702bbdce4135ba31a7d216131cad9ce.tar.gz
[scudo] Use template specialization on Quarantine to avoid zero-length array am: c69ff27cfb am: f603b0128e am: 77f8306724 am: 1918656fbb
Original change: https://android-review.googlesource.com/c/platform/external/scudo/+/2066948 Change-Id: I57db8b57b6f8393043416b3a476a0429598a1fb7 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--standalone/secondary.h16
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 {