From e4b610994c586715d3a36ed30d54c1b974d5f97f Mon Sep 17 00:00:00 2001 From: Kugel Fuhr <98353208+kugelfuhr@users.noreply.github.com> Date: Mon, 16 Jun 2025 16:01:56 +0200 Subject: [PATCH] Fix #2694. Also reformatting of long comments and refactoring of a small piece of code. --- src/ld65/config.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ld65/config.c b/src/ld65/config.c index 947302e98..cb55fae69 100644 --- a/src/ld65/config.c +++ b/src/ld65/config.c @@ -2107,7 +2107,9 @@ unsigned CfgProcess (void) FillLevel - M->Size, (FillLevel - M->Size == 1) ? "" : "s"); } if (FillLevel > M->FillLevel) { - /* Regular segments increase FillLevel. Overwrite segments may increase but not decrease FillLevel. */ + /* Regular segments increase FillLevel. Overwrite segments may + ** increase but not decrease FillLevel. + */ FillAdded = FillLevel - M->FillLevel; M->FillLevel = FillLevel; } @@ -2127,15 +2129,18 @@ unsigned CfgProcess (void) /* Calculate the new address */ Addr += S->Seg->Size; - /* If this segment will go out to the file, or its place - ** in the file will be filled, then increase the file size. - ** An OVERWRITE segment will only increase the size if it overlapped some of the fill area. + /* If this segment will go out to the file, or its place in the + ** file will be filled, then increase the file size. An OVERWRITE + ** segment will only increase the size if it overlapped some of + ** the fill area. */ if (S->Load == M && ((S->Flags & SF_BSS) == 0 || (M->Flags & MF_FILL) != 0)) { - M->F->Size += (!(S->Flags & SF_OVERWRITE)) ? - (Addr - StartAddr) : - FillAdded; + if ((S->Flags & SF_OVERWRITE) == 0) { + M->F->Size += Addr - StartAddr; + } else { + M->F->Size += FillAdded; + } } } @@ -2173,7 +2178,7 @@ unsigned CfgProcess (void) ** area, account for that in the file size. */ if ((M->Flags & MF_OVERFLOW) == 0 && (M->Flags & MF_FILL) != 0) { - M->F->Size += (M->Size - M->FillLevel); + M->F->Size = M->FileOffs + M->Size; } }