[scudo] Use template specialization on Quarantine to avoid zero-length array

Use a separate templated QuarantineBlocks class to avoid a zero-length array

Differential Revision: https://reviews.llvm.org/D122518

GitOrigin-RevId: 0e1d2007aa3c63597c6965dd265055da78bf7c51
Change-Id: I2b8a70e0382c0ea408d6ccf89cbc9d526d64bdbb
diff --git a/standalone/secondary.h b/standalone/secondary.h
index abb58a2..f046839 100644
--- a/standalone/secondary.h
+++ b/standalone/secondary.h
@@ -113,6 +113,19 @@
   }
 }
 
+// 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 @@
   atomic_s32 ReleaseToOsIntervalMs = {};
 
   CachedBlock Entries[Config::SecondaryCacheEntriesArraySize] = {};
-  CachedBlock Quarantine[Config::SecondaryCacheQuarantineSize] = {};
+  NonZeroLengthArray<CachedBlock, Config::SecondaryCacheQuarantineSize>
+      Quarantine = {};
 };
 
 template <typename Config> class MapAllocator {