Skip to content

Commit 599a162

Browse files
committed
Add a quick check on the # of parameter values for the variable_modXX parameters. Throw and error and exit the program if there aren't the expected 8 parameter values.
1 parent a625674 commit 599a162

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Comet.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,40 @@ void LoadParameters(char* pszParamsFile,
556556
if (!strncmp(szParamName, "variable_mod", 12) && strlen(szParamName) == 14)
557557
{
558558
char szTmp[512], szTmp1[512];
559+
560+
// Validate that the variable mod parameter has the correct number of fields (8 entries)
561+
int iEntryCount = 0;
562+
bool inString = false;
563+
564+
for (int i = 0; szParamVal[i] != '\0'; i++)
565+
{
566+
if (!isspace(szParamVal[i]))
567+
{ // We're in a non-whitespace character
568+
if (!inString)
569+
{ // Starting a new string
570+
iEntryCount++;
571+
inString = true;
572+
}
573+
}
574+
else
575+
{ // We hit whitespace
576+
inString = false;
577+
}
578+
}
579+
580+
if (iEntryCount != 8)
581+
{
582+
string strErrorMsg = "\n Comet version " + g_sCometVersion + "\n\n"
583+
+ " Error: Invalid variable_mod parameter found; expected parameter 8 values but found " + std::to_string(iEntryCount) + ".\n"
584+
+ " " + std::string(szParamName) + " = " + std::string(szParamVal) + "\n";
585+
logerr(strErrorMsg);
586+
exit(1);
587+
}
588+
559589
varModsParam.szVarModChar[0] = '\0';
560590
varModsParam.iMinNumVarModAAPerMod = 0;
561591
varModsParam.iMaxNumVarModAAPerMod = 0;
592+
562593
sscanf(szParamVal, "%lf %31s %d %511s %d %d %d %s",
563594
&varModsParam.dVarModMass,
564595
varModsParam.szVarModChar,

0 commit comments

Comments
 (0)