aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/option.c7
-rw-r--r--src/os/mem.c2
-rw-r--r--src/os/os.h2
3 files changed, 7 insertions, 4 deletions
diff --git a/src/option.c b/src/option.c
index 17428ac697..4e40440386 100644
--- a/src/option.c
+++ b/src/option.c
@@ -2011,8 +2011,11 @@ void set_init_1(void)
#endif
{
#ifdef HAVE_TOTAL_MEM
- /* Use amount of memory available to Vim. */
- n = (os_get_total_mem_kib() >> 1);
+ /* Use half of amount of memory available to Vim. */
+ /* If too much to fit in long_u, get long_u max */
+ uint64_t available_kib = os_get_total_mem_kib();
+ n = available_kib / 2 > ULONG_MAX ? ULONG_MAX
+ : (long_u)(available_kib /2);
#else
n = (0x7fffffff >> 11);
#endif
diff --git a/src/os/mem.c b/src/os/mem.c
index 4eef84bfbe..e5549340ff 100644
--- a/src/os/mem.c
+++ b/src/os/mem.c
@@ -4,7 +4,7 @@
#include "os/os.h"
-long_u os_get_total_mem_kib(void) {
+uint64_t os_get_total_mem_kib(void) {
// Convert bytes to KiB.
return uv_get_total_memory() >> 10;
}
diff --git a/src/os/os.h b/src/os/os.h
index e624f6ac23..67cda28348 100644
--- a/src/os/os.h
+++ b/src/os/os.h
@@ -79,7 +79,7 @@ int os_rmdir(const char *path);
int os_remove(const char *path);
/// Get the total system physical memory in KiB.
-long_u os_get_total_mem_kib(void);
+uint64_t os_get_total_mem_kib(void);
const char *os_getenv(const char *name);
int os_setenv(const char *name, const char *value, int overwrite);
char *os_getenvname_at_index(size_t index);