summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-08-26 02:14:58 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-08-26 02:14:58 +0000
commitce6482eace34fcd43e2f5310997f5366706f077e (patch)
treeb4dc3185dc7d6a32585d4311baa3430da05e26f9
parent97e242658265ed97badfecd3a5d7f596077716d0 (diff)
downloadbusybox-w32-ce6482eace34fcd43e2f5310997f5366706f077e.tar.gz
busybox-w32-ce6482eace34fcd43e2f5310997f5366706f077e.tar.bz2
busybox-w32-ce6482eace34fcd43e2f5310997f5366706f077e.zip
Fix overflow for machines greater than 4GB, return unsigned int to avoid
a cast and for greater accuracy.
-rw-r--r--init/init.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/init/init.c b/init/init.c
index 1ecc43e16..e52517e91 100644
--- a/init/init.c
+++ b/init/init.c
@@ -310,7 +310,7 @@ static void set_term(int fd)
310 310
311/* How much memory does this machine have? 311/* How much memory does this machine have?
312 Units are kBytes to avoid overflow on 4GB machines */ 312 Units are kBytes to avoid overflow on 4GB machines */
313static int check_free_memory(void) 313static unsigned int check_free_memory(void)
314{ 314{
315 struct sysinfo info; 315 struct sysinfo info;
316 unsigned int result, u, s = 10; 316 unsigned int result, u, s = 10;
@@ -330,10 +330,11 @@ static int check_free_memory(void)
330 s--; 330 s--;
331 } 331 }
332 result = (info.totalram >> s) + (info.totalswap >> s); 332 result = (info.totalram >> s) + (info.totalswap >> s);
333 result = result * u; 333 if ((unsigned long long) (result * u) > UINT_MAX) {
334 if (result < 0) 334 return(UINT_MAX);
335 result = INT_MAX; 335 } else {
336 return result; 336 return(result * u);
337 }
337} 338}
338 339
339static void console_init(void) 340static void console_init(void)