From f27a8132d993fc48df27410c0660fde14c0aaccd Mon Sep 17 00:00:00 2001 From: Rangi Date: Mon, 20 Jul 2026 00:02:39 -0400 Subject: [PATCH] Avoid truncating too-large JR offset from an invalid object file --- src/link/patch.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/link/patch.cpp b/src/link/patch.cpp index 881b03cf..e16befd6 100644 --- a/src/link/patch.cpp +++ b/src/link/patch.cpp @@ -588,12 +588,12 @@ static void applyFilePatches(Section §ion, Section &dataSection) { // Offset is relative to the byte *after* the operand // PC as operand to `jr` is lower than reference PC by 2 uint16_t address = patch.pcSection->org + patch.pcOffset + 2; - int16_t jumpOffset = value - address; + int32_t jumpOffset = value - address; if (jumpOffset < -128 || jumpOffset > 127) { firstErrorAt( patch, - "`JR` target must be between -128 and 127 bytes away, not %" PRId16 + "`JR` target must be between -128 and 127 bytes away, not %" PRId32 "; use `JP` instead", jumpOffset );