m32script: when failing to load file, don't append '.m32' if already there.

So that there are no error messages like "M32 file `a.m32.m32' not found."

Also, in build.c's 'save as' code, add a bound check that would probably
always pass in practice, but looks a bit safer and may fail in very cornerly
cases.

git-svn-id: https://svn.eduke32.com/eduke32@4124 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-10-28 21:26:30 +00:00
parent 0fdcc0a1d4
commit 8beb990640
2 changed files with 9 additions and 6 deletions

View file

@ -7770,7 +7770,7 @@ CANCEL:
i = 0; i = 0;
while (boardfilename[i] != 0 && i < 64) while (boardfilename[i] != 0 && i < 64)
i++; i++;
if (boardfilename[i-4] == '.') if (i >= 4 && boardfilename[i-4] == '.')
i -= 4; i -= 4;
boardfilename[i] = 0; boardfilename[i] = 0;

View file

@ -3677,6 +3677,8 @@ void C_CompilationInfo(void)
initprintf(" %d/%d quotes, %d/%d quote redefinitions\n", k,MAXQUOTES, g_numQuoteRedefinitions,MAXQUOTES); initprintf(" %d/%d quotes, %d/%d quote redefinitions\n", k,MAXQUOTES, g_numQuoteRedefinitions,MAXQUOTES);
} }
EDUKE32_STATIC_ASSERT((sizeof(keyw)/sizeof(keyw[0]))-1 == CON_END);
void C_Compile(const char *filenameortext, int32_t isfilename) void C_Compile(const char *filenameortext, int32_t isfilename)
{ {
char *mptr = NULL; char *mptr = NULL;
@ -3719,9 +3721,6 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
return; return;
} }
if ((sizeof(keyw)/sizeof(keyw[0]))-1 != CON_END)
initprintf("INTERNAL WARNING: keyw[] and CON_END don't match!\n");
g_scriptPtr = script+1; g_scriptPtr = script+1;
firstime = 0; firstime = 0;
@ -3742,8 +3741,12 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
fp = kopen4load(mptr, 0 /*g_loadFromGroupOnly*/); fp = kopen4load(mptr, 0 /*g_loadFromGroupOnly*/);
if (fp == -1) // JBF: was 0 if (fp == -1) // JBF: was 0
{ {
Bstrcat(&mptr[fs], ".m32"); if (fs >= 4 && Bmemcmp(&mptr[fs-4], ".m32", 4) != 0)
fp = kopen4load(mptr, 0 /*g_loadFromGroupOnly*/); {
Bstrcat(&mptr[fs], ".m32");
fp = kopen4load(mptr, 0 /*g_loadFromGroupOnly*/);
}
if (fp == -1) if (fp == -1)
{ {
initprintf("M32 file `%s' not found.\n", mptr); initprintf("M32 file `%s' not found.\n", mptr);