Bare metal: fix corner case in __normalize_e820( ) (#624)

See https://github.com/jart/cosmopolitan/pull/609#issuecomment-1247083243
This commit is contained in:
tkchia 2022-09-16 12:09:29 +08:00 committed by GitHub
parent 134ffee519
commit 3733b43a8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;