Skip to content

Commit e02d718

Browse files
committed
Merge branch 'cb/total-ram-bsd-fix'
Use of sysctl() system call to learn the total RAM size used on BSDs has been corrected. * cb/total-ram-bsd-fix: builtin/gc: correct total_ram calculation with HAVE_BSD_SYSCTL
2 parents cc876f2 + 781c1cf commit e02d718

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

builtin/gc.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ static uint64_t total_ram(void)
539539
return total;
540540
}
541541
#elif defined(HAVE_BSD_SYSCTL) && (defined(HW_MEMSIZE) || defined(HW_PHYSMEM) || defined(HW_PHYSMEM64))
542-
int64_t physical_memory;
542+
uint64_t physical_memory;
543543
int mib[2];
544544
size_t length;
545545

@@ -551,9 +551,16 @@ static uint64_t total_ram(void)
551551
# else
552552
mib[1] = HW_PHYSMEM;
553553
# endif
554-
length = sizeof(int64_t);
555-
if (!sysctl(mib, 2, &physical_memory, &length, NULL, 0))
554+
length = sizeof(physical_memory);
555+
if (!sysctl(mib, 2, &physical_memory, &length, NULL, 0)) {
556+
if (length == 4) {
557+
uint32_t mem;
558+
559+
if (!sysctl(mib, 2, &mem, &length, NULL, 0))
560+
physical_memory = mem;
561+
}
556562
return physical_memory;
563+
}
557564
#elif defined(GIT_WINDOWS_NATIVE)
558565
MEMORYSTATUSEX memInfo;
559566

0 commit comments

Comments
 (0)