[NTOSKRNL:CC] Added Bounds Checked Array Class

This Bounds Checked array will be used for OBCB type
This commit is contained in:
Dibyamartanda Samanta 2024-08-01 14:02:45 +02:00 committed by CodingWorkshop Signing Team
parent d825fe1dcb
commit dac01f6510
Signed by: CodingWorkshop Signing Team
GPG Key ID: 6DC88369C82795D2

View File

@ -104,3 +104,43 @@ private:
PEX_SPIN_LOCK m_SpinLock;
KIRQL m_OldIrql;
};
template <typename T>
class Array {
public:
Array(T* data, size_t size) : data_(data), size_(size) {}
T& operator[](size_t index) {
checkBounds(index);
return data_[index];
}
const T& operator[](size_t index) const {
checkBounds(index);
return data_[index];
}
T& at(size_t index) {
checkBounds(index);
return data_[index];
}
const T& at(size_t index) const {
checkBounds(index);
return data_[index];
}
size_t size() const {
return size_;
}
private:
T* data_;
size_t size_;
void checkBounds(size_t index) const {
if (index >= size_) {
ExRaiseStatus(STATUS_ARRAY_BOUNDS_EXCEEDED);
}
}
};