1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-05 06:28:57 +00:00

Check segment in in #pragma for validity

git-svn-id: svn://svn.cc65.org/cc65/trunk@223 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2000-07-29 12:03:29 +00:00
parent 9d85d084d0
commit c0f16c531b
3 changed files with 56 additions and 21 deletions

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998 Ullrich von Bassewitz */ /* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* Wacholderweg 14 */
/* D-70597 Stuttgart */ /* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */ /* EMail: uz@musoftware.de */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -136,6 +136,7 @@ static char* ErrMsg [ERR_COUNT-1] = {
"Illegal character constant", "Illegal character constant",
"Illegal modifier", "Illegal modifier",
"Illegal storage class", "Illegal storage class",
"Illegal segment name: `%s'",
"Division by zero", "Division by zero",
"Modulo operation with zero", "Modulo operation with zero",
"Range error", "Range error",

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998 Ullrich von Bassewitz */ /* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* Wacholderweg 14 */
/* D-70597 Stuttgart */ /* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */ /* EMail: uz@musoftware.de */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -131,6 +131,7 @@ enum Errors {
ERR_ILLEGAL_CHARCONST, ERR_ILLEGAL_CHARCONST,
ERR_ILLEGAL_MODIFIER, ERR_ILLEGAL_MODIFIER,
ERR_ILLEGAL_STORAGE_CLASS, ERR_ILLEGAL_STORAGE_CLASS,
ERR_ILLEGAL_SEG_NAME,
ERR_DIV_BY_ZERO, ERR_DIV_BY_ZERO,
ERR_MOD_BY_ZERO, ERR_MOD_BY_ZERO,
ERR_RANGE, ERR_RANGE,

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998 Ullrich von Bassewitz */ /* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* Wacholderweg 14 */
/* D-70597 Stuttgart */ /* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */ /* EMail: uz@musoftware.de */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -36,13 +36,14 @@
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include "global.h"
#include "error.h"
#include "litpool.h"
#include "symtab.h"
#include "scanner.h"
#include "codegen.h" #include "codegen.h"
#include "error.h"
#include "expr.h" #include "expr.h"
#include "global.h"
#include "litpool.h"
#include "scanner.h"
#include "segname.h"
#include "symtab.h"
#include "pragma.h" #include "pragma.h"
@ -134,6 +135,38 @@ static void StringPragma (void (*Func) (const char*))
static void SegNamePragma (void (*Func) (const char*))
/* Handle a pragma that expects a segment name parameter */
{
if (curtok != TOK_SCONST) {
Error (ERR_STRLIT_EXPECTED);
} else {
/* Get the segment name */
const char* Name = GetLiteral (curval);
/* Check if the name is valid */
if (ValidSegName (Name)) {
/* Call the given function to set the name */
Func (Name);
} else {
/* Segment name is invalid */
Error (ERR_ILLEGAL_SEG_NAME, Name);
}
/* Reset the string pointer, removing the string from the pool */
ResetLiteralOffs (curval);
}
/* Skip the string (or error) token */
NextToken ();
}
static void FlagPragma (unsigned char* Flag) static void FlagPragma (unsigned char* Flag)
/* Handle a pragma that expects a boolean paramater */ /* Handle a pragma that expects a boolean paramater */
{ {
@ -180,15 +213,15 @@ void DoPragma (void)
switch (Pragma) { switch (Pragma) {
case PR_BSSSEG: case PR_BSSSEG:
StringPragma (g_bssname); SegNamePragma (g_bssname);
break; break;
case PR_CODESEG: case PR_CODESEG:
StringPragma (g_codename); SegNamePragma (g_codename);
break; break;
case PR_DATASEG: case PR_DATASEG:
StringPragma (g_dataname); SegNamePragma (g_dataname);
break; break;
case PR_REGVARADDR: case PR_REGVARADDR:
@ -196,7 +229,7 @@ void DoPragma (void)
break; break;
case PR_RODATASEG: case PR_RODATASEG:
StringPragma (g_rodataname); SegNamePragma (g_rodataname);
break; break;
case PR_SIGNEDCHARS: case PR_SIGNEDCHARS: