From 4c4f124611a98c66b929403aaaad0eb1a8f63018 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 28 Jul 2016 16:07:26 +0100 Subject: [PATCH] Detect if -warp's parm is actually a valid map name (MAPxx or plain number), and print an "invalid map name" message if not --- src/d_main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 14a8a06e..b61ec414 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1060,10 +1060,11 @@ void D_SRB2Main(void) if (M_CheckParm("-warp") && M_IsNextParm()) { const char *word = M_GetNextParm(); - if (fastncmp(word, "MAP", 3)) + char ch; // use this with sscanf to catch non-digits with + if (fastncmp(word, "MAP", 3)) // MAPxx name pstartmap = M_MapNumber(word[3], word[4]); - else - pstartmap = atoi(word); + else if (sscanf(word, "%d%c", &pstartmap, &ch) != 1) // a plain number + I_Error("Cannot warp to map %s (invalid map name)\n", word); // Don't check if lump exists just yet because the wads haven't been loaded! // Just do a basic range check here. if (pstartmap < 1 || pstartmap > NUMMAPS)