Skip to content

Commit a094b44

Browse files
authored
Merge pull request #977 from ldorau/Remove_incorrect_assert_in_utils_align_ptr_up_size_down
Fix: remove incorrect assert in utils_align_ptr_up_size_down()
2 parents ee6a711 + dd47ffc commit a094b44

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/utils/utils_common.c

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ void utils_align_ptr_up_size_down(void **ptr, size_t *size, size_t alignment) {
2525
}
2626

2727
ASSERT(IS_ALIGNED(p, alignment));
28-
ASSERT(IS_ALIGNED(s, alignment));
2928

3029
*ptr = (void *)p;
3130
*size = s;

test/utils/utils_linux.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5+
#include <cstdint>
56
#include <sys/mman.h>
67

78
#include "base.hpp"
@@ -169,3 +170,19 @@ TEST_F(test, utils_open) {
169170
EXPECT_EQ(utils_file_open(NULL), -1);
170171
EXPECT_EQ(utils_file_open_or_create(NULL), -1);
171172
}
173+
174+
TEST_F(test, utils_align_ptr_up_size_down) {
175+
uintptr_t ptr = 0x4000;
176+
size_t size = 0x8000;
177+
size_t alignment = 0x4000;
178+
utils_align_ptr_up_size_down((void **)&ptr, &size, alignment);
179+
EXPECT_EQ(ptr, 0x4000);
180+
EXPECT_EQ(size, 0x8000);
181+
182+
ptr = 0x4001;
183+
size = 0x8000;
184+
alignment = 0x4000;
185+
utils_align_ptr_up_size_down((void **)&ptr, &size, alignment);
186+
EXPECT_EQ(ptr, 0x8000);
187+
EXPECT_EQ(size, 0x4001);
188+
}

0 commit comments

Comments
 (0)