Ver código fonte

Assert on non-power-of-two alignment values

Daniele Bartolini 12 anos atrás
pai
commit
1b4c4689cc
2 arquivos alterados com 5 adições e 4 exclusões
  1. 2 1
      src/core/mem/Memory.cpp
  2. 3 3
      src/core/mem/Memory.h

+ 2 - 1
src/core/mem/Memory.cpp

@@ -24,8 +24,9 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
+#include <new>
+
 #include "Memory.h"
-#include "Assert.h"
 #include "MallocAllocator.h"
 
 //-----------------------------------------------------------------------------

+ 3 - 3
src/core/mem/Memory.h

@@ -26,10 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include <stdint.h>
-#include <cstdio>
-#include <new>
 #include "Types.h"
+#include "Assert.h"
 
 namespace crown
 {
@@ -42,6 +40,8 @@ const size_t	DEFAULT_ALIGN	= 4;			//!< Default memory alignment in bytes
 /// Returns the pointer @a p aligned to the desired @a align byte
 inline void* align(void* p, size_t align)
 {
+	CE_ASSERT(align % 2 == 0, "Alignment must be a power of two");
+
 	uintptr_t ptr = (uintptr_t)p;
 
 	return (void*)(ptr + (align - ptr % align));