Fix WinNT server builds by not using snprintf and updating FS_FixupFileCase.

This commit is contained in:
Marco Cawthorne 2023-06-23 14:32:20 -07:00
parent 8482809f18
commit 2fbf78579d
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
2 changed files with 22 additions and 21 deletions

View File

@ -762,7 +762,7 @@ static void Cmd_Exec_f (void)
f = fs_manifest->mainconfig; f = fs_manifest->mainconfig;
if (!*f) if (!*f)
f = "config"; f = "config";
snprintf(name, sizeof(name)-5, "configs/%s", f); Q_snprintfz(name, sizeof(name)-5, "configs/%s", f);
COM_DefaultExtension(name, ".cfg", sizeof(name)); COM_DefaultExtension(name, ".cfg", sizeof(name));
} }
else else
@ -1190,7 +1190,7 @@ static void Cmd_Alias_f (void)
// check for overlap with a command // check for overlap with a command
if (Cmd_Exists (s)) if (Cmd_Exists (s))
{ //commands always take precedence over aliases (so mods can't clobber 'quit' etc), so creating an alias with one of these names is stupid. always try to rename them. { //commands always take precedence over aliases (so mods can't clobber 'quit' etc), so creating an alias with one of these names is stupid. always try to rename them.
if (Cmd_IsInsecure() && snprintf(cmd, sizeof(cmd), "%s_a", s) < sizeof(cmd)) if (Cmd_IsInsecure() && Q_snprintfz(cmd, sizeof(cmd), "%s_a", s) < sizeof(cmd))
{ {
if (Cmd_Exists (cmd)) if (Cmd_Exists (cmd))
{ {
@ -1210,7 +1210,7 @@ static void Cmd_Alias_f (void)
{ //aliases take precedence over cvars (while cvars can be set via 'set'), so user's choice. { //aliases take precedence over cvars (while cvars can be set via 'set'), so user's choice.
if (Cvar_FindVar (s)) if (Cvar_FindVar (s))
{ {
if (Cmd_IsInsecure() && snprintf(cmd, sizeof(cmd), "%s_a", s) < sizeof(cmd)) if (Cmd_IsInsecure() && Q_snprintfz(cmd, sizeof(cmd), "%s_a", s) < sizeof(cmd))
{ {
Con_Printf (S_COLOR_RED"alias %s: renamed to %s due to cvar conflict\n", s, cmd); Con_Printf (S_COLOR_RED"alias %s: renamed to %s due to cvar conflict\n", s, cmd);
s = cmd; s = cmd;
@ -4147,7 +4147,7 @@ static void Cmd_WriteConfig_f(void)
else if (!Q_strcasecmp(Cmd_Argv(0), "saveconfig")) else if (!Q_strcasecmp(Cmd_Argv(0), "saveconfig"))
{ {
//dpcompat: this variation allows writing to any path. at least force the extension. //dpcompat: this variation allows writing to any path. at least force the extension.
snprintf(fname, sizeof(fname), "%s", filename); Q_snprintfz(fname, sizeof(fname), "%s", filename);
COM_RequireExtension(fname, ".cfg", sizeof(fname)); COM_RequireExtension(fname, ".cfg", sizeof(fname));
if (Cmd_IsInsecure() && strncmp(fname, "data/", 5)) if (Cmd_IsInsecure() && strncmp(fname, "data/", 5))
@ -4175,7 +4175,7 @@ static void Cmd_WriteConfig_f(void)
Con_Printf (CON_ERROR "Couldn't write config %s\n",filename); Con_Printf (CON_ERROR "Couldn't write config %s\n",filename);
return; return;
} }
snprintf(fname, sizeof(fname), "configs/%s", filename); Q_snprintfz(fname, sizeof(fname), "configs/%s", filename);
COM_DefaultExtension(fname, ".cfg", sizeof(fname)); COM_DefaultExtension(fname, ".cfg", sizeof(fname));
FS_NativePath(fname, FS_BASEGAMEONLY, sysname, sizeof(sysname)); FS_NativePath(fname, FS_BASEGAMEONLY, sysname, sizeof(sysname));

View File

@ -2308,7 +2308,7 @@ qboolean FS_NativePath(const char *fname, enum fs_relative relativeto, char *out
if (relativeto == FS_SYSTEM) if (relativeto == FS_SYSTEM)
{ {
//system is already the native path. we can just pass it through. perhaps we should clean it up first however, although that's just making sure all \ are / //system is already the native path. we can just pass it through. perhaps we should clean it up first however, although that's just making sure all \ are /
snprintf(out, outlen, "%s", fname); Q_snprintfz(out, outlen, "%s", fname);
for (; *out; out++) for (; *out; out++)
{ {
@ -2337,36 +2337,36 @@ qboolean FS_NativePath(const char *fname, enum fs_relative relativeto, char *out
case FS_GAME: //this is really for diagnostic type stuff... case FS_GAME: //this is really for diagnostic type stuff...
if (FS_FLocateFile(fname, FSLF_IFFOUND, &loc)) if (FS_FLocateFile(fname, FSLF_IFFOUND, &loc))
{ {
nlen = snprintf(out, outlen, "%s/%s", loc.search->logicalpath, fname); nlen = Q_snprintfz(out, outlen, "%s/%s", loc.search->logicalpath, fname);
break; break;
} }
//fallthrough //fallthrough
case FS_GAMEONLY: case FS_GAMEONLY:
if (com_homepathenabled) if (com_homepathenabled)
nlen = snprintf(out, outlen, "%s%s/%s", com_homepath, gamedirfile, fname); nlen = Q_snprintfz(out, outlen, "%s%s/%s", com_homepath, gamedirfile, fname);
else else
nlen = snprintf(out, outlen, "%s%s/%s", com_gamepath, gamedirfile, fname); nlen = Q_snprintfz(out, outlen, "%s%s/%s", com_gamepath, gamedirfile, fname);
break; break;
case FS_LIBRARYPATH: case FS_LIBRARYPATH:
#ifdef FTE_LIBRARY_PATH #ifdef FTE_LIBRARY_PATH
nlen = snprintf(out, outlen, STRINGIFY(FTE_LIBRARY_PATH)"/%s", fname); nlen = Q_snprintfz(out, outlen, STRINGIFY(FTE_LIBRARY_PATH)"/%s", fname);
break; break;
#else #else
return false; return false;
#endif #endif
case FS_BINARYPATH: case FS_BINARYPATH:
if (host_parms.binarydir && *host_parms.binarydir) if (host_parms.binarydir && *host_parms.binarydir)
nlen = snprintf(out, outlen, "%s%s", host_parms.binarydir, fname); nlen = Q_snprintfz(out, outlen, "%s%s", host_parms.binarydir, fname);
else else
nlen = snprintf(out, outlen, "%s%s", host_parms.basedir, fname); nlen = Q_snprintfz(out, outlen, "%s%s", host_parms.basedir, fname);
break; break;
case FS_ROOT: case FS_ROOT:
if (com_installer) if (com_installer)
return false; return false;
if (com_homepathenabled) if (com_homepathenabled)
nlen = snprintf(out, outlen, "%s%s", com_homepath, fname); nlen = Q_snprintfz(out, outlen, "%s%s", com_homepath, fname);
else else
nlen = snprintf(out, outlen, "%s%s", com_gamepath, fname); nlen = Q_snprintfz(out, outlen, "%s%s", com_gamepath, fname);
break; break;
case FS_BASEGAMEONLY: // fte/ case FS_BASEGAMEONLY: // fte/
@ -2383,9 +2383,9 @@ qboolean FS_NativePath(const char *fname, enum fs_relative relativeto, char *out
if (!last) if (!last)
return false; //eep? return false; //eep?
if (com_homepathenabled) if (com_homepathenabled)
nlen = snprintf(out, outlen, "%s%s/%s", com_homepath, last, fname); nlen = Q_snprintfz(out, outlen, "%s%s/%s", com_homepath, last, fname);
else else
nlen = snprintf(out, outlen, "%s%s/%s", com_gamepath, last, fname); nlen = Q_snprintfz(out, outlen, "%s%s/%s", com_gamepath, last, fname);
break; break;
case FS_PUBGAMEONLY: // $gamedir/ or qw/ but not fte/ case FS_PUBGAMEONLY: // $gamedir/ or qw/ but not fte/
last = NULL; last = NULL;
@ -2406,9 +2406,9 @@ qboolean FS_NativePath(const char *fname, enum fs_relative relativeto, char *out
if (!last) if (!last)
return false; //eep? return false; //eep?
if (com_homepathenabled) if (com_homepathenabled)
nlen = snprintf(out, outlen, "%s%s/%s", com_homepath, last, fname); nlen = Q_snprintfz(out, outlen, "%s%s/%s", com_homepath, last, fname);
else else
nlen = snprintf(out, outlen, "%s%s/%s", com_gamepath, last, fname); nlen = Q_snprintfz(out, outlen, "%s%s/%s", com_gamepath, last, fname);
break; break;
case FS_PUBBASEGAMEONLY: // qw/ (fixme: should be the last non-private basedir) case FS_PUBBASEGAMEONLY: // qw/ (fixme: should be the last non-private basedir)
last = NULL; last = NULL;
@ -2424,9 +2424,9 @@ qboolean FS_NativePath(const char *fname, enum fs_relative relativeto, char *out
if (!last) if (!last)
return false; //eep? return false; //eep?
if (com_homepathenabled) if (com_homepathenabled)
nlen = snprintf(out, outlen, "%s%s/%s", com_homepath, last, fname); nlen = Q_snprintfz(out, outlen, "%s%s/%s", com_homepath, last, fname);
else else
nlen = snprintf(out, outlen, "%s%s/%s", com_gamepath, last, fname); nlen = Q_snprintfz(out, outlen, "%s%s/%s", com_gamepath, last, fname);
break; break;
default: default:
Sys_Error("FS_NativePath case not handled\n"); Sys_Error("FS_NativePath case not handled\n");
@ -3840,9 +3840,10 @@ qboolean FS_Restarted(unsigned int *since)
} }
#ifdef __WIN32 //already assumed to be case insensitive. let the OS keep fixing up the paths itself. #ifdef __WIN32 //already assumed to be case insensitive. let the OS keep fixing up the paths itself.
static void FS_FixupFileCase(char *out, size_t outsize, const char *basedir, const char *entry) static qboolean FS_FixupFileCase(char *out, size_t outsize, const char *basedir, const char *entry, qboolean isdir)
{ {
Q_snprintfz(out, outsize, "%s%s", basedir, entry); Q_snprintfz(out, outsize, "%s%s", basedir, entry);
return true;
} }
#else #else
struct fixupcase_s struct fixupcase_s