mirror of
https://github.com/sheumann/hush.git
synced 2024-12-26 10:32:02 +00:00
Fix overflow for machines greater than 4GB, return unsigned int to avoid
a cast and for greater accuracy.
This commit is contained in:
parent
97e2426582
commit
ce6482eace
11
init/init.c
11
init/init.c
@ -310,7 +310,7 @@ static void set_term(int fd)
|
|||||||
|
|
||||||
/* How much memory does this machine have?
|
/* How much memory does this machine have?
|
||||||
Units are kBytes to avoid overflow on 4GB machines */
|
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;
|
struct sysinfo info;
|
||||||
unsigned int result, u, s = 10;
|
unsigned int result, u, s = 10;
|
||||||
@ -330,10 +330,11 @@ static int check_free_memory(void)
|
|||||||
s--;
|
s--;
|
||||||
}
|
}
|
||||||
result = (info.totalram >> s) + (info.totalswap >> s);
|
result = (info.totalram >> s) + (info.totalswap >> s);
|
||||||
result = result * u;
|
if ((unsigned long long) (result * u) > UINT_MAX) {
|
||||||
if (result < 0)
|
return(UINT_MAX);
|
||||||
result = INT_MAX;
|
} else {
|
||||||
return result;
|
return(result * u);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void console_init(void)
|
static void console_init(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user