Skip to content

Commit 24fbde3

Browse files
Sjorsluke-jr
andcommitted
support: clamp RLIMIT_MEMLOCK to size_t
On 32-bit systems we build with _FILE_OFFSET_BITS=64 (see CMakeLists.txt), which makes rlim_t 64-bit when building against glibc (see bits/resource.h). Since size_t could be 32-bit, clamp RLIMIT_MEMLOCK to std::numeric_limits<size_t>::max() in PosixLockedPageAllocator::GetLimit(). Co-authored-by: Luke Dashjr <luke-jr+git@utopios.org>
1 parent b848ffc commit 24fbde3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/support/lockedpool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ size_t PosixLockedPageAllocator::GetLimit()
262262
#ifdef RLIMIT_MEMLOCK
263263
struct rlimit rlim;
264264
if (getrlimit(RLIMIT_MEMLOCK, &rlim) == 0) {
265-
if (rlim.rlim_cur != RLIM_INFINITY) {
265+
if (rlim.rlim_cur != RLIM_INFINITY &&
266+
std::cmp_less_equal(rlim.rlim_cur, static_cast<rlim_t>(std::numeric_limits<size_t>::max()))) {
266267
return rlim.rlim_cur;
267268
}
268269
}

0 commit comments

Comments
 (0)