summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominic Chen <ddchen@apple.com>2022-04-19 01:05:23 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-04-19 01:05:23 +0000
commit1918656fbbd9f32094f463ab6b6ecf4580862241 (patch)
tree295e5549bdc711e6ea593ca30365111e4ed2e4de
parentfb37ef04c942b578084c135ab033161ff44cc99b (diff)
parent77f8306724360364850172351ff904d1fa05c030 (diff)
downloadscudo-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.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 {