Harden sizeclass table
If a sizeclass in the metadata is corrupted, then this can be used to force an index beyond the end of these tables. This extends the tables to the next power of two, and uses a mask on the index, so they are always either a valid piece of data, or zero.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "bits.h"
|
||||
#include "flaglock.h"
|
||||
|
||||
namespace snmalloc
|
||||
@@ -30,4 +31,22 @@ namespace snmalloc
|
||||
return obj;
|
||||
}
|
||||
};
|
||||
|
||||
template <size_t length, typename T>
|
||||
class ModArray
|
||||
{
|
||||
static constexpr size_t rlength = bits::next_pow2_const(length);
|
||||
T array[rlength];
|
||||
|
||||
public:
|
||||
constexpr const T &operator[] (const size_t i) const
|
||||
{
|
||||
return array[i & (rlength - 1)];
|
||||
}
|
||||
|
||||
constexpr T &operator[] (const size_t i)
|
||||
{
|
||||
return array[i & (rlength - 1)];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user