diff options
author | Glenn L McGrath | 2003-08-26 02:14:58 +0000 |
---|---|---|
committer | Glenn L McGrath | 2003-08-26 02:14:58 +0000 |
commit | ce6482eace34fcd43e2f5310997f5366706f077e (patch) | |
tree | b4dc3185dc7d6a32585d4311baa3430da05e26f9 /init | |
parent | 97e242658265ed97badfecd3a5d7f596077716d0 (diff) | |
download | busybox-ce6482eace34fcd43e2f5310997f5366706f077e.zip busybox-ce6482eace34fcd43e2f5310997f5366706f077e.tar.gz |
Fix overflow for machines greater than 4GB, return unsigned int to avoid
a cast and for greater accuracy.
Diffstat (limited to 'init')
-rw-r--r-- | init/init.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/init/init.c b/init/init.c index 1ecc43e..e52517e 100644 --- a/init/init.c +++ b/init/init.c @@ -310,7 +310,7 @@ static void set_term(int fd) /* How much memory does this machine have? Units are kBytes to avoid overflow on 4GB machines */ -static int check_free_memory(void) +static unsigned int check_free_memory(void) { struct sysinfo info; unsigned int result, u, s = 10; @@ -330,10 +330,11 @@ static int check_free_memory(void) s--; } result = (info.totalram >> s) + (info.totalswap >> s); - result = result * u; - if (result < 0) - result = INT_MAX; - return result; + if ((unsigned long long) (result * u) > UINT_MAX) { + return(UINT_MAX); + } else { + return(result * u); + } } static void console_init(void) |