From a230d24226a2ea40826eda56104accf5961dadd4 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 30 Jul 2016 21:56:31 +0000 Subject: [PATCH] Allow trailing comments after num_levels and num_secrets --- common/main/mission.h | 3 ++- similar/main/mission.cpp | 29 +++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/common/main/mission.h b/common/main/mission.h index 11f2fc3af..32e3c8b7c 100644 --- a/common/main/mission.h +++ b/common/main/mission.h @@ -37,7 +37,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "ntstring.h" #define MAX_MISSIONS 5000 // ZICO - changed from 300 to get more levels in list -#define MAX_LEVELS_PER_MISSION 127 // KREATOR - increased from 30 (limited by Demo and Multiplayer code) +// KREATOR - increased from 30 (limited by Demo and Multiplayer code) +constexpr uint8_t MAX_LEVELS_PER_MISSION = 127; constexpr uint8_t MAX_SECRET_LEVELS_PER_MISSION = 127; // KREATOR - increased from 6 (limited by Demo and Multiplayer code) #define MISSION_NAME_LEN 25 diff --git a/similar/main/mission.cpp b/similar/main/mission.cpp index 0da3a8d68..b43e21a9a 100644 --- a/similar/main/mission.cpp +++ b/similar/main/mission.cpp @@ -861,9 +861,17 @@ static int load_mission(const mle *mission) if ((v=get_value(buf))!=NULL) { char *ip; - unsigned long n_levels = strtoul(v, &ip, 10); + const auto n_levels = strtoul(v, &ip, 10); Assert(n_levels <= MAX_LEVELS_PER_MISSION); - n_levels = min(n_levels, *ip ? 0ul : MAX_LEVELS_PER_MISSION); + if (n_levels > MAX_LEVELS_PER_MISSION) + continue; + if (*ip) + { + while (isspace(static_cast(*ip))) + ++ip; + if (*ip && *ip != ';') + continue; + } Level_names = make_unique(n_levels); range_for (auto &i, unchecked_partial_range(Level_names.get(), n_levels)) { @@ -884,11 +892,20 @@ static int load_mission(const mle *mission) else if (istok(buf,"num_secrets")) { if ((v=get_value(buf))!=NULL) { char *ip; - unsigned long n_levels = strtoul(v, &ip, 10); + const auto n_levels = strtoul(v, &ip, 10); Assert(n_levels <= MAX_SECRET_LEVELS_PER_MISSION); - N_secret_levels = min(n_levels, *ip ? 0ul : MAX_SECRET_LEVELS_PER_MISSION); - Secret_level_names = make_unique(N_secret_levels); - Secret_level_table = make_unique(N_secret_levels); + if (n_levels > MAX_SECRET_LEVELS_PER_MISSION) + continue; + if (*ip) + { + while (isspace(static_cast(*ip))) + ++ip; + if (*ip && *ip != ';') + continue; + } + N_secret_levels = n_levels; + Secret_level_names = make_unique(n_levels); + Secret_level_table = make_unique(n_levels); for (int i=0;i