Skip to content

Commit

Permalink
[scudo] Use template specialization on Quarantine to avoid zero-lengt…
Browse files Browse the repository at this point in the history
…h array

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

Differential Revision: https://reviews.llvm.org/D122518
  • Loading branch information
ddcc committed Mar 28, 2022
1 parent 2add3fb commit 7dda44c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion compiler-rt/lib/scudo/standalone/secondary.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,18 @@ template <typename Config> class MapAllocatorCache {
u64 Time;
};

// Template specialization to avoid producing zero-length array
template <size_t Size> class QuarantineBlocks {
public:
CachedBlock &operator[](uptr Idx) { return Blocks[Idx]; }
private:
CachedBlock Blocks[Size];
};
template <> class QuarantineBlocks<0> {
public:
CachedBlock &operator[](uptr UNUSED Idx) { UNREACHABLE("Unsupported!"); }
};

void releaseIfOlderThan(CachedBlock &Entry, u64 Time) {
if (!Entry.CommitBase || !Entry.Time)
return;
Expand Down Expand Up @@ -395,7 +407,7 @@ template <typename Config> class MapAllocatorCache {
atomic_s32 ReleaseToOsIntervalMs = {};

CachedBlock Entries[Config::SecondaryCacheEntriesArraySize] = {};
CachedBlock Quarantine[Config::SecondaryCacheQuarantineSize] = {};
QuarantineBlocks<Config::SecondaryCacheQuarantineSize> Quarantine = {};
};

template <typename Config> class MapAllocator {
Expand Down

0 comments on commit 7dda44c

Please sign in to comment.