From: divverent Date: Sun, 28 Dec 2008 18:47:42 +0000 (+0000) Subject: fix whitespace handling: X-Git-Tag: xonotic-v0.1.0preview~1984 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=50f3f558108be1cf9e79f516bfdb257d2b50e2c5;p=xonotic%2Fdarkplaces.git fix whitespace handling: treat ONLY the following characters as whitespace: NUL, TAB, LF, CR, SPC Alternatively, there is commented out macro code in quakedef.h to accept any chars in 0..32 as whitespace. Previously: 0..32 and 128..255 (due to signed char) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8606 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_main.c b/cl_main.c index 75e3bd85..7beb895a 100644 --- a/cl_main.c +++ b/cl_main.c @@ -209,7 +209,7 @@ void CL_SetInfo(const char *key, const char *value, qboolean send, qboolean allo if (!allowmodel && (!strcasecmp(key, "pmodel") || !strcasecmp(key, "emodel"))) fail = true; for (i = 0;key[i];i++) - if (key[i] <= ' ' || key[i] == '\"') + if (ISWHITESPACE(key[i]) || key[i] == '\"') fail = true; for (i = 0;value[i];i++) if (value[i] == '\r' || value[i] == '\n' || value[i] == '\"') @@ -2097,10 +2097,10 @@ void CL_Locs_Reload_f(void) if (text < textend) text++; // trim trailing whitespace - while (lineend > linestart && lineend[-1] <= ' ') + while (lineend > linestart && ISWHITESPACE(lineend[-1])) lineend--; // trim leading whitespace - while (linestart < lineend && *linestart <= ' ') + while (linestart < lineend && ISWHITESPACE(*linestart)) linestart++; // check if this is a comment if (linestart + 2 <= lineend && !strncmp(linestart, "//", 2)) @@ -2117,7 +2117,7 @@ void CL_Locs_Reload_f(void) else maxs[i - 3] = atof(linetext); // now advance past the number - while (linetext < lineend && *linetext > ' ' && *linetext != ',') + while (linetext < lineend && !ISWHITESPACE(*linetext) && *linetext != ',') linetext++; // advance through whitespace if (linetext < lineend) @@ -2128,10 +2128,10 @@ void CL_Locs_Reload_f(void) limit = 6; // note: comma can be followed by whitespace } - if (*linetext <= ' ') + if (ISWHITESPACE(*linetext)) { // skip whitespace - while (linetext < lineend && *linetext <= ' ') + while (linetext < lineend && ISWHITESPACE(*linetext)) linetext++; } } diff --git a/cl_parse.c b/cl_parse.c index 77ffee39..d6b70ac2 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -2716,7 +2716,7 @@ static void CL_IPLog_Load(void) text++; if (line[0] == '/' && line[1] == '/') continue; // skip comments if anyone happens to add them - for (i = 0;i < len && line[i] > ' ';i++) + for (i = 0;i < len && !ISWHITESPACE(line[i]);i++) address[i] = line[i]; address[i] = 0; // skip exactly one space character diff --git a/cmd.c b/cmd.c index c9e5cb7b..73f55456 100644 --- a/cmd.c +++ b/cmd.c @@ -712,7 +712,7 @@ static const char *Cmd_GetDirectCvarValue(const char *varname, cmdalias_t *alias *is_multiple = true; // kill pre-argument whitespace - for (;*p && *p <= ' ';p++) + for (;*p && ISWHITESPACE(*p);p++) ; return p; @@ -1143,7 +1143,7 @@ static void Cmd_TokenizeString (const char *text) while (1) { // skip whitespace up to a /n - while (*text && *text <= ' ' && *text != '\r' && *text != '\n') + while (*text && ISWHITESPACE(*text) && *text != '\r' && *text != '\n') text++; // line endings: diff --git a/common.c b/common.c index e0cffe48..aac01fba 100644 --- a/common.c +++ b/common.c @@ -643,7 +643,7 @@ void Com_HexDumpToConsole(const unsigned char *data, int size) *cur++ = STRING_COLOR_TAG; *cur++ = STRING_COLOR_TAG; } - else if (d[j] >= ' ') + else if (d[j] >= (unsigned char) ' ') *cur++ = d[j]; else *cur++ = '.'; @@ -996,7 +996,7 @@ skipwhite: // UNIX: \n // Mac: \r // Windows: \r\n - for (;*data <= ' ' && ((*data != '\n' && *data != '\r') || !returnnewline);data++) + for (;ISWHITESPACE(*data) && ((*data != '\n' && *data != '\r') || !returnnewline);data++) { if (*data == 0) { @@ -1072,7 +1072,7 @@ skipwhite: else { // regular word - for (;*data > ' ';data++) + for (;!ISWHITESPACE(*data);data++) if (len < (int)sizeof(com_token) - 1) com_token[len++] = *data; com_token[len] = 0; @@ -1109,7 +1109,7 @@ skipwhite: // UNIX: \n // Mac: \r // Windows: \r\n - for (;*data <= ' ' && ((*data != '\n' && *data != '\r') || !returnnewline);data++) + for (;ISWHITESPACE(*data) && ((*data != '\n' && *data != '\r') || !returnnewline);data++) { if (*data == 0) { @@ -1186,7 +1186,7 @@ skipwhite: else { // regular word - for (;*data > ' ' && *data != '{' && *data != '}' && *data != ')' && *data != '(' && *data != ']' && *data != '[' && *data != ':' && *data != ',' && *data != ';';data++) + for (;!ISWHITESPACE(*data) && *data != '{' && *data != '}' && *data != ')' && *data != '(' && *data != ']' && *data != '[' && *data != ':' && *data != ',' && *data != ';';data++) if (len < (int)sizeof(com_token) - 1) com_token[len++] = *data; com_token[len] = 0; @@ -1223,7 +1223,7 @@ skipwhite: // UNIX: \n // Mac: \r // Windows: \r\n - for (;*data <= ' ' && ((*data != '\n' && *data != '\r') || !returnnewline);data++) + for (;ISWHITESPACE(*data) && ((*data != '\n' && *data != '\r') || !returnnewline);data++) { if (*data == 0) { @@ -1300,7 +1300,7 @@ skipwhite: else { // regular word - for (;*data > ' ' && *data != ',' && *data != ';' && *data != '{' && *data != '}' && *data != ')' && *data != '(' && *data != ']' && *data != '[' && *data != ':' && *data != ',' && *data != ';';data++) + for (;!ISWHITESPACE(*data) && *data != ',' && *data != ';' && *data != '{' && *data != '}' && *data != ')' && *data != '(' && *data != ']' && *data != '[' && *data != ':' && *data != ',' && *data != ';';data++) if (len < (int)sizeof(com_token) - 1) com_token[len++] = *data; com_token[len] = 0; @@ -1332,7 +1332,7 @@ int COM_ParseToken_Console(const char **datapointer) // skip whitespace skipwhite: - for (;*data <= ' ';data++) + for (;ISWHITESPACE(*data);data++) { if (*data == 0) { @@ -1368,7 +1368,7 @@ skipwhite: else { // regular word - for (;*data > ' ';data++) + for (;!ISWHITESPACE(*data);data++) if (len < (int)sizeof(com_token) - 1) com_token[len++] = *data; com_token[len] = 0; @@ -1693,7 +1693,7 @@ int COM_ReadAndTokenizeLine(const char **text, char **argv, int maxargc, char *t commentprefixlength = (int)strlen(commentprefix); while (*l && *l != '\n' && *l != '\r') { - if (*l > ' ') + if (!ISWHITESPACE(*l)) { if (commentprefixlength && !strncmp(l, commentprefix, commentprefixlength)) { @@ -1718,7 +1718,7 @@ int COM_ReadAndTokenizeLine(const char **text, char **argv, int maxargc, char *t } else { - while (*l > ' ') + while (!ISWHITESPACE(*l)) { if (tokenbuf >= tokenbufend) return -1; diff --git a/console.c b/console.c index da0f18a1..421e0379 100644 --- a/console.c +++ b/console.c @@ -1812,8 +1812,8 @@ qboolean GetMapList (const char *s, char *completedname, int completednamebuffer if (com_token[0] == '}') break; // skip leading whitespace - for (k = 0;com_token[k] && com_token[k] <= ' ';k++); - for (l = 0;l < (int)sizeof(keyname) - 1 && com_token[k+l] && com_token[k+l] > ' ';l++) + for (k = 0;com_token[k] && ISWHITESPACE(com_token[k]);k++); + for (l = 0;l < (int)sizeof(keyname) - 1 && com_token[k+l] && !ISWHITESPACE(com_token[k+l]);l++) keyname[l] = com_token[k+l]; keyname[l] = 0; if (!COM_ParseToken_Simple(&data, false, false)) diff --git a/host_cmd.c b/host_cmd.c index 4436ae5b..b80cf563 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -530,7 +530,7 @@ void Host_Savegame_to (const char *name) // convert space to _ to make stdio happy // LordHavoc: convert control characters to _ as well for (i=0 ; i 0 && (*text < ' ' || *text == ';')) + if((signed char) *text > 0 && ((signed char) *text < (signed char) ' ' || *text == ';')) return NULL; // block possible exploits against the parser/alias expansion while(s != endpos) @@ -2399,13 +2399,13 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat char *s = string + 5; char *endpos = string + length + 1; // one behind the NUL, so adding strlen+1 will eventually reach it char password[64]; - for (i = 0;*s > ' ';s++) + for (i = 0;!ISWHITESPACE(*s);s++) if (i < (int)sizeof(password) - 1) password[i++] = *s; - if(*s <= ' ' && s != endpos) // skip leading ugly space + if(ISWHITESPACE(*s) && s != endpos) // skip leading ugly space ++s; password[i] = 0; - if (password[0] > ' ') + if (!ISWHITESPACE(password[0])) { const char *userlevel = RCon_Authenticate(password, s, endpos); if(userlevel) diff --git a/prvm_cmds.c b/prvm_cmds.c index 696ffea0..63f17f29 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -45,7 +45,7 @@ void VM_Warning(const char *fmt, ...) void VM_CheckEmptyString (const char *s) { - if (s[0] <= ' ') + if (ISWHITESPACE(s[0])) PRVM_ERROR ("%s: Bad string", PRVM_NAME); } @@ -2291,7 +2291,7 @@ void VM_tokenize (void) break; // skip whitespace here to find token start pos - while(*p && (unsigned char) *p <= ' ') + while(*p && ISWHITESPACE(*p)) ++p; tokens_startpos[num_tokens] = p - string; @@ -2323,7 +2323,7 @@ void VM_tokenize_console (void) break; // skip whitespace here to find token start pos - while(*p && (unsigned char) *p <= ' ') + while(*p && ISWHITESPACE(*p)) ++p; tokens_startpos[num_tokens] = p - string; diff --git a/prvm_edict.c b/prvm_edict.c index 742e4b98..d8499c43 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -995,7 +995,7 @@ qboolean PRVM_ED_ParseEpair(prvm_edict_t *ent, ddef_t *key, const char *s, qbool break; case ev_float: - while (*s && *s <= ' ') + while (*s && ISWHITESPACE(*s)) s++; val->_float = atof(s); break; @@ -1003,12 +1003,12 @@ qboolean PRVM_ED_ParseEpair(prvm_edict_t *ent, ddef_t *key, const char *s, qbool case ev_vector: for (i = 0;i < 3;i++) { - while (*s && *s <= ' ') + while (*s && ISWHITESPACE(*s)) s++; if (!*s) break; val->vector[i] = atof(s); - while (*s > ' ') + while (!ISWHITESPACE(*s)) s++; if (!*s) break; @@ -1016,7 +1016,7 @@ qboolean PRVM_ED_ParseEpair(prvm_edict_t *ent, ddef_t *key, const char *s, qbool break; case ev_entity: - while (*s && *s <= ' ') + while (*s && ISWHITESPACE(*s)) s++; i = atoi(s); if (i >= prog->limit_edicts) diff --git a/quakedef.h b/quakedef.h index 3ddf1c73..6dc94ef1 100644 --- a/quakedef.h +++ b/quakedef.h @@ -354,5 +354,12 @@ void Sys_Shared_Init(void); // debug protocol exploits. #define DEMOMSG_CLIENT_TO_SERVER 0x80000000 +// In Quake, any char in 0..32 counts as whitespace +//#define ISWHITESPACE(ch) ((unsigned char) ch <= (unsigned char) ' ') +#define ISWHITESPACE(ch) (!(ch) || (ch) == ' ' || (ch) == '\t' || (ch) == '\r' || (ch) == '\n') + +// This also includes extended characters, and ALL control chars +#define ISWHITESPACEORCONTROL(ch) ((signed char) (ch) <= (signed char) ' ') + #endif diff --git a/sys_linux.c b/sys_linux.c index e2bc4e32..8e042f40 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -68,7 +68,7 @@ void Sys_PrintToTerminal(const char *text) #endif while(*text) { - int written = (int)write(1, text, (int)strlen(text)); + ssize_t written = write(1, text, strlen(text)); if(written <= 0) break; // sorry, I cannot do anything about this error - without an output text += written; @@ -87,7 +87,7 @@ double Sys_DoubleTime (void) if(sys_usenoclockbutbenchmark.integer) { benchmark_time += 1; - return benchmark_time / 1e6; + return ((double) benchmark_time) / 1e6; } #ifdef WIN32 #include diff --git a/sys_win.c b/sys_win.c index 5431221a..928d8422 100644 --- a/sys_win.c +++ b/sys_win.c @@ -269,7 +269,7 @@ char *Sys_ConsoleInput (void) break; default: - if (ch >= ' ') + if (ch >= (int) (unsigned char) ' ') { WriteFile(houtput, &ch, 1, &dummy, NULL); text[len] = ch; @@ -423,7 +423,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin // FIXME: this tokenizer is rather redundent, call a more general one while (*lpCmdLine && (com_argc < MAX_NUM_ARGVS)) { - while (*lpCmdLine && *lpCmdLine <= ' ') + while (*lpCmdLine && ISWHITESPACE(*lpCmdLine)) lpCmdLine++; if (!*lpCmdLine) @@ -443,7 +443,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin // unquoted word argv[com_argc] = lpCmdLine; com_argc++; - while (*lpCmdLine && *lpCmdLine > ' ') + while (*lpCmdLine && !ISWHITESPACE(*lpCmdLine)) lpCmdLine++; }