astub.c: clean up [']+[F] menu code, fixing one oob access w/ dyn. entries.

git-svn-id: https://svn.eduke32.com/eduke32@4417 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2014-04-05 20:27:33 +00:00
parent 7603f432df
commit d2098c320a

View file

@ -12943,8 +12943,10 @@ static void GenericSpriteSearch(void)
////////// SPECIAL FUNCTIONS MENU ////////// ////////// SPECIAL FUNCTIONS MENU //////////
#define MENU_ENTRY_SIZE 25
static int32_t numMenuFunctions = 8; static int32_t numMenuFunctions = 8;
static char *funcMenuStrings[8*3] = static char funcMenuStrings[8*3][MENU_ENTRY_SIZE] =
{ {
"Replace invalid tiles", "Replace invalid tiles",
"Delete all spr of tile #", "Delete all spr of tile #",
@ -12961,7 +12963,7 @@ static ofstype funcMenuStatenum[8*2];
void registerMenuFunction(const char *funcname, int32_t stateidx) void registerMenuFunction(const char *funcname, int32_t stateidx)
{ {
char fn[25]; char fn[MENU_ENTRY_SIZE];
int32_t i; int32_t i;
if (funcname == NULL) // unregister stateidx if (funcname == NULL) // unregister stateidx
@ -12971,16 +12973,14 @@ void registerMenuFunction(const char *funcname, int32_t stateidx)
for (i=8; i<numMenuFunctions; i++) for (i=8; i<numMenuFunctions; i++)
if (funcMenuStatenum[i-8]==stateidx) if (funcMenuStatenum[i-8]==stateidx)
{ {
Bfree(funcMenuStrings[i]);
for (j=i; j<numMenuFunctions-1; j++) for (j=i; j<numMenuFunctions-1; j++)
{ {
funcMenuStatenum[j] = funcMenuStatenum[j+1]; funcMenuStatenum[j-8] = funcMenuStatenum[j+1-8];
funcMenuStrings[j] = funcMenuStrings[j+1]; Bmemcpy(funcMenuStrings[j], funcMenuStrings[j+1], MENU_ENTRY_SIZE);
} }
funcMenuStatenum[j] = 0; funcMenuStatenum[j-8] = 0;
funcMenuStrings[j] = NULL; Bmemset(funcMenuStrings[j], 0, MENU_ENTRY_SIZE);
numMenuFunctions--; numMenuFunctions--;
@ -12990,8 +12990,8 @@ void registerMenuFunction(const char *funcname, int32_t stateidx)
return; return;
} }
// register menu entry named FUNCNAME to call the M32script // Register menu entry named FUNCNAME to call the M32script
// state with index STATEIDX // state with index STATEIDX.
Bstrncpyz(fn, funcname, sizeof(fn)); Bstrncpyz(fn, funcname, sizeof(fn));
for (i=8; i<numMenuFunctions; i++) for (i=8; i<numMenuFunctions; i++)
@ -12999,8 +12999,7 @@ void registerMenuFunction(const char *funcname, int32_t stateidx)
if (funcMenuStatenum[i-8]==stateidx) if (funcMenuStatenum[i-8]==stateidx)
{ {
// same stateidx, different name // same stateidx, different name
Bfree(funcMenuStrings[i]); Bstrncpyz(funcMenuStrings[i], fn, MENU_ENTRY_SIZE);
funcMenuStrings[i] = Bstrdup(fn);
return; return;
} }
else if (!Bstrcmp(funcMenuStrings[i], fn)) else if (!Bstrcmp(funcMenuStrings[i], fn))
@ -13014,7 +13013,7 @@ void registerMenuFunction(const char *funcname, int32_t stateidx)
if (numMenuFunctions == 3*8) if (numMenuFunctions == 3*8)
return; // max reached return; // max reached
funcMenuStrings[numMenuFunctions] = Bstrdup(fn); Bstrncpyz(funcMenuStrings[numMenuFunctions], fn, MENU_ENTRY_SIZE);
funcMenuStatenum[numMenuFunctions-8] = stateidx; funcMenuStatenum[numMenuFunctions-8] = stateidx;
numMenuFunctions++; numMenuFunctions++;
@ -13078,7 +13077,6 @@ static void FuncMenu(void)
drawgradient(); drawgradient();
disptext[dispwidth] = 0; disptext[dispwidth] = 0;
// clearmidstatbar16();
FuncMenuOpts(); FuncMenuOpts();
@ -13105,10 +13103,10 @@ static void FuncMenu(void)
row--; row--;
} }
} }
#if 1
if (PRESSED_KEYSC(LEFT)) if (PRESSED_KEYSC(LEFT))
{ {
if (col==1 || col==2) if (col > 0)
{ {
printext16(xpos,ypos+row*8,editorcolors[11],0,disptext,0); printext16(xpos,ypos+row*8,editorcolors[11],0,disptext,0);
col--; col--;
@ -13121,7 +13119,7 @@ static void FuncMenu(void)
if (PRESSED_KEYSC(RIGHT)) if (PRESSED_KEYSC(RIGHT))
{ {
if ((col==0 || col==1) && crowmax[col+1]>=0) if (col < 2 && crowmax[col+1]>=0)
{ {
printext16(xpos,ypos+row*8,editorcolors[11],0,disptext,0); printext16(xpos,ypos+row*8,editorcolors[11],0,disptext,0);
col++; col++;
@ -13131,7 +13129,7 @@ static void FuncMenu(void)
if (row > rowmax) row = rowmax; if (row > rowmax) row = rowmax;
} }
} }
#endif
if (PRESSED_KEYSC(ENTER)) if (PRESSED_KEYSC(ENTER))
editval = 1; editval = 1;
@ -13365,7 +13363,6 @@ static void FuncMenu(void)
} }
printext16(xpos,ypos+row*MENU_Y_SPACING,editorcolors[11],editorcolors[0],disptext,0); printext16(xpos,ypos+row*MENU_Y_SPACING,editorcolors[11],editorcolors[0],disptext,0);
/*clearmidstatbar16();*/
showframe(1); showframe(1);
keystatus[KEYSC_ESC] = 0; keystatus[KEYSC_ESC] = 0;