From 12d0857ca05dc11cc17f571d3b1cab942949beb1 Mon Sep 17 00:00:00 2001 From: black Date: Mon, 28 Jan 2008 01:02:56 +0000 Subject: [PATCH] Make fgets always return the null string on error. Add code to FS_Open to fix bad paths (replaces \ with /). The code is nasty and #ifdefed out - #define FS_FIX_PATHS to use it. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8028 d7cf8633-e32d-0410-b094-e92efae38249 --- fs.c | 13 +++++++++++++ prvm_cmds.c | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/fs.c b/fs.c index 8fd5d619..8571aed1 100644 --- a/fs.c +++ b/fs.c @@ -1819,6 +1819,19 @@ Open a file. The syntax is the same as fopen */ qfile_t* FS_Open (const char* filepath, const char* mode, qboolean quiet, qboolean nonblocking) { +#ifdef FS_FIX_PATHS + char fixedFileName[MAX_QPATH]; + char *d = fixedFileName; + // try to fix common mistakes (\ instead of /) + for( ; *filepath ; filepath++, d++ ) + if( *filepath != '\\' ) + *d = *filepath; + else + *d = '/'; + *d = '\0'; + filepath = fixedFileName; +#endif + if (FS_CheckNastyPath(filepath, false)) { Con_Printf("FS_Open(\"%s\", \"%s\", %s): nasty filename rejected\n", filepath, mode, quiet ? "true" : "false"); diff --git a/prvm_cmds.c b/prvm_cmds.c index bfa74e5c..236ffc46 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -1596,6 +1596,9 @@ void VM_fgets(void) VM_SAFEPARMCOUNT(1,VM_fgets); + // set the return value regardless of any possible errors + PRVM_G_INT(OFS_RETURN) = OFS_NULL; + filenum = (int)PRVM_G_FLOAT(OFS_PARM0); if (filenum < 0 || filenum >= PRVM_MAX_OPENFILES) { @@ -1628,8 +1631,6 @@ void VM_fgets(void) Con_Printf("fgets: %s: %s\n", PRVM_NAME, string); if (c >= 0 || end) PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(string); - else - PRVM_G_INT(OFS_RETURN) = OFS_NULL; } /* -- 2.39.2