Permalink
Browse files

Wz3: Fix base name stuff

Don't return pointer to local variable!
Disable it for sINTRO (where we have neither proper file IO nor the string library)
use s*String functions which always ensure 0-termination
  • Loading branch information...
1 parent 59b8140 commit e9c3310f214264322a39ffd7fd3e2042e88e48f8 @rygorous rygorous committed Apr 24, 2012
Showing with 20 additions and 20 deletions.
  1. +11 −12 werkkzeug3/_start.cpp
  2. +1 −1 werkkzeug3/_start.hpp
  3. +8 −7 werkkzeug3/mainplayer.cpp
View
@@ -6148,26 +6148,25 @@ sU8 *sSystem_::LoadFile(const sChar *name)
/****************************************************************************/
+#if !sINTRO
//----------------------------------------------------------------------------
-// retrieve current exe name
+// get base name of current exe
//----------------------------------------------------------------------------
-sChar *sSystem_::GetModuleName()
+void sSystem_::GetModuleBaseName(sChar *buffer,sInt size)
{
// Retrieves the full path for the file that contains the specified module
char str[MAX_PATH];
GetModuleFileName(NULL, str, MAX_PATH);
-
- // remove full path to just keep filename
- char * fileName;
- fileName = strrchr(str,'\\')+1;
-
- // remove .exe extension to just keep basename
- char baseName[MAX_PATH] = "";
- strncpy(baseName, fileName, strlen(fileName)-4);
+
+ // strip path
+ sCopyString(buffer,sFileFromPathString(str),size);
- return baseName;
+ // remove extension (if present) to just keep base name
+ sChar *ext = sFileExtensionString(buffer);
+ if (ext)
+ *ext = 0;
}
-
+#endif
/****************************************************************************/
@@ -990,7 +990,7 @@ struct sSystem_
sBool DeleteFile(const sChar *name); // delete file from disk
void GetCurrentDir(sChar *buffer,sInt size); // get current dir as "c:/nxn/genthree"
sU32 GetDriveMask(); // get bitmask of available drives
- sChar *GetModuleName(); // get current exe name
+ void GetModuleBaseName(sChar *buffer,sInt size); // get base name of current exe
sBitmap *LoadBitmap(const sU8 *data,sInt size); // load bitmap using windows loader
sBool LoadBitmapCore(const sU8 *data,sInt size,sInt &x,sInt &y,sU8 *&d); // simplified version for intro
@@ -245,22 +245,23 @@ sBool sAppHandler(sInt code,sDInt value)
#if !LINKEDIN
data = PtrTable[0];
-//#if !sINTRO
+#if !sINTRO
if(((sInt)data)==0x54525450)
{
data = sSystem->LoadFile(sSystem->GetCmdLine());
if(data==0)
{
- // get module name and load a .kx file with the same name
- sChar * kxData = sSystem->GetModuleName();
- sAppendString(kxData, ".kx", sGetStringLen(kxData)+3 );
- data = sSystem->LoadFile(kxData);
+ // get module name and load a .kx file with the same name
+ sChar kxData[256];
+ sSystem->GetModuleBaseName(kxData, sizeof(kxData));
+ sAppendString(kxData, ".kx", sizeof(kxData));
+ data = sSystem->LoadFile(kxData);
//data = sSystem->LoadFile("id08.kx");
- if(data==0)
+ if(data==0)
sSystem->Abort("need data file");
}
}
-//#endif
+#endif
#else
data = DebugData;
#endif

0 comments on commit e9c3310

Please sign in to comment.