From 2f6f5f0da142f2a21f30449fe6de78d24e2987ae Mon Sep 17 00:00:00 2001 From: Kugel Fuhr <98353208+kugelfuhr@users.noreply.github.com> Date: Wed, 11 Sep 2024 19:20:01 +0200 Subject: [PATCH 1/2] Fix problem with #line when there is no whitespace between line number and filename. y --- src/cc65/preproc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc65/preproc.c b/src/cc65/preproc.c index 1ee810060..96db1d8fe 100644 --- a/src/cc65/preproc.c +++ b/src/cc65/preproc.c @@ -2913,7 +2913,7 @@ static unsigned GetLineDirectiveNum (void) /* Ensure the buffer is terminated with a '\0' */ SB_Terminate (&Buf); - if (SkipWhitespace (0) != 0 || CurC == '\0') { + if (SB_GetLen (&Buf) > 0) { const char* Str = SB_GetConstBuf (&Buf); if (Str[0] == '\0') { PPWarning ("#line directive interprets number as decimal, not octal"); @@ -2929,9 +2929,10 @@ static unsigned GetLineDirectiveNum (void) } } } else { - PPError ("#line directive requires a simple decimal digit sequence"); + PPError ("#line directive requires a decimal digit sequence"); ClearLine (); } + SkipWhitespace (0); /* Done with the buffer */ SB_Done (&Buf); From 70ca6d420063c0fe0b9abb731232ca533a1d958e Mon Sep 17 00:00:00 2001 From: Kugel Fuhr <98353208+kugelfuhr@users.noreply.github.com> Date: Wed, 11 Sep 2024 19:21:19 +0200 Subject: [PATCH 2/2] Fixed a standard noncompliance: In C99 and above there must be whitespace between a name of an object like macro and its replacement list. --- src/cc65/preproc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/cc65/preproc.c b/src/cc65/preproc.c index 96db1d8fe..d033520b8 100644 --- a/src/cc65/preproc.c +++ b/src/cc65/preproc.c @@ -2640,6 +2640,18 @@ static void DoDefine (void) goto Error_Handler; } NextChar (); + + } else { + + /* Object like macro. Check ISO/IEC 9899:1999 (E) 6.10.3p3: + ** "There shall be white-space between the identifier and the + ** replacement list in the definition of an object-like macro." + ** Note: C89 doesn't have this constraint. + */ + if (Std == STD_C99 && !IsSpace (CurC)) { + PPWarning ("ISO C99 requires whitespace after the macro name"); + } + } /* Remove whitespace and comments from the line, store the preprocessed