- made the code mostly signed-char safe.

This eliminates all char function parameters that are not really ASCII characters and casts all char argument to the ctype is... functions.
This commit is contained in:
Christoph Oelckers 2022-10-12 22:09:26 +02:00
parent dc1c6976e2
commit 2f896b859b
13 changed files with 32 additions and 33 deletions

View file

@ -687,7 +687,7 @@ MoviePlayer* OpenMovie(const char* filename, TArray<int>& ans, const int* framet
{
size_t nLen = strlen(filename);
// Strip the drive letter and retry.
if (nLen >= 3 && isalpha(filename[0]) && filename[1] == ':' && filename[2] == '/')
if (nLen >= 3 && isalpha((uint8_t)filename[0]) && filename[1] == ':' && filename[2] == '/')
{
filename += 3;
fr = fileSystem.OpenFileReader(filename);

View file

@ -986,7 +986,7 @@ bool IsAbsPath(const char *name)
if (IsSeperator(name[0])) return true;
#ifdef _WIN32
/* [A-Za-z]: (for Windows) */
if (isalpha(name[0]) && name[1] == ':') return true;
if (isalpha((uint8_t)name[0]) && name[1] == ':') return true;
#endif /* _WIN32 */
return 0;
}

View file

@ -379,7 +379,7 @@ static bool DoSubstitution (FString &out, const char *in)
out.AppendCStrPart(a, b - a);
a = ++b;
while (*b && isalpha(*b))
while (*b && isalpha((uint8_t) * b))
{
++b;
}

View file

@ -233,7 +233,7 @@ TArray<FString> CollectSearchPaths()
if (nice.Len() > 0)
{
#ifdef _WIN32
if (isalpha(nice[0] && nice[1] == ':' && nice[2] != '/')) continue; // ignore drive relative paths because they are meaningless.
if (isalpha((uint8_t)nice[0] && nice[1] == ':' && nice[2] != '/')) continue; // ignore drive relative paths because they are meaningless.
#endif
// A path ending with "/*" means to add all subdirectories.
if (nice[nice.Len()-2] == '/' && nice[nice.Len()-1] == '*')

View file

@ -59,7 +59,7 @@ struct define_t
define_t gCmdDefines[kMaxCmdLineDefines];
void addMemoryResource(char* fileName, char flags, int ID);
void addMemoryResource(const char* fileName, int flags, int ID);
struct tag_t {
const char* _value;
@ -320,7 +320,7 @@ void RFS::ScriptError(const char* message)
char* p = _pStartLine;
while (*p != '\n')
{
if (isprint(*p))
if (isprint((uint8_t) *p))
msg.Push(*p);
else
msg.Push(' ');
@ -354,7 +354,7 @@ uint8_t RFS::GetNextTag()
// skip any space characters
do {
Increment();
} while (isspace(_curChar));
} while (isspace((uint8_t)_curChar));
if (_curChar == '\0') {
return kTagEnd;
@ -409,12 +409,12 @@ uint8_t RFS::GetNextTag()
isNegative = true;
if (!isdigit(_curChar)) {
if (!isdigit((uint8_t)_curChar)) {
UnsetMark();
}
}
if (isdigit(_curChar))
if (isdigit((uint8_t)_curChar))
{
// left path
if (_curChar == '0')
@ -428,14 +428,14 @@ uint8_t RFS::GetNextTag()
while (1)
{
Increment();
if (!isxdigit(_curChar)) { // isxdigit() checks for a hex value
if (!isxdigit((uint8_t)_curChar)) { // isxdigit() checks for a hex value
break;
}
// hex version of atoi?
scriptValue *= 16;
if (!isdigit(_curChar)) {
scriptValue += toupper(_curChar) - 55;
if (!isdigit((uint8_t)_curChar)) {
scriptValue += toupper((uint8_t)_curChar) - 55;
}
else {
scriptValue += _curChar - '0';
@ -518,7 +518,7 @@ uint8_t RFS::GetNextTag()
i = 0;
while (isalnum(_curChar))
while (isalnum((uint8_t)_curChar))
{
scriptBuffer[i] = _curChar;
SetMark();
@ -987,7 +987,7 @@ void ParseScript(int lumpnum)
//
//---------------------------------------------------------------------------
void addMemoryResource(char* filePath, char flags, int ID)
void addMemoryResource(const char* filePath, int flags, int ID)
{
char zDirectory[BMAX_PATH];
char zFilename[BMAX_PATH];

View file

@ -116,7 +116,7 @@ void IniFile::LoadRes(void *res)
char *pBuffer = buffer;
// remove whitespace from buffer
while (isspace(*pBuffer)) {
while (isspace((uint8_t)*pBuffer)) {
pBuffer++;
}
@ -239,7 +239,7 @@ bool IniFile::FindKey(const char *key)
assert(pEqual != NULL);
// remove whitespace
while (isspace(*(pEqual - 1))) {
while (isspace((uint8_t) *(pEqual - 1))) {
pEqual--;
}
@ -251,7 +251,7 @@ bool IniFile::FindKey(const char *key)
// strings match
*pEqual = c;
_13 = ++pEqualStart;
while (isspace(*_13)) {
while (isspace((uint8_t)*_13)) {
_13++;
}

View file

@ -156,7 +156,7 @@ static FString cleanPath(const char* pth)
FString path = pth;
FixPathSeperator(path);
if (fileSystem.FileExists(path)) return path;
if (path.Len() > 3 && path[1] == ':' && isalpha(path[0]) && path[2] == '/')
if (path.Len() > 3 && path[1] == ':' && isalpha((uint8_t)path[0]) && path[2] == '/')
{
path = path.Mid(3);
if (fileSystem.FileExists(path)) return path;

View file

@ -6682,7 +6682,7 @@ void useIncDecGen(DBloodActor* sourceactor, int objType, sectortype* destSect, w
//
//---------------------------------------------------------------------------
void sprite2sectorSlope(DBloodActor* actor, sectortype* pSector, char rel, bool forcez)
void sprite2sectorSlope(DBloodActor* actor, sectortype* pSector, int rel, bool forcez)
{
int slope = 0, z = 0;
switch (rel) {

View file

@ -839,7 +839,7 @@ void PathSound(sectortype* pSector, int nSound)
//
//---------------------------------------------------------------------------
void TranslateSector(sectortype* pSector, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, char bAllWalls)
void TranslateSector(sectortype* pSector, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, bool bAllWalls)
{
int x, y;
XSECTOR* pXSector = &pSector->xs();
@ -1450,13 +1450,13 @@ int StepRotateBusy(sectortype* pSector, unsigned int a2, DBloodActor* initiator)
{
vbp = pXSector->data + marker0->int_ang();
int nWave = pXSector->busyWaveA;
TranslateSector(pSector, GetWaveValue(pXSector->busy, nWave), GetWaveValue(a2, nWave), marker0->int_pos().X, marker0->int_pos().Y, marker0->int_pos().X, marker0->int_pos().Y, pXSector->data, marker0->int_pos().X, marker0->int_pos().Y, vbp, 1);
TranslateSector(pSector, GetWaveValue(pXSector->busy, nWave), GetWaveValue(a2, nWave), marker0->int_pos().X, marker0->int_pos().Y, marker0->int_pos().X, marker0->int_pos().Y, pXSector->data, marker0->int_pos().X, marker0->int_pos().Y, vbp, true);
}
else
{
vbp = pXSector->data - marker0->int_ang();
int nWave = pXSector->busyWaveB;
TranslateSector(pSector, GetWaveValue(pXSector->busy, nWave), GetWaveValue(a2, nWave), marker0->int_pos().X, marker0->int_pos().Y, marker0->int_pos().X, marker0->int_pos().Y, vbp, marker0->int_pos().X, marker0->int_pos().Y, pXSector->data, 1);
TranslateSector(pSector, GetWaveValue(pXSector->busy, nWave), GetWaveValue(a2, nWave), marker0->int_pos().X, marker0->int_pos().Y, marker0->int_pos().X, marker0->int_pos().Y, vbp, marker0->int_pos().X, marker0->int_pos().Y, pXSector->data, true);
}
pXSector->busy = a2;
if (pXSector->command == kCmdLink && pXSector->txID)
@ -1510,7 +1510,7 @@ int PathBusy(sectortype* pSector, unsigned int a2, DBloodActor* initiator)
if (!basepath || !marker0 || !marker1) return 0;
int nWave = marker0->xspr.wave;
TranslateSector(pSector, GetWaveValue(pXSector->busy, nWave), GetWaveValue(a2, nWave), basepath->int_pos().X, basepath->int_pos().Y, marker0->int_pos().X, marker0->int_pos().Y, marker0->int_ang(), marker1->int_pos().X, marker1->int_pos().Y, marker1->int_ang(), 1);
TranslateSector(pSector, GetWaveValue(pXSector->busy, nWave), GetWaveValue(a2, nWave), basepath->int_pos().X, basepath->int_pos().Y, marker0->int_pos().X, marker0->int_pos().Y, marker0->int_ang(), marker1->int_pos().X, marker1->int_pos().Y, marker1->int_ang(), true);
ZTranslateSector(pSector, pXSector, a2, nWave);
pXSector->busy = a2;
if ((a2 & 0xffff) == 0)
@ -1555,9 +1555,9 @@ void OperateDoor(sectortype* pSector, EVENT event, BUSYID busyWave)
}
}
else {
char t = !pXSector->state; int nDelta;
int nDelta;
if (t) nDelta = 65536 / ClipLow((pXSector->busyTimeA * 120) / 10, 1);
if (!pXSector->state) nDelta = 65536 / ClipLow((pXSector->busyTimeA * 120) / 10, 1);
else nDelta = -65536 / ClipLow((pXSector->busyTimeB * 120) / 10, 1);
AddBusy(pSector, busyWave, nDelta);
@ -1623,7 +1623,7 @@ void OperateTeleport(sectortype* pSector)
if (actor->spr.statnum == kStatDude)
{
PLAYER* pPlayer;
char bPlayer = actor->IsPlayerActor();
bool bPlayer = actor->IsPlayerActor();
if (bPlayer)
pPlayer = &gPlayer[actor->spr.type - kDudePlayer1];
else

View file

@ -73,7 +73,7 @@ static int ccmd_spawn(CCmdFuncPtr parm)
pal = (uint8_t)atol(parm->parms[1]); set |= 1;
[[fallthrough]];
case 1: // tile number
if (isdigit(parm->parms[0][0])) {
if (isdigit((uint8_t)parm->parms[0][0])) {
picnum = (unsigned short)atol(parm->parms[0]);
}
else {

View file

@ -407,7 +407,7 @@ bool ConCompiler::ispecial(char c)
static bool isaltok(char c)
{
// isalnum pukes on negative input.
return c > 0 && (isalnum(c) || c == '{' || c == '}' || c == '/' || c == '*' || c == '-' || c == '_' || c == '.');
return c > 0 && (isalnum((uint8_t)c) || c == '{' || c == '}' || c == '/' || c == '*' || c == '-' || c == '_' || c == '.');
}
//---------------------------------------------------------------------------
@ -532,7 +532,7 @@ void ConCompiler::getlabel(void)
skipcomments();
while (isalnum(*textptr & 0xff) == 0)
while (isalnum((uint8_t) * textptr & 0xff) == 0)
{
if (*textptr == 0x0a) line_number++;
textptr++;
@ -719,7 +719,7 @@ int ConCompiler::transnum(int type)
}
}
if (isdigit(*textptr) == 0 && *textptr != '-')
if (isdigit((uint8_t) *textptr) == 0 && *textptr != '-')
{
ReportError(ERROR_PARMUNDEFINED);
errorcount++;
@ -2935,7 +2935,7 @@ int ConCompiler::parsecommand()
#if 0
voxel_map[j].name[i] = 0;
voxel_map[j].voxnum = -2; // flag to load later
while ((i < 12) && (isalnum(*textptr) || *textptr == '.'))
while ((i < 12) && (isalnum((uint8_t) * textptr) || *textptr == '.'))
{
voxel_map[j].name[i++] = *textptr++;
}

View file

@ -4323,7 +4323,7 @@ void getzrangepoint(int x, int y, int z, sectortype* sect,
int j, k, l, dax, day, daz, xspan, yspan, xoff, yoff;
int x1, y1, x2, y2, x3, y3, x4, y4, cosang, sinang, tilenum;
short cstat;
char clipyou;
uint8_t clipyou;
if (sect == nullptr)
{

View file

@ -15001,7 +15001,6 @@ int InitUzi(PLAYER* pp)
int xvect,yvect,zvect;
ESpriteFlags cstat = 0;
uint8_t pal = 0;
//static char alternate=0;
static int uziclock=0;
int clockdiff=0;
bool FireSnd = false;