From c49bf71d7c7b744eb09aa978d3f21cd3af41529e Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Wed, 17 Jun 2020 11:42:18 +0300 Subject: [PATCH] [runtime] Add assert for illegal alignment (#4235) Without that check next assert will wrongly pass e.g. for align=65 --- runtime/src/main/cpp/Natives.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/src/main/cpp/Natives.cpp b/runtime/src/main/cpp/Natives.cpp index d194bd7f524..e9fb15336f8 100644 --- a/runtime/src/main/cpp/Natives.cpp +++ b/runtime/src/main/cpp/Natives.cpp @@ -52,6 +52,8 @@ void* Kotlin_interop_malloc(KLong size, KInt align) { if (size > SIZE_MAX) { return nullptr; } + RuntimeAssert(align > 0, "Unsupported alignment"); + RuntimeAssert((align & (align - 1)) == 0, "Alignment must be power of two"); void* result = konan::calloc_aligned(1, size, align); if ((reinterpret_cast(result) & (align - 1)) != 0) {