Lugdunum  0.1.0
BoundsChecker.inl
Go to the documentation of this file.
1 inline void NoBoundsChecking::guardFront(void*, size_t) const {}
2 inline void NoBoundsChecking::guardBack(void*, size_t) const {}
3 
4 inline void NoBoundsChecking::checkFront(void*, size_t) const {}
5 inline void NoBoundsChecking::checkBack(void*, size_t) const {}
6 
7 inline void SimpleBoundsChecking::guardFront(void* ptr, size_t) const {
8  std::memcpy(ptr, SimpleBoundsChecking::MagicFront, SimpleBoundsChecking::SizeFront);
9 }
10 
11 inline void SimpleBoundsChecking::guardBack(void* ptr, size_t size) const {
12  std::memcpy(static_cast<char*>(ptr) + size - SimpleBoundsChecking::SizeBack, SimpleBoundsChecking::MagicBack, SimpleBoundsChecking::SizeBack);
13 }
14 
15 inline void SimpleBoundsChecking::checkFront(void* ptr, size_t) const {
16  // In release, LUG_ASSERT is discarded
17  (void)(ptr);
18 
19  LUG_ASSERT(
20  std::memcmp(ptr, SimpleBoundsChecking::MagicFront, SimpleBoundsChecking::SizeFront) == 0,
21  "Memory overwrite at front of the user buffer"
22  );
23 }
24 
25 inline void SimpleBoundsChecking::checkBack(void* ptr, size_t size) const {
26  // In release, LUG_ASSERT is discarded
27  (void)(ptr);
28  (void)(size);
29 
30  LUG_ASSERT(
31  std::memcmp(static_cast<char*>(ptr) + size - SimpleBoundsChecking::SizeBack, SimpleBoundsChecking::MagicBack, SimpleBoundsChecking::SizeBack) == 0,
32  "Memory overwrite at back of the user buffer"
33  );
34 }
#define LUG_ASSERT(assertion, message)
Definition: Debug.hpp:38