Skip to content

Commit 7d7229c

Browse files
authored
Avoid integer overflow on ARM machine with 8G of memory (#73271)
1 parent 9dad110 commit 7d7229c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/coreclr/gc/unix/gcenv.unix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ uint64_t GCToOSInterface::GetPhysicalMemoryLimit(bool* is_restricted)
12291229
return 0;
12301230
}
12311231

1232-
return pages * pageSize;
1232+
return (uint64_t)pages * (uint64_t)pageSize;
12331233
#elif HAVE_SYSCTL
12341234
int mib[3];
12351235
mib[0] = CTL_HW;

src/coreclr/pal/src/misc/sysinfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,10 @@ GlobalMemoryStatusEx(
338338

339339
// Get the physical memory size
340340
#if HAVE_SYSCONF && HAVE__SC_PHYS_PAGES
341-
int64_t physical_memory;
341+
uint64_t physical_memory;
342342

343343
// Get the Physical memory size
344-
physical_memory = sysconf( _SC_PHYS_PAGES ) * sysconf( _SC_PAGE_SIZE );
344+
physical_memory = ((uint64_t)sysconf( _SC_PHYS_PAGES )) * ((uint64_t) sysconf( _SC_PAGE_SIZE ));
345345
lpBuffer->ullTotalPhys = (DWORDLONG)physical_memory;
346346
fRetVal = TRUE;
347347
#elif HAVE_SYSCTL

0 commit comments

Comments
 (0)