Allowed character code zero to be remapped with other character codes.

This commit is contained in:
Greg King
2016-06-11 06:43:19 -04:00
parent e95d07aa97
commit 573381a340
8 changed files with 71 additions and 59 deletions

View File

@@ -618,16 +618,16 @@ static void DoCase (void)
static void DoCharMap (void)
/* Allow custome character mappings */
/* Allow custom character mappings */
{
long Index;
long Code;
/* Read the index as numerical value */
Index = ConstExpression ();
if (Index <= 0 || Index > 255) {
if (Index < 0 || Index > 255) {
/* Value out of range */
ErrorSkip ("Range error");
ErrorSkip ("Index range error");
return;
}
@@ -638,7 +638,7 @@ static void DoCharMap (void)
Code = ConstExpression ();
if (Code < 0 || Code > 255) {
/* Value out of range */
ErrorSkip ("Range error");
ErrorSkip ("Code range error");
return;
}

View File

@@ -66,11 +66,12 @@ IntStack WarningsAreErrors = INTSTACK(0); /* Treat warnings as errors */
/* Warn about: */
IntStack WarnConstComparison= INTSTACK(1); /* - constant comparison results */
IntStack WarnNoEffect = INTSTACK(1); /* - statements without an effect */
IntStack WarnRemapZero = INTSTACK(1); /* - remapping character code zero */
IntStack WarnStructParam = INTSTACK(1); /* - structs passed by val */
IntStack WarnUnknownPragma = INTSTACK(1); /* - unknown #pragmas */
IntStack WarnUnusedLabel = INTSTACK(1); /* - unused labels */
IntStack WarnUnusedParam = INTSTACK(1); /* - unused parameters */
IntStack WarnUnusedVar = INTSTACK(1); /* - unused variables */
IntStack WarnUnknownPragma = INTSTACK(1); /* - unknown #pragmas */
/* Map the name of a warning to the intstack that holds its state */
typedef struct WarnMapEntry WarnMapEntry;
@@ -79,10 +80,11 @@ struct WarnMapEntry {
const char* Name;
};
static WarnMapEntry WarnMap[] = {
/* Keep sorted, even if this isn't used for now */
{ &WarningsAreErrors, "error" },
/* Keep names sorted, even if it isn't used for now */
{ &WarnConstComparison, "const-comparison" },
{ &WarningsAreErrors, "error" },
{ &WarnNoEffect, "no-effect" },
{ &WarnRemapZero, "remap-zero" },
{ &WarnStructParam, "struct-param" },
{ &WarnUnknownPragma, "unknown-pragma" },
{ &WarnUnusedLabel, "unused-label" },

View File

@@ -65,11 +65,12 @@ extern IntStack WarningsAreErrors; /* Treat warnings as errors */
/* Warn about: */
extern IntStack WarnConstComparison; /* - constant comparison results */
extern IntStack WarnNoEffect; /* - statements without an effect */
extern IntStack WarnRemapZero; /* - remapping character code zero */
extern IntStack WarnStructParam; /* - structs passed by val */
extern IntStack WarnUnknownPragma; /* - unknown #pragmas */
extern IntStack WarnUnusedLabel; /* - unused labels */
extern IntStack WarnUnusedParam; /* - unused parameters */
extern IntStack WarnUnusedVar; /* - unused variables */
extern IntStack WarnUnknownPragma; /* - unknown #pragmas */

View File

@@ -453,13 +453,14 @@ static void CharMapPragma (StrBuf* B)
return;
}
if (Index < 1 || Index > 255) {
if (Index == 0) {
/* For groepaz */
Error ("Remapping 0 is not allowed");
} else {
if (Index != 0) {
Error ("Character index out of range");
return;
}
/* For groepaz and Christian */
if (IS_Get (&WarnRemapZero)) {
Warning ("Remapping from 0 is dangerous with string functions");
}
return;
}
/* Comma follows */
@@ -472,13 +473,14 @@ static void CharMapPragma (StrBuf* B)
return;
}
if (C < 1 || C > 255) {
if (C == 0) {
/* For groepaz */
Error ("Remapping 0 is not allowed");
} else {
if (C != 0) {
Error ("Character code out of range");
return;
}
/* For groepaz and Christian */
if (IS_Get (&WarnRemapZero)) {
Warning ("Remapping to 0 can make string functions stop unexpectedly");
}
return;
}
/* Remap the character */

View File

@@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998-2002 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@cc65.org */
/* (C) 1998-2002, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */

View File

@@ -124,6 +124,6 @@ void TgtTranslateStrBuf (StrBuf* Buf)
void TgtTranslateSet (unsigned Index, unsigned char C)
/* Set the translation code for the given character */
{
CHECK (Index > 0 && Index < sizeof (Tab));
CHECK (Index < sizeof (Tab));
Tab[Index] = C;
}