Skip to content

Commit

Permalink
Add some limits
Browse files Browse the repository at this point in the history
  • Loading branch information
w4123 committed May 25, 2018
1 parent a95e114 commit 8bde466
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions Dice/RD.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class RD
for (auto i : strDiceCnt)
if (!isdigit(i))
return Input_Err;
if (strDiceCnt.length() > 3)
if (strDiceCnt.length() > 3 || (strDiceCnt.length() == 3 && strDiceCnt != "100"))
return DiceTooBig_Err;
std::string strAddVal = dice.substr(dice.find("a") + 1);
for (auto i : strAddVal)
Expand Down Expand Up @@ -124,7 +124,7 @@ class RD
else if (dice[0] == 'P')
{
vBnP.push_back(P_Dice);
if (dice.length() > 4)
if (dice.length() > 2)
return DiceTooBig_Err;
for (int i = 1; i != dice.length(); i++)
if (!isdigit(dice[i]))
Expand Down Expand Up @@ -161,7 +161,7 @@ class RD
else if (dice[0] == 'B')
{
vBnP.push_back(B_Dice);
if (dice.length() > 4)
if (dice.length() > 2)
return DiceTooBig_Err;
for (int i = 1; i != dice.length(); i++)
if (!isdigit(dice[i]))
Expand Down Expand Up @@ -235,9 +235,9 @@ class RD
}
else if (!boolContainK)
{
if (dice.substr(0, dice.find("D")).length() > 3)
if (dice.substr(0, dice.find("D")).length() > 3 || (dice.substr(0, dice.find("D")).length() == 3 && dice.substr(0, dice.find("D")) != "100"))
return DiceTooBig_Err;
if (dice.substr(dice.find("D") + 1).length() > 5)
if (dice.substr(dice.find("D") + 1).length() > 4 || (dice.substr(dice.find("D") + 1).length() == 4 && dice.substr(dice.find("D") + 1) != "1000"))
return TypeTooBig_Err;
int intDiceCnt = dice.substr(0, dice.find("D")).length() == 0 ? 1 : stoi(dice.substr(0, dice.find("D")));
int intDiceType = stoi(dice.substr(dice.find("D") + 1));
Expand Down Expand Up @@ -267,8 +267,10 @@ class RD
return Value_Err;
int intKNum = stoi(dice.substr(dice.find("K") + 1));
dice = dice.substr(0, dice.find("K"));
if (dice.substr(0, dice.find("D")).length() > 3 || dice.substr(dice.find("D") + 1).length() > 5)
return Value_Err;
if (dice.substr(0, dice.find("D")).length() > 3 || (dice.substr(0, dice.find("D")).length() == 3 && dice.substr(0, dice.find("D")) != "100"))
return DiceTooBig_Err;
if (dice.substr(dice.find("D") + 1).length() > 4 || (dice.substr(dice.find("D") + 1).length() == 4 && dice.substr(dice.find("D") + 1) != "1000"))
return TypeTooBig_Err;
int intDiceCnt = dice.substr(0, dice.find("D")).length() == 0 ? 1 : stoi(dice.substr(0, dice.find("D")));
int intDiceType = stoi(dice.substr(dice.find("D") + 1));
if (intKNum <= 0 || intDiceCnt == 0)
Expand Down Expand Up @@ -539,6 +541,10 @@ class RD
{
std::string strReturnString = strDice;
strReturnString.append("=");
if(FormStringSeparate().length() > 30)
{
return FormShortString();
}
strReturnString.append(FormStringSeparate());
if (FormStringSeparate() != FormStringCombined())
{
Expand All @@ -547,7 +553,7 @@ class RD
}
if (FormStringCombined() != std::to_string(intTotal))
{
strReturnString.append("=");
strReturnString.append("=");
strReturnString.append(std::to_string(intTotal));
}
return strReturnString;
Expand Down
Binary file modified SDK_Release.lib
Binary file not shown.

0 comments on commit 8bde466

Please sign in to comment.