From 66f2a2ef2a48d2724dc587c8459f7dbe401cb5b0 Mon Sep 17 00:00:00 2001 From: tkchia Date: Thu, 15 Sep 2022 16:23:27 +0000 Subject: [PATCH] Bare metal: fix corner case in __normalize_e820( ) See https://github.com/jart/cosmopolitan/pull/609#issuecomment-1247083243 --- libc/intrin/mman.greg.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libc/intrin/mman.greg.c b/libc/intrin/mman.greg.c index 6e0cc8c47..12cb3dc7e 100644 --- a/libc/intrin/mman.greg.c +++ b/libc/intrin/mman.greg.c @@ -93,8 +93,9 @@ static noasan textreal void __normalize_e820(struct mman *mm) { x = mm->e820[n].addr; y = mm->e820[n].addr + mm->e820[n].size; a = ROUNDUP(x, 4096); - b = ROUNDDOWN(y, 4096) - a; - if (b > 0 && mm->e820[i].type == kMemoryUsable) { + b = ROUNDDOWN(y, 4096); + if (b > a && mm->e820[i].type == kMemoryUsable) { + b -= a; mm->e820[n].addr = a; mm->e820[n].size = b; ++n;