:: commit 6bdf6c3e587a4d4c4eeb5d742ce7234a892567fa

monkuous <84319635+monkuous@users.noreply.github.com> — 2024-09-17 20:24

parents: 337b15089f

protos/multiboot2: use signed integers for relocation

diff --git a/common/protos/multiboot2.c b/common/protos/multiboot2.c
index 4d059206..49f99ca0 100644
--- a/common/protos/multiboot2.c
+++ b/common/protos/multiboot2.c
@@ -314,24 +314,24 @@ noreturn void multiboot2_load(char *config, char* cmdline) {
         }
     }
 
-    uint64_t reloc_slide = 0;
+    int64_t reloc_slide = 0;
 
     if (has_reloc_header) {
         bool reloc_ascend;
-        uint64_t relocated_base;
+        int64_t relocated_base;
 
         switch (reloc_tag.preference) {
             default:
             case 0: case 1: // Prefer lowest to highest
                 reloc_ascend = true;
-                relocated_base = ALIGN_UP(reloc_tag.min_addr, reloc_tag.align);
+                relocated_base = (int64_t)ALIGN_UP(reloc_tag.min_addr, reloc_tag.align);
                 if (relocated_base + ranges->length > reloc_tag.max_addr) {
                     goto reloc_fail;
                 }
                 break;
             case 2: // Prefer highest to lowest
                 reloc_ascend = false;
-                relocated_base = ALIGN_DOWN(reloc_tag.max_addr - ranges->length, reloc_tag.align);
+                relocated_base = (int64_t)ALIGN_DOWN(reloc_tag.max_addr - ranges->length, reloc_tag.align);
                 if (relocated_base < reloc_tag.min_addr) {
                     goto reloc_fail;
                 }
tab: 248 wrap: offon