From 7a0f2a3409580030f60f0bf2b351dd701f868b5a Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 26 Apr 2007 15:24:41 -0700 Subject: linux.c32: saturate memory size to 32 bits if too large --- com32/modules/linux.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'com32/modules/linux.c') diff --git a/com32/modules/linux.c b/com32/modules/linux.c index f1db8c87..c20536f3 100644 --- a/com32/modules/linux.c +++ b/com32/modules/linux.c @@ -99,6 +99,12 @@ static unsigned long long suffix_number(const char *str) return v; } +/* Truncate to 32 bits, with saturate */ +static inline uint32_t saturate32(unsigned long long v) +{ + return (v > 0xffffffff) ? 0xffffffff : (uint32_t)v; +} + /* Stitch together the command line from a set of argv's */ static char *make_cmdline(char **argv) { @@ -196,7 +202,7 @@ int main(int argc, char *argv[]) /* Look for specific command-line arguments we care about */ if ((arg = find_argument(argp, "mem="))) - mem_limit = suffix_number(arg); + mem_limit = saturate32(suffix_number(arg)); if ((arg = find_argument(argp, "vga="))) video_mode = strtoul(arg, NULL, 0); -- cgit v1.2.3