diff --git a/src/blua/lauxlib.c b/src/blua/lauxlib.c index 8e35f5f08..c7dfb4666 100644 --- a/src/blua/lauxlib.c +++ b/src/blua/lauxlib.c @@ -24,6 +24,8 @@ #include "lauxlib.h" +#include "lfastcmp.h" + #define FREELIST_REF 0 /* free list of references */ @@ -40,7 +42,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); lua_getinfo(L, "n", &ar); - if (strcmp(ar.namewhat, "method") == 0) { + if (fastcmp(ar.namewhat, "method")) { narg--; /* do not count `self' */ if (narg == 0) /* error is in the self argument itself? */ return luaL_error(L, "calling " LUA_QS " on bad self (%s)", @@ -97,7 +99,7 @@ LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, luaL_checkstring(L, narg); int i; for (i=0; lst[i]; i++) - if (strcmp(lst[i], name) == 0) + if (fastcmp(lst[i], name)) return i; return luaL_argerror(L, narg, lua_pushfstring(L, "invalid option " LUA_QS, name)); diff --git a/src/blua/lfastcmp.h b/src/blua/lfastcmp.h new file mode 100644 index 000000000..f25c59896 --- /dev/null +++ b/src/blua/lfastcmp.h @@ -0,0 +1,32 @@ +#ifndef __FASTCMP_H__ +#define __FASTCMP_H__ + +#include +#include + +// same as fastcmp but we cant use our fancy macros + +// returns false if s != c +// returns true if s == c +__attribute__((always_inline)) static inline bool fasticmp(const char *s, const char *c) +{ + for (; *s && toupper(*s) == toupper(*c); s++, c++) ; + return (*s == *c); // make sure both strings ended +} + +// case-sensitive of the above +__attribute__((always_inline)) static inline bool fastcmp(const char *s, const char *c) +{ + for (; *s && *s == *c; s++, c++) ; + return (*s == *c); // make sure both strings ended +} + +// length-limited of the above +// only true if both strings are at least l characters long AND match, case-sensitively! +__attribute__((always_inline)) static inline bool fastncmp(const char *s, const char *c, uint16_t l) +{ + for (; *s && *s == *c && --l; s++, c++) ; + return !l; // make sure you reached the end +} + +#endif diff --git a/src/command.c b/src/command.c index e73125649..676212703 100644 --- a/src/command.c +++ b/src/command.c @@ -879,7 +879,7 @@ static void COM_Help_f(void) { for (cmd = com_commands; cmd; cmd = cmd->next) { - if (strcmp(cmd->name, help)) + if (!fastcmp(cmd->name, help)) continue; CONS_Printf("\x82""Command %s:\n", cmd->name); @@ -1610,7 +1610,7 @@ void CV_ResetCheatNetVars(void) // Returns true if the variable's current value is its default value boolean CV_IsSetToDefault(consvar_t *v) { - return (!(strcmp(v->defaultvalue, v->string))); + return (fastcmp(v->defaultvalue, v->string)); } // If any cheats CVars are not at their default settings, return true. @@ -1622,7 +1622,7 @@ UINT8 CV_CheatsEnabled(void) consvar_t *cvar; for (cvar = consvar_vars; cvar; cvar = cvar->next) - if ((cvar->flags & CV_CHEAT) && strcmp(cvar->defaultvalue, cvar->string)) + if ((cvar->flags & CV_CHEAT) && !fastcmp(cvar->defaultvalue, cvar->string)) return 1; return 0; } @@ -1799,7 +1799,7 @@ void CV_AddValue(consvar_t *var, INT32 increment) } #define MINVAL 0 #define MAXVAL 1 - else if (var->PossibleValue[MINVAL].strvalue && !strcmp(var->PossibleValue[MINVAL].strvalue, "MIN")) + else if (var->PossibleValue[MINVAL].strvalue && fastcmp(var->PossibleValue[MINVAL].strvalue, "MIN")) { // SRB2Kart #ifdef PARANOIA if (!var->PossibleValue[MAXVAL].strvalue) @@ -2139,7 +2139,7 @@ void CV_SaveVariables(FILE *f) char stringtowrite[MAXTEXTCMD+1]; // Silly hack for Min/Max vars - if (!strcmp(cvar->string, "MAX") || !strcmp(cvar->string, "MIN")) + if (fastcmp(cvar->string, "MAX") || fastcmp(cvar->string, "MIN")) { if (cvar->flags & CV_FLOAT) sprintf(stringtowrite, "%f", FixedToFloat(cvar->value)); diff --git a/src/console.c b/src/console.c index 3959d9b98..062e6ebf3 100644 --- a/src/console.c +++ b/src/console.c @@ -1010,7 +1010,7 @@ boolean CON_Responder(event_t *ev) Lock_state(); // Only add command to history if it differs from previous one - if (strcmp(input.buffer, inputlines[(inputline-1) & 31])) + if (!fastcmp(input.buffer, inputlines[(inputline-1) & 31])) { inputline = (inputline+1) & 31; M_TextInputInit(&input, inputlines[inputline], CON_MAXPROMPTCHARS); diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 61afc0eb7..ad4ce5d09 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2179,7 +2179,7 @@ static void SL_InsertServer(serverinfo_pak* info, SINT8 node) if (info->subversion != SUBVERSION) return; // Close, but no cigar. - if (strcmp(info->application, SRB2APPLICATION)) + if (!fastcmp(info->application, SRB2APPLICATION)) return;/* that's a different mod */ i = serverlistcount++; @@ -2224,7 +2224,7 @@ void CL_QueryServerList (msg_server_t *server_list) // thwart nefarious servers who lie to the MS. /* lol bruh, that version COMES from the servers */ - //if (strcmp(version, server_list[i].version) == 0) + //if (fastcmp(version, server_list[i].version)) { INT32 node = I_NetMakeNodewPort(server_list[i].ip, server_list[i].port); if (node == -1) diff --git a/src/d_main.c b/src/d_main.c index 0f3793eb2..782addc64 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1295,7 +1295,7 @@ static void IdentifyVersion(void) } #if (1) // reduce the amount of findfile by only using full cwd in this func - if (strcmp(tempsrb2path, srb2waddir)) + if (!fastcmp(tempsrb2path, srb2waddir)) #endif { strlcpy(srb2path, srb2waddir, sizeof (srb2path)); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index f86041a8f..ca6551ca3 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1507,9 +1507,9 @@ static void SendNameAndColor(void) CV_StealthSet(&cv_playercolor, cv_playercolor.defaultvalue); } - if (!strcmp(cv_playername.string, player_names[consoleplayer]) + if (fastcmp(cv_playername.string, player_names[consoleplayer]) && cv_playercolor.value == players[consoleplayer].skincolor - && !strcmp(cv_skin.string, skins[players[consoleplayer].skin].name)) + && fastcmp(cv_skin.string, skins[players[consoleplayer].skin].name)) return; // We'll handle it later if we're not playing. @@ -2321,8 +2321,8 @@ static void Command_Playdemo_f(void) CONS_Printf(M_GetText("Playing back demo '%s'.\n"), name); - demo.loadfiles = strcmp(COM_Argv(2), "-addfiles") == 0; - demo.ignorefiles = strcmp(COM_Argv(2), "-force") == 0; + demo.loadfiles = fastcmp(COM_Argv(2), "-addfiles"); + demo.ignorefiles = fastcmp(COM_Argv(2), "-force"); // Internal if no extension, external if one exists // If external, convert the file name to a path in SRB2's home directory @@ -5208,14 +5208,14 @@ static void Ringslinger_OnChange(void) static void Gravity_OnChange(void) { if (!M_SecretUnlocked(SECRET_PANDORA) && !netgame && !cv_debug - && strcmp(cv_gravity.string, cv_gravity.defaultvalue)) + && !fastcmp(cv_gravity.string, cv_gravity.defaultvalue)) { CONS_Printf(M_GetText("You haven't earned this yet.\n")); CV_StealthSet(&cv_gravity, cv_gravity.defaultvalue); return; } #ifndef NETGAME_GRAVITY - if(netgame) + if (netgame) { CV_StealthSet(&cv_gravity, cv_gravity.defaultvalue); return; diff --git a/src/d_netfil.c b/src/d_netfil.c index 5a1272172..f279eaee0 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -946,17 +946,17 @@ void Got_Filetxpak(void) char *filename = file->filename; static INT32 filetime = 0; - if (!(strcmp(filename, "srb2.srb") - //&& strcmp(filename, "srb2.wad") - //&& strcmp(filename, "patch.dta") - //&& strcmp(filename, "music.dta") - && strcmp(filename, "gfx.kart") - && strcmp(filename, "textures.kart") - && strcmp(filename, "chars.kart") - && strcmp(filename, "maps.kart") - && strcmp(filename, "sounds.kart") - && strcmp(filename, "music.kart") - && strcmp(filename, "patch.kart") + if ((fastcmp(filename, "srb2.srb") + //|| fastcmp(filename, "srb2.wad") + //|| fastcmp(filename, "patch.dta") + //|| fastcmp(filename, "music.dta") + || fastcmp(filename, "gfx.kart") + || fastcmp(filename, "textures.kart") + || fastcmp(filename, "chars.kart") + || fastcmp(filename, "maps.kart") + || fastcmp(filename, "sounds.kart") + || fastcmp(filename, "music.kart") + || fastcmp(filename, "patch.kart") )) I_Error("Tried to download \"%s\"", filename); @@ -1197,7 +1197,7 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet } // next, check SRB2's "home" directory (if non-'.') - if (strcmp(srb2home, ".")) + if (!fastcmp(srb2home, ".")) { homecheck = filesearch(filename, srb2home, wantedmd5sum, completepath, 10); @@ -1209,7 +1209,7 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet } // next, check SRB2's "path" directory (also if non-'.') - if (strcmp(srb2path, ".")) + if (!fastcmp(srb2path, ".")) { homecheck = filesearch(filename, srb2path, wantedmd5sum, completepath, 10); @@ -1554,7 +1554,7 @@ CURLGetLogin (const char *url, HTTP_login ***return_prev_next) ( login = (*prev_next)); prev_next = &login->next ){ - if (strcmp(login->url, url) == 0) + if (fastcmp(login->url, url) != 0) { if (return_prev_next) (*return_prev_next) = prev_next; diff --git a/src/d_protocol.c b/src/d_protocol.c index 6ceb05100..963d8e587 100644 --- a/src/d_protocol.c +++ b/src/d_protocol.c @@ -211,12 +211,12 @@ void D_SetupProtocol(void) if (result) { - if (strcmp(buffer, "no") == 0) + if (!fastcmp(buffer, "no")) { fclose(fp); return; } - else if (strcmp(buffer, exe_path) != 0) + else if (fastcmp(buffer, exe_path)) { // overwrite fclose(fp); diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 88e6b4641..0d74e636f 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1715,9 +1715,9 @@ char *I_GetUserName(void) strncpy(username, p, MAXPLAYERNAME); } - - if (strcmp(username, "") != 0) + if (!fastcmp(username, "")) return username; + return NULL; // dummy for platform independent version } diff --git a/src/discord.c b/src/discord.c index f94cd574d..8f937cfc1 100644 --- a/src/discord.c +++ b/src/discord.c @@ -277,7 +277,7 @@ static void DRPC_HandleJoinRequest(const DiscordUser *requestUser) while (append != NULL) { // CHECK FOR DUPES!! Ignore any that already exist from the same user. - if (!strcmp(newRequest->userID, append->userID)) + if (fastcmp(newRequest->userID, append->userID)) { Discord_Respond(newRequest->userID, DISCORD_REPLY_IGNORE); DRPC_RemoveRequest(newRequest); @@ -419,7 +419,7 @@ static const char *DRPC_GetServerIP(void) // If you're connected if (I_GetNodeAddress && (address = I_GetNodeAddress(servernode)) != NULL) { - if (strcmp(address, "self")) + if (!fastcmp(address, "self")) { // We're not the server, so we could successfully get the IP! // No need to do anything else :) @@ -684,7 +684,7 @@ void DRPC_UpdatePresence(void) // Character image while (supportedSkins[checkSkin] != NULL) { - if (!strcmp(skins[players[consoleplayer].skin].name, supportedSkins[checkSkin])) + if (fastcmp(skins[players[consoleplayer].skin].name, supportedSkins[checkSkin])) { snprintf(charimg, 21, "char%s", supportedSkins[checkSkin]); discordPresence.smallImageKey = charimg; diff --git a/src/doomdef.h b/src/doomdef.h index b633d231a..dfc351685 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -69,6 +69,8 @@ extern "C" { #include #include +#include "fastcmp.h" + #ifdef _WIN32 #include #endif diff --git a/src/filesrch.c b/src/filesrch.c index 628a221c2..b9821d368 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -353,7 +353,7 @@ void searchfilemenu(char *tempname) { for (i = first; i < sizedirmenu; i++) { - if (!strcmp(dirmenu[i]+DIR_STRING, tempname)) + if (fastcmp(dirmenu[i]+DIR_STRING, tempname)) { dir_on[menudepthleft] = i; break; @@ -400,7 +400,7 @@ void searchfilemenu(char *tempname) { if (filemenucmp(coredirmenu[i]+DIR_STRING, localmenusearch)) { - if (tempname && !strcmp(coredirmenu[i]+DIR_STRING, tempname)) + if (tempname && fastcmp(coredirmenu[i]+DIR_STRING, tempname)) { dir_on[menudepthleft] = sizedirmenu; Z_Free(tempname); @@ -587,7 +587,7 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) nameonly(filenamebuf[i]); } - if (strcmp(dent->d_name, filenamebuf[i])) + if (!fastcmp(dent->d_name, filenamebuf[i])) continue; if (cv_addons_md5.value && !checkfilemd5(menupath, wadfiles[i]->md5sum)) @@ -598,11 +598,11 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) } else if (ext == EXT_TXT) { - if (!strncmp(dent->d_name, "log-", 4) || !strcmp(dent->d_name, "errorlog.txt")) + if (!strncmp(dent->d_name, "log-", 4) || fastcmp(dent->d_name, "errorlog.txt")) ext |= EXT_LOADED; } - if (!strcmp(dent->d_name, configfile)) + if (fastcmp(dent->d_name, configfile)) ext |= EXT_LOADED; } diff --git a/src/g_game.c b/src/g_game.c index 848c60168..0876afc40 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3475,7 +3475,8 @@ void G_LoadGameData(void) if (READUINT32(save.p) != 0xFCAFE211) { const char *gdfolder = "the SRB2Kart folder"; - if (strcmp(srb2home,".")) + + if (!fastcmp(srb2home,".")) gdfolder = srb2home; Z_Free(save.buffer); @@ -3559,7 +3560,8 @@ void G_LoadGameData(void) datacorrupt: { const char *gdfolder = "the SRB2Kart folder"; - if (strcmp(srb2home,".")) + + if (!fastcmp(srb2home,".")) gdfolder = srb2home; Z_Free(save.buffer); @@ -3770,7 +3772,8 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) memset(vcheck, 0, sizeof (vcheck)); sprintf(vcheck, "version %d", VERSION); - if (strcmp((const char *)save.p, (const char *)vcheck)) + + if (!fastcmp((const char *)save.p, (const char *)vcheck)) { #ifdef SAVEGAME_OTHERVERSIONS M_StartMessage(M_GetText("Save game from different version.\nYou can load this savegame, but\nsaving afterwards will be disabled.\n\nDo you want to continue anyway?\n\n(Press 'Y' to confirm)\n"), @@ -4048,7 +4051,7 @@ char *G_BuildMapTitle(INT32 mapnum) if (!mapheaderinfo[mapnum-1]) P_AllocMapHeader(mapnum-1); - if (strcmp(mapheaderinfo[mapnum-1]->lvlttl, "")) + if (!fastcmp(mapheaderinfo[mapnum-1]->lvlttl, "")) { size_t len = 1; const char *zonetext = NULL; diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index a9b072c74..1ce724b58 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -5814,7 +5814,7 @@ static void COM_HWR_glinfo(void) { argv = COM_Argv(i); - if (strcmp(argv, "--list-extensions") == 0 || strcmp(argv, "-l") == 0) + if (fastcmp(argv, "--list-extensions")|| fastcmp(argv, "-l")) { list_extensions = 1; } diff --git a/src/hardware/hw_model.c b/src/hardware/hw_model.c index 6a9825402..77a995ed0 100644 --- a/src/hardware/hw_model.c +++ b/src/hardware/hw_model.c @@ -163,22 +163,22 @@ model_t *LoadModel(const char *filename, int ztag) return NULL; } - if (!strcmp(extension, ".md3")) + if (fastcmp(extension, ".md3")) { if (!(model = MD3_LoadModel(filename, ztag, false))) return NULL; } - else if (!strcmp(extension, ".md3s")) // MD3 that will be converted in memory to use full floats + else if (fastcmp(extension, ".md3s")) // MD3 that will be converted in memory to use full floats { if (!(model = MD3_LoadModel(filename, ztag, true))) return NULL; } - else if (!strcmp(extension, ".md2")) + else if (fastcmp(extension, ".md2")) { if (!(model = MD2_LoadModel(filename, ztag, false))) return NULL; } - else if (!strcmp(extension, ".md2s")) + else if (fastcmp(extension, ".md2s")) { if (!(model = MD2_LoadModel(filename, ztag, true))) return NULL; diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 1eba4f2cf..2523735ee 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -56,7 +56,7 @@ static const char *whitelist[] = { // Allow scripters to write files of these ty static int StartsWith(const char *a, const char *b) // this is wolfs being lazy yet again { - if(strncmp(a, b, strlen(b)) == 0) return 1; + if (strncmp(a, b, strlen(b)) == 0) return 1; return 0; }; @@ -78,6 +78,7 @@ static int lib_open(lua_State *L) break; } } + if (strstr(filename, "..") || strchr(filename, ':') || StartsWith(filename, "\\") || StartsWith(filename, "/") || !pass) { diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index f04fe089e..8fa92cdce 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -416,9 +416,9 @@ static int lib_cvRegisterVar(lua_State *L) cvpv[to].value = val; \ cvpv[to].strvalue = strval; for (int j = 0; j < i; j++) { - if (!strcmp(cvpv[j].strvalue, "MIN") && j != 0) { + if (fastcmp(cvpv[j].strvalue, "MIN") && j != 0) { SWAP(j, 0) - } else if (!strcmp(cvpv[j].strvalue, "MAX") && j != 1) { + } else if (fastcmp(cvpv[j].strvalue, "MAX") && j != 1) { SWAP(j, 1) } } diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index c2016b771..e571f7649 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -92,7 +92,7 @@ FUNCINLINE static ATTRINLINE unsigned hook_in_list for (type = 0; list[type] != NULL; ++type) { - if (strcmp(name, list[type]) == 0) + if (fastcmp(name, list[type])) break; } @@ -254,7 +254,7 @@ static int lib_addHook(lua_State *L) { add_hook(&hookIds[type]); } - /*else if (strcmp(name, "HUD") == 0) // ehh this is cool and all, but i dont want modders potentially breaking vanilla clients lol + /*else if (fastcmp(name, "HUD")) // ehh this is cool and all, but i dont want modders potentially breaking vanilla clients lol { add_hud_hook(L, 3); }*/ @@ -840,7 +840,7 @@ typedef struct { FUNCINLINE static ATTRINLINE boolean checkbotkey(const char *field) { - return lua_toboolean(gL, -1) && strcmp(lua_tostring(gL, -2), field) == 0; + return lua_toboolean(gL, -1) && fastcmp(lua_tostring(gL, -2), field); } static void res_botai(Hook_State *hook) diff --git a/src/m_aatree.c b/src/m_aatree.c index 34e8e1d87..f78355eaf 100644 --- a/src/m_aatree.c +++ b/src/m_aatree.c @@ -183,7 +183,7 @@ static aatree_node_t *M_AATreeSetString_Node(aatree_node_t *node, UINT32 flags, else { aatree_entry_t *entry = node->value; - if (entry != NULL && strcmp(entry->key, key) != 0) + if (entry != NULL && !fastcmp(entry->key, key)) entry = entry->next; if (entry != NULL) { @@ -252,7 +252,7 @@ void *M_AATreeGetString(aatree_t *aatree, const char *key) I_Assert((aatree->flags & AATREE_STRING) == AATREE_STRING); UINT32 hash = FNV1a_HashString(key); aatree_entry_t *entry = M_AATreeGet_Node(aatree->root, hash); - while (entry != NULL && strcmp(entry->key, key) != 0) + while (entry != NULL && !fastcmp(entry->key, key)) entry = entry->next; return entry != NULL ? entry->value : NULL; } diff --git a/src/m_menu.c b/src/m_menu.c index b7ea3cc71..d70ec6d57 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3698,10 +3698,10 @@ static void M_HandleAddons(INT32 choice) break; case EXT_TXT: case EXT_CFG: - if ((strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, CONFIGFILENAME) == 0) - || (strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, AUTOLOADCONFIGFILENAME) == 0) - || (strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, "kartserv.cfg") == 0) - || (strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, "kartexec.cfg") == 0)) + if (fastcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, CONFIGFILENAME) + || fastcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, AUTOLOADCONFIGFILENAME) + || fastcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, "kartserv.cfg") + || fastcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, "kartexec.cfg")) { M_StartMessage(va("%c%s\x80\nYou can't autoload this builds' base console scripts, silly!\n They're already autoloaded on startup! \n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),NULL,MM_NOTHING); S_StartSound(NULL, sfx_s26d); @@ -3809,7 +3809,7 @@ static void ReplayNamesLoadThread(void* userdata) Lock_search_state(); - if (strcmp(menupath, replaydirpath) == 0) + if (fastcmp(menupath, replaydirpath)) { memcpy(demolist_all, demolist_all_local, sizeof(menudemo_t)*sizedirmenu); replaynamesloaded = true; @@ -6778,7 +6778,7 @@ static int ServerListEntryComparator_##key(const void *entry1, const void *entry const serverelem_t *sa = (const serverelem_t*)entry1, *sb = (const serverelem_t*)entry2; \ if (sa->info.key != sb->info.key) \ return sa->info.key - sb->info.key; \ - return strcmp(sa->info.servername, sb->info.servername); \ + return !fastcmp(sa->info.servername, sb->info.servername); \ } // This does descending instead of ascending. @@ -6788,7 +6788,7 @@ static int ServerListEntryComparator_##key##_reverse(const void *entry1, const v const serverelem_t *sa = (const serverelem_t*)entry1, *sb = (const serverelem_t*)entry2; \ if (sb->info.key != sa->info.key) \ return sb->info.key - sa->info.key; \ - return strcmp(sb->info.servername, sa->info.servername); \ + return !fastcmp(sb->info.servername, sa->info.servername); \ } SERVER_LIST_ENTRY_COMPARATOR(time) @@ -6809,8 +6809,8 @@ static int ServerListEntryComparator_modified(const void *entry1, const void *en if (modstate_a != modstate_b) return modstate_a - modstate_b; - // Default to strcmp. - return strcmp(sa->info.servername, sb->info.servername); + // Default to !fastcmp. + return !fastcmp(sa->info.servername, sb->info.servername); } void M_SortServerList(void) @@ -8787,7 +8787,7 @@ static boolean M_QuitMultiPlayerMenu(void) size_t l; // send name if changed - if (strcmp(setupm_name, setupm_cvname->string)) + if (!fastcmp(setupm_name, setupm_cvname->string)) { // remove trailing whitespaces for (l= strlen(setupm_name)-1; @@ -9448,7 +9448,7 @@ static void M_VideoModeMenu(INT32 choice) // VESA mode, which is always a higher modenum for (j = 0; j < vidm_nummodes; j++) { - if (!strcmp(modedescs[j].desc, desc)) + if (fastcmp(modedescs[j].desc, desc)) { // mode(0): 320x200 is always standard VGA, not vesa if (modedescs[j].modenum) diff --git a/src/m_perfstats.c b/src/m_perfstats.c index 7384a6086..75aad72e2 100644 --- a/src/m_perfstats.c +++ b/src/m_perfstats.c @@ -916,7 +916,7 @@ static void draw_think_frame_stats(int hook_length, ps_hookinfo_t *hook) int len = (int)strlen(str); char* str_ptr; - if (strcmp(".lua", str + len - 4) == 0) + if (fastcmp(".lua", str + len - 4)) { str[len-4] = '\0'; // remove .lua at end } diff --git a/src/p_saveg.c b/src/p_saveg.c index d3a162e2d..570e8e1f0 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3391,7 +3391,7 @@ FUNCINLINE static ATTRINLINE void P_UnArchiveSPGame(savebuffer_t *save, INT16 ma READSTRINGN(save->p, testname, sizeof(testname)); - if (strcmp(testname, timeattackfolder)) + if (!fastcmp(testname, timeattackfolder)) { if (modifiedgame) I_Error("Save game not for this modification."); diff --git a/src/r_data.c b/src/r_data.c index 93ad621fa..893252571 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -867,7 +867,7 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) I_Error("Error parsing TEXTURES lump: Unexpected end of file where comma after \"%s\"'s patch name should be",patchName); } - if (strcmp(texturesToken,",")!=0) + if (!fastcmp(texturesToken,",")) { I_Error("Error parsing TEXTURES lump: Expected \",\" after %s's patch name, got \"%s\"",patchName,texturesToken); } @@ -907,7 +907,7 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) I_Error("Error parsing TEXTURES lump: Unexpected end of file where comma after patch \"%s\"'s x coordinate should be",patchName); } - if (strcmp(texturesToken,",")!=0) + if (!fastcmp(texturesToken,",")) { I_Error("Error parsing TEXTURES lump: Expected \",\" after patch \"%s\"'s x coordinate, got \"%s\"",patchName,texturesToken); } @@ -996,7 +996,7 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where comma after texture \"%s\"'s name should be",newTextureName); } - else if (strcmp(texturesToken,",")!=0) + else if (!fastcmp(texturesToken,",")) { I_Error("Error parsing TEXTURES lump: Expected \",\" after texture \"%s\"'s name, got \"%s\"",newTextureName,texturesToken); } @@ -1030,7 +1030,7 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where comma after texture \"%s\"'s width should be",newTextureName); } - if (strcmp(texturesToken,",")!=0) + if (!fastcmp(texturesToken,",")) { I_Error("Error parsing TEXTURES lump: Expected \",\" after texture \"%s\"'s width, got \"%s\"",newTextureName,texturesToken); } @@ -1066,7 +1066,7 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) I_Error("Error parsing TEXTURES lump: Unexpected end of file where open curly brace for texture \"%s\" should be",newTextureName); } - if (strcmp(texturesToken,"{")==0) + if (fastcmp(texturesToken,"{")) { if (actuallyLoadTexture) { @@ -1084,7 +1084,7 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where patch definition for texture \"%s\" should be",newTextureName); } - while (strcmp(texturesToken,"}")!=0) + while (!fastcmp(texturesToken,"}")) { if (stricmp(texturesToken, "PATCH")==0) { @@ -1334,8 +1334,9 @@ lumpnum_t R_GetFlatNumForName(const char *name) if (lump == LUMPERROR) { - if (strcmp(name, SKYFLATNAME)) + if (!fastcmp(name, SKYFLATNAME)) CONS_Debug(DBG_SETUP, "R_GetFlatNumForName: Could not find flat %.8s\n", name); + lump = W_CheckNumForName("REDFLR"); } diff --git a/src/r_patch.cpp b/src/r_patch.cpp index 09aca078a..1e09ae7bb 100644 --- a/src/r_patch.cpp +++ b/src/r_patch.cpp @@ -63,7 +63,7 @@ static void R_ParseSpriteInfoFrame(spriteinfo_t *info) I_Error("Error parsing SPRTINFO lump: Missing sprite info"); else { - if (strcmp(sprinfoToken,"{")==0) + if (fastcmp(sprinfoToken,"{")) { Z_Free(sprinfoToken); sprinfoToken = M_GetToken(NULL); @@ -71,7 +71,7 @@ static void R_ParseSpriteInfoFrame(spriteinfo_t *info) { I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite info should be"); } - while (strcmp(sprinfoToken,"}")!=0) + while (!fastcmp(sprinfoToken,"}")) { if (stricmp(sprinfoToken, "XPIVOT")==0) { @@ -175,7 +175,7 @@ static void R_ParseSpriteInfo(boolean spr2) { I_Error("Error parsing SPRTINFO lump: Unexpected end of file where open curly brace for sprite \"%s\" should be",newSpriteName); } - if (strcmp(sprinfoToken,"{")==0) + if (fastcmp(sprinfoToken,"{")) { Z_Free(sprinfoToken); sprinfoToken = M_GetToken(NULL); @@ -183,7 +183,7 @@ static void R_ParseSpriteInfo(boolean spr2) { I_Error("Error parsing SPRTINFO lump: Unexpected end of file where definition for sprite \"%s\" should be",newSpriteName); } - while (strcmp(sprinfoToken,"}")!=0) + while (!fastcmp(sprinfoToken,"}")) { if (stricmp(sprinfoToken, "SKIN")==0) { diff --git a/src/r_skins.c b/src/r_skins.c index 9d289f936..26cd84afa 100644 --- a/src/r_skins.c +++ b/src/r_skins.c @@ -375,7 +375,7 @@ static UINT16 W_CheckForSkinMarkerInPwad(UINT16 wadid, UINT16 startlump) } //sort function for sorting skin names -static int skinSortFunc(const void *a, const void *b) //tbh i have no clue what the naming conventions for local functions are +static int skinSortFunc(const void *a, const void *b) // tbh i have no clue what the naming conventions for local functions are { const skin_t *in1 = &skins[*(const UINT8 *)a]; const skin_t *in2 = &skins[*(const UINT8 *)b]; @@ -383,22 +383,22 @@ static int skinSortFunc(const void *a, const void *b) //tbh i have no clue what const UINT8 val_a = *((const UINT8 *)a); const UINT8 val_b = *((const UINT8 *)b); - //return (strcmp(in1->realname, in2->realname) < 0) || (strcmp(in1->realname, in2->realname) ==); + // return (strcmp(in1->realname, in2->realname) < 0) || (strcmp(in1->realname, in2->realname) ==); switch (cv_skinselectgridsort.value) { case SKINMENUSORT_REALNAME: //CONS_Printf("Sorting by realname\n"); // check name - if ((temp = strcmp(in1->realname, in2->realname))) + if ((temp = !fastcmp(in1->realname, in2->realname))) return temp; // sort by internal name - return strcmp(in1->name, in2->name); + return !fastcmp(in1->name, in2->name); break; case SKINMENUSORT_NAME: //CONS_Printf("Sorting by name\n"); - return strcmp(in1->name, in2->name); + return !fastcmp(in1->name, in2->name); break; case SKINMENUSORT_SPEED: @@ -414,10 +414,10 @@ static int skinSortFunc(const void *a, const void *b) //tbh i have no clue what else if (in2->kartweight < in1->kartweight) return 1; // then check name - if ((temp = strcmp(in1->realname, in2->realname))) + if ((temp = !fastcmp(in1->realname, in2->realname))) return temp; // sort by internal name - return strcmp(in1->name, in2->name); + return !fastcmp(in1->name, in2->name); break; case SKINMENUSORT_WEIGHT: @@ -433,10 +433,10 @@ static int skinSortFunc(const void *a, const void *b) //tbh i have no clue what else if (in2->kartspeed < in1->kartspeed) return 1; // then check name - if ((temp = strcmp(in1->realname, in2->realname))) + if ((temp = !fastcmp(in1->realname, in2->realname))) return temp; // sort by internal name - return strcmp(in1->name, in2->name); + return !fastcmp(in1->name, in2->name); break; case SKINMENUSORT_PREFCOLOR: @@ -447,10 +447,10 @@ static int skinSortFunc(const void *a, const void *b) //tbh i have no clue what else if (in2->prefcolor < in1->prefcolor) return 1; // then check name - if ((temp = strcmp(in1->realname, in2->realname))) + if ((temp = !fastcmp(in1->realname, in2->realname))) return temp; // sort by internal name - return strcmp(in1->name, in2->name); + return !fastcmp(in1->name, in2->name); break; case SKINMENUSORT_ID: @@ -467,11 +467,12 @@ static int skinSortFunc(const void *a, const void *b) //tbh i have no clue what return 1; default: - return strcmp(in1->name, in2->name); + return !fastcmp(in1->name, in2->name); break; } - //im scared this somehow will sometimes end up here so im gonna add this here just to be safe - return strcmp(in1->name, in2->name); + + // im scared this somehow will sometimes end up here so im gonna add this here just to be safe + return !fastcmp(in1->name, in2->name); } void sortSkinGrid(void) diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index a528796eb..edd685327 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -35,9 +35,6 @@ #define _CREATE_DLL_ // necessary for Unix AND Windows -#define GETFUNC(func) \ - else if (0 == strcmp(#func, funcName)) \ - funcPointer = &func \ // // /** \brief The *hwSym function diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 20ca205bb..0bd0179d1 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -2261,8 +2261,9 @@ char *I_GetUserName(void) } - if (strcmp(username, "") != 0) + if (!fastcmp(username, "")) return username; + return NULL; // dummy for platform independent version } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index c3e0d1afb..d548dbd0e 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -992,7 +992,7 @@ static void Impl_HandleControllerAddedEvent(SDL_Event evt) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (!strcmp(cv_usejoystick[i].string, "0") || !cv_usejoystick[i].value) + if (fastcmp(cv_usejoystick[i].string, "0") || !cv_usejoystick[i].value) cv_usejoystick[i].value = 0; else if (atoi(cv_usejoystick[i].string) <= I_NumJoys() // don't mess if we intentionally set higher than NumJoys && cv_usejoystick[i].value) // update the cvar ONLY if a device exists @@ -1064,7 +1064,7 @@ static void Impl_HandleControllerRemovedEvent(void) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (!strcmp(cv_usejoystick[i].string, "0")) + if (fastcmp(cv_usejoystick[i].string, "0")) { cv_usejoystick[i].value = 0; } diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index ce612d016..e029b3316 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -170,8 +170,8 @@ boolean OglSdlSurface(INT32 w, INT32 h) } } - if (strcmp((const char*)gl_renderer, "GDI Generic") == 0 && - strcmp((const char*)gl_version, "1.1.0") == 0) + if (fastcmp((const char*)gl_renderer, "GDI Generic") && + fastcmp((const char*)gl_version, "1.1.0")) { // Oh no... Windows gave us the GDI Generic rasterizer, so something is wrong... // The game will crash later on when unsupported OpenGL commands are encountered. diff --git a/src/v_video.c b/src/v_video.c index 6d5eb0fa7..e94363752 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -23,7 +23,6 @@ #include "r_main.h" #include "r_fps.h" #include "console.h" - #include "i_video.h" // rendermode #include "z_zone.h" #include "m_misc.h" @@ -134,7 +133,7 @@ static boolean InitCube(void) if (!loaded_config) return false; -#define diffcons(cv) (strcmp(cv.string, cv.defaultvalue)) +#define diffcons(cv) (!fastcmp(cv.string, cv.defaultvalue)) #define diffconsgamma(cv) (cv.value != 0) #define diffconssat(cv) (cv.value != 10) @@ -596,7 +595,7 @@ void V_ResetPaletteCVars(void) if (!loaded_config) return; -#define diffcons(cv) (strcmp(cv.string, cv.defaultvalue)) +#define diffcons(cv) (!fastcmp(cv.string, cv.defaultvalue)) if diffcons(cv_palette) CV_StealthSetValue(&cv_palette, atoi(cv_palette.defaultvalue)); if diffcons(cv_palettenum)