From ee096d27df58e4a3658364f01dd96c4141d2001d Mon Sep 17 00:00:00 2001 From: Gros chien Date: Tue, 26 Aug 2025 23:45:39 +0200 Subject: [PATCH 1/7] Fix segfault when using -x without -l --- src/ca65/macro.c | 2 +- src/ca65/toklist.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ca65/macro.c b/src/ca65/macro.c index 260bbd866..6ea136c20 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -728,7 +728,7 @@ ExpandParam: /* Use next macro token */ TokSet (Mac->Exp); - if (ExpandMacros) { + if (ExpandMacros && SB_GetLen (&ListingName) > 0) { if (new_expand_line) { /* Suppress unneeded lines if short expansion ** the ExpandStart is used to ensure that diff --git a/src/ca65/toklist.c b/src/ca65/toklist.c index 7fd8cfcd3..5c8cadfcf 100644 --- a/src/ca65/toklist.c +++ b/src/ca65/toklist.c @@ -252,7 +252,7 @@ static int ReplayTokList (void* List) /* see description in macro.c */ static int new_expand_line = 1; - if (ExpandMacros) { + if (ExpandMacros && SB_GetLen (&ListingName) > 0) { if (new_expand_line) { if (LineLast->FragList == 0 && ExpandMacros==1) { LineCur->Output--; From 613e752051f0c1febd90227113e437e575edab22 Mon Sep 17 00:00:00 2001 From: Stefan Date: Fri, 5 Sep 2025 09:58:36 +0200 Subject: [PATCH 2/7] Fixed minor typo --- doc/agat.sgml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/agat.sgml b/doc/agat.sgml index ca5338c5f..71d5b019f 100644 --- a/doc/agat.sgml +++ b/doc/agat.sgml @@ -38,7 +38,7 @@ The default load address is $1903. Programs containing Agat-specific code may use the Usefull info

+Useful info

Emulation

From 0dc484f5a7efe8313b22d456c3a3c30b156ee8bf Mon Sep 17 00:00:00 2001 From: Kugel Fuhr <98353208+kugelfuhr@users.noreply.github.com> Date: Mon, 8 Sep 2025 20:51:27 +0200 Subject: [PATCH 3/7] Fix hardcoded upper limit of input files. --- src/ld65/main.c | 97 ++++++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 42 deletions(-) diff --git a/src/ld65/main.c b/src/ld65/main.c index ab2106fdc..3b434f68d 100644 --- a/src/ld65/main.c +++ b/src/ld65/main.c @@ -88,16 +88,46 @@ static unsigned LibFiles = 0; /* Count of library files linked */ #define INPUT_FILES_SGROUP 3 /* Entry is 'StartGroup' */ #define INPUT_FILES_EGROUP 4 /* Entry is 'EndGroup' */ -#define MAX_INPUTFILES 256 - /* Array of inputs (libraries and object files) */ -static struct InputFile { - const char *FileName; - unsigned Type; -} *InputFiles; -static unsigned InputFilesCount = 0; -static const char *CmdlineCfgFile = NULL, - *CmdlineTarget = NULL; +struct InputFile { + unsigned char Type; + char FileName[1]; /* Dynamically allocated */ +}; +typedef struct InputFile InputFile; +static Collection InputFiles = STATIC_COLLECTION_INITIALIZER; + +static const char* CmdlineCfgFile = NULL; +static const char* CmdlineTarget = NULL; + + + +/*****************************************************************************/ +/* struct InputFile */ +/*****************************************************************************/ + + + +static InputFile* NewInputFile (unsigned char Type, const char* FileName) +/* Create a new InputFile struct and return it */ +{ + unsigned Length = FileName? strlen (FileName) : 0; + InputFile* F = xmalloc (sizeof (InputFile) + Length); + F->Type = Type; + if (FileName) { + memcpy (F->FileName, FileName, Length + 1); + } else { + F->FileName[0] = '\0'; + } + return F; +} + + + +static void FreeInputFile (InputFile* F) +/* Free an InputFile struct */ +{ + xfree (F); +} @@ -434,10 +464,7 @@ static void OptLargeAlignment (const char* Opt attribute ((unused)), static void OptLib (const char* Opt attribute ((unused)), const char* Arg) /* Link a library */ { - InputFiles[InputFilesCount].Type = INPUT_FILES_FILE_LIB; - InputFiles[InputFilesCount].FileName = Arg; - if (++InputFilesCount >= MAX_INPUTFILES) - Error ("Too many input files"); + CollAppend (&InputFiles, NewInputFile (INPUT_FILES_FILE_LIB, Arg)); } @@ -485,10 +512,7 @@ static void OptNoUtf8 (const char* Opt attribute ((unused)), static void OptObj (const char* Opt attribute ((unused)), const char* Arg) /* Link an object file */ { - InputFiles[InputFilesCount].Type = INPUT_FILES_FILE_OBJ; - InputFiles[InputFilesCount].FileName = Arg; - if (++InputFilesCount >= MAX_INPUTFILES) - Error ("Too many input files"); + CollAppend (&InputFiles, NewInputFile (INPUT_FILES_FILE_OBJ, Arg)); } @@ -606,10 +630,7 @@ static void CmdlOptStartGroup (const char* Opt attribute ((unused)), const char* Arg attribute ((unused))) /* Remember 'start group' occurrence in input files array */ { - InputFiles[InputFilesCount].Type = INPUT_FILES_SGROUP; - InputFiles[InputFilesCount].FileName = Arg; /* Unused */ - if (++InputFilesCount >= MAX_INPUTFILES) - Error ("Too many input files"); + CollAppend (&InputFiles, NewInputFile (INPUT_FILES_SGROUP, 0)); } @@ -618,10 +639,7 @@ static void CmdlOptEndGroup (const char* Opt attribute ((unused)), const char* Arg attribute ((unused))) /* Remember 'end group' occurrence in input files array */ { - InputFiles[InputFilesCount].Type = INPUT_FILES_EGROUP; - InputFiles[InputFilesCount].FileName = Arg; /* Unused */ - if (++InputFilesCount >= MAX_INPUTFILES) - Error ("Too many input files"); + CollAppend (&InputFiles, NewInputFile (INPUT_FILES_EGROUP, 0)); } @@ -679,9 +697,6 @@ static void ParseCommandLine (void) unsigned I; unsigned LabelFileGiven = 0; - /* Allocate memory for input file array */ - InputFiles = xmalloc (MAX_INPUTFILES * sizeof (struct InputFile)); - /* Defer setting of config/target and input files until all options are parsed */ I = 1; while (I < ArgCount) { @@ -774,13 +789,8 @@ static void ParseCommandLine (void) } } else { - /* A filename */ - InputFiles[InputFilesCount].Type = INPUT_FILES_FILE; - InputFiles[InputFilesCount].FileName = Arg; - if (++InputFilesCount >= MAX_INPUTFILES) - Error ("Too many input files"); - + CollAppend (&InputFiles, NewInputFile (INPUT_FILES_FILE, Arg)); } /* Next argument */ @@ -793,17 +803,18 @@ static void ParseCommandLine (void) OptConfig (NULL, CmdlineCfgFile); } - /* Process input files */ - for (I = 0; I < InputFilesCount; ++I) { - switch (InputFiles[I].Type) { + /* Process input files and delete the entries while doing so */ + for (I = 0; I < CollCount (&InputFiles); ++I) { + InputFile* F = CollAtUnchecked (&InputFiles, I); + switch (F->Type) { case INPUT_FILES_FILE: - LinkFile (InputFiles[I].FileName, FILETYPE_UNKNOWN); + LinkFile (F->FileName, FILETYPE_UNKNOWN); break; case INPUT_FILES_FILE_LIB: - LinkFile (InputFiles[I].FileName, FILETYPE_LIB); + LinkFile (F->FileName, FILETYPE_LIB); break; case INPUT_FILES_FILE_OBJ: - LinkFile (InputFiles[I].FileName, FILETYPE_OBJ); + LinkFile (F->FileName, FILETYPE_OBJ); break; case INPUT_FILES_SGROUP: OptStartGroup (NULL, 0); @@ -812,12 +823,14 @@ static void ParseCommandLine (void) OptEndGroup (NULL, 0); break; default: - abort (); + FAIL ("Unknown file type"); } + FreeInputFile (F); } /* Free memory used for input file array */ - xfree (InputFiles); + DoneCollection (&InputFiles); + InitCollection (&InputFiles); /* Don't leave dangling pointers */ } From 1ef3f88f0adf7b3dba0849dfd521fc448cf366c2 Mon Sep 17 00:00:00 2001 From: Stefan Date: Sun, 14 Sep 2025 22:30:24 +0200 Subject: [PATCH 4/7] Fixed typos --- doc/ca65.sgml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 5e53fb002..2e5411c58 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -3192,7 +3192,7 @@ See: , when . pc_assignment @@ -3793,7 +3793,7 @@ See: , Date: Sun, 14 Sep 2025 22:36:31 +0200 Subject: [PATCH 5/7] Fixed typo --- doc/ca65.sgml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 5e53fb002..74ca32631 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -3792,7 +3792,7 @@ See: ,.LOCAL

This command may only be used inside a macro definition. It declares a list - of identifiers as local to the macro expansion. The identifers may be + of identifiers as local to the macro expansion. The identifiers may be standard identifiers or cheap local identifiers depending on the planed use. A problem when using macros are labels: Since they don't change their name, From 5e89953bf9ca04a21f1b7f28949c3000bf547436 Mon Sep 17 00:00:00 2001 From: Stefan Date: Wed, 17 Sep 2025 15:03:55 +0200 Subject: [PATCH 6/7] Fixed overflow --- src/common/gentype.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/gentype.c b/src/common/gentype.c index 1600a7c2f..1067fcbc6 100644 --- a/src/common/gentype.c +++ b/src/common/gentype.c @@ -102,7 +102,10 @@ const char* GT_AsString (const StrBuf* Type, StrBuf* String) ** will be zero terminated and a pointer to the contents are returned. */ { - static const char HexTab[16] = "0123456789ABCDEF"; + static const char HexTab[16] = { + '0','1','2','3','4','5','6','7', + '8','9','A','B','C','D','E','F' + }; unsigned I; /* Convert Type into readable hex. String will have twice then length From 9601b11a9c12718084787da794b8ca994a15d2f1 Mon Sep 17 00:00:00 2001 From: Stefan Date: Thu, 18 Sep 2025 11:10:41 +0200 Subject: [PATCH 7/7] inplicit length --- src/common/gentype.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/common/gentype.c b/src/common/gentype.c index 1067fcbc6..81480000a 100644 --- a/src/common/gentype.c +++ b/src/common/gentype.c @@ -102,10 +102,7 @@ const char* GT_AsString (const StrBuf* Type, StrBuf* String) ** will be zero terminated and a pointer to the contents are returned. */ { - static const char HexTab[16] = { - '0','1','2','3','4','5','6','7', - '8','9','A','B','C','D','E','F' - }; + static const char HexTab[] = "0123456789ABCDEF"; unsigned I; /* Convert Type into readable hex. String will have twice then length