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

Dominic Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 19:22:42 PDT 2022


ddcc updated this revision to Diff 418760.
ddcc added a comment.

Add another template argument to avoid exposing private struct


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122518/new/

https://reviews.llvm.org/D122518

Files:
  compiler-rt/lib/scudo/standalone/secondary.h


Index: compiler-rt/lib/scudo/standalone/secondary.h
===================================================================
--- compiler-rt/lib/scudo/standalone/secondary.h
+++ compiler-rt/lib/scudo/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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122518.418760.patch
Type: text/x-patch
Size: 1087 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220329/15773cdd/attachment.bin>


More information about the llvm-commits mailing list