mirror of
https://github.com/fabiangreffrath/woof.git
synced 2025-09-23 12:04:38 -04:00
don't crash if wrong input for command -recordfrom, strict arguments checking (#680)
This commit is contained in:
parent
e1ab6d938d
commit
0f49d69a16
26
src/d_main.c
26
src/d_main.c
@ -1821,7 +1821,7 @@ int demowarp = -1;
|
||||
|
||||
void D_DoomMain(void)
|
||||
{
|
||||
int p, slot;
|
||||
int p;
|
||||
|
||||
setbuf(stdout,NULL);
|
||||
|
||||
@ -2569,19 +2569,24 @@ void D_DoomMain(void)
|
||||
// Support -loadgame with -record and reimplement -recordfrom.
|
||||
|
||||
//!
|
||||
// @arg <save> <demo>
|
||||
// @arg <savenum> <demofile>
|
||||
// @category demo
|
||||
//
|
||||
// Records a demo starting from a saved game. It is the same as "-loadgame
|
||||
// <save> -record <demo>". "-loadgame <save> -playdemo <demo>" plays back the
|
||||
// demo starting from the saved game.
|
||||
// Record a demo, loading from the given filename. Equivalent to -loadgame
|
||||
// <savenum> -record <demofile>.
|
||||
//
|
||||
|
||||
if ((slot = M_CheckParm("-recordfrom")) && (p = slot+2) < myargc)
|
||||
G_RecordDemo(myargv[p]);
|
||||
p = M_CheckParmWithArgs("-recordfrom", 2);
|
||||
if (p)
|
||||
{
|
||||
startloadgame = M_ParmArgToInt(p);
|
||||
G_RecordDemo(myargv[p + 2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot = M_CheckParm("-loadgame");
|
||||
p = M_CheckParmWithArgs("-loadgame", 1);
|
||||
if (p)
|
||||
startloadgame = M_ParmArgToInt(p);
|
||||
|
||||
//!
|
||||
// @arg <demo>
|
||||
@ -2627,11 +2632,6 @@ void D_DoomMain(void)
|
||||
demoskip_tics = -1;
|
||||
}
|
||||
|
||||
if (slot && ++slot < myargc)
|
||||
{
|
||||
startloadgame = atoi(myargv[slot]);
|
||||
}
|
||||
|
||||
// [FG] init graphics (WIDESCREENDELTA) before HUD widgets
|
||||
I_InitGraphics();
|
||||
|
||||
|
@ -1699,6 +1699,7 @@ static void G_LoadGameErr(const char *msg)
|
||||
M_ForcedLoadGame(msg); // Print message asking for 'Y' to force
|
||||
if (command_loadgame) // If this was a command-line -loadgame
|
||||
{
|
||||
G_CheckDemoStatus(); // If there was also a -record
|
||||
D_StartTitle(); // Start the title screen
|
||||
gamestate = GS_DEMOSCREEN; // And set the game state accordingly
|
||||
}
|
||||
@ -3759,6 +3760,10 @@ boolean G_CheckDemoStatus(void)
|
||||
if (demorecording)
|
||||
{
|
||||
demorecording = false;
|
||||
|
||||
if (!demo_p)
|
||||
return false;
|
||||
|
||||
*demo_p++ = DEMOMARKER;
|
||||
|
||||
G_AddDemoFooter();
|
||||
|
39
src/m_argv.c
39
src/m_argv.c
@ -98,7 +98,25 @@ int M_ParmArg2ToInt(int p)
|
||||
#if defined(HAVE_PARAMS_GEN)
|
||||
#include "params.h"
|
||||
|
||||
static int CheckArgs(int p, int num_args)
|
||||
static int CheckArgs(int p)
|
||||
{
|
||||
int i;
|
||||
|
||||
++p;
|
||||
|
||||
for (i = p; i < myargc; ++i)
|
||||
{
|
||||
if (myargv[i][0] == '-')
|
||||
break;
|
||||
}
|
||||
|
||||
if (i > p)
|
||||
return i;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int CheckNumArgs(int p, int num_args)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -110,7 +128,7 @@ static int CheckArgs(int p, int num_args)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i > p)
|
||||
if (i == p + num_args)
|
||||
return i;
|
||||
|
||||
return 0;
|
||||
@ -123,7 +141,7 @@ void M_CheckCommandLine(void)
|
||||
while (p < myargc)
|
||||
{
|
||||
int i;
|
||||
int args = -1;
|
||||
int args = 0;
|
||||
|
||||
for (i = 0; i < arrlen(params_with_args); ++i)
|
||||
{
|
||||
@ -131,7 +149,7 @@ void M_CheckCommandLine(void)
|
||||
!strcasecmp(myargv[p], "-deh") ||
|
||||
!strcasecmp(myargv[p], "-bex"))
|
||||
{
|
||||
args = myargc;
|
||||
args = -1;
|
||||
break;
|
||||
}
|
||||
else if (!strcasecmp(myargv[p], "-warp") ||
|
||||
@ -147,14 +165,23 @@ void M_CheckCommandLine(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (args > 0)
|
||||
if (args)
|
||||
{
|
||||
int check = CheckArgs(p, args);
|
||||
int check = args > 0 ? CheckNumArgs(p, args) : CheckArgs(p);
|
||||
|
||||
if (check)
|
||||
{
|
||||
p = check;
|
||||
}
|
||||
// -warp can have only one parameter
|
||||
else if (!strcasecmp(myargv[p], "-warp"))
|
||||
{
|
||||
check = CheckNumArgs(p, 1);
|
||||
if (!check)
|
||||
I_Error("No parameter for '-warp'.");
|
||||
else
|
||||
p = check;
|
||||
}
|
||||
// -turbo has default value
|
||||
else if (!strcasecmp(myargv[p], "-turbo"))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user