vfs: check userland buffers before reading them.
[haiku.git] / headers / os / support / StackOrHeapArray.h
blob45049a41297f088d9da528e4941189b67666f61c
1 /*
2 * Copyright 2012, Jonathan Schleifer <js@webkeks.org>. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _SUPPORT_STACKORHEAPARRAY_H
6 #define _SUPPORT_STACKORHEAPARRAY_H
8 #include <cstddef>
9 #include <new>
11 template <typename Type, int StackSize>
12 class BStackOrHeapArray {
13 public:
14 BStackOrHeapArray(size_t count)
16 if (count > StackSize)
17 fData = new(std::nothrow) Type[count];
18 else
19 fData = fStackData;
22 ~BStackOrHeapArray()
24 if (fData != fStackData)
25 delete[] fData;
28 bool IsValid() const
30 return fData != NULL;
33 operator Type*()
35 return fData;
38 private:
39 Type fStackData[StackSize];
40 Type* fData;
43 #endif