ld65 overwrite segment should pad with fill value if the desired seek position is beyond the end of the file so far

This commit is contained in:
bbbradsmith 2023-02-19 08:37:07 -05:00
parent 2ac055383f
commit 4fc19a3d4c
1 changed files with 9 additions and 1 deletions

View File

@ -193,8 +193,16 @@ static void BinWriteMem (BinDesc* D, MemoryArea* M)
NewAddr += M->Start;
}
if (DoWrite || (M->Flags & MF_FILL) != 0) {
/* Seek in "overwrite" segments */
if (S->Flags & SF_OVERWRITE) {
/* Seek in "overwrite" segments. Fill if the seek position has not been reached yet. */
unsigned long FileLength;
unsigned long SeekTarget = NewAddr - M->Start + M->FileOffs;
fseek (D->F, 0, SEEK_END);
FileLength = ftell (D->F);
if (SeekTarget > FileLength) {
WriteMult (D->F, M->FillVal, SeekTarget - FileLength);
PrintNumVal ("SF_OVERWRITE", SeekTarget - FileLength);
}
fseek (D->F, NewAddr - M->Start + M->FileOffs, SEEK_SET);
} else {
WriteMult (D->F, M->FillVal, NewAddr-Addr);