Skip to content

Commit

Permalink
fix more UB
Browse files Browse the repository at this point in the history
  • Loading branch information
w4123 committed Nov 23, 2018
1 parent 9b30d18 commit 6573493
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions Dice/Dice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ EVE_PrivateMsg_EX(__eventPrivateMsg)
eve.message_block();
const string strNickName = getName(eve.fromQQ);
string strLowerMessage = eve.message;
transform(strLowerMessage.begin(), strLowerMessage.end(), strLowerMessage.begin(), tolower);
transform(strLowerMessage.begin(), strLowerMessage.end(), strLowerMessage.begin(), [](unsigned char c) { return tolower(c); });
if (strLowerMessage.substr(intMsgCnt, 4) == "help")
{
AddMsgToQueue(GlobalMsg["strHlpMsg"], eve.fromQQ);
Expand Down Expand Up @@ -788,7 +788,7 @@ EVE_PrivateMsg_EX(__eventPrivateMsg)
intMsgCnt++;
string strSearch = eve.message.substr(intMsgCnt);
for (auto& n : strSearch)
n = toupper(n);
n = toupper(static_cast<unsigned char>(n));
string strReturn;
if (RuleGetter->analyze(strSearch, strReturn))
{
Expand Down Expand Up @@ -1480,7 +1480,7 @@ EVE_GroupMsg_EX(__eventGroupMsg)
eve.message_block();
const string strNickName = getName(eve.fromQQ, eve.fromGroup);
string strLowerMessage = eve.message;
transform(strLowerMessage.begin(), strLowerMessage.end(), strLowerMessage.begin(), tolower);
transform(strLowerMessage.begin(), strLowerMessage.end(), strLowerMessage.begin(), [](unsigned char c) { return tolower(c); });
if (strLowerMessage.substr(intMsgCnt, 3) == "bot")
{
intMsgCnt += 3;
Expand Down Expand Up @@ -2545,7 +2545,7 @@ EVE_GroupMsg_EX(__eventGroupMsg)
intMsgCnt++;
string strSearch = eve.message.substr(intMsgCnt);
for (auto& n : strSearch)
n = toupper(n);
n = toupper(static_cast<unsigned char>(n));
string strReturn;
if (RuleGetter->analyze(strSearch, strReturn))
{
Expand Down Expand Up @@ -3191,7 +3191,7 @@ EVE_DiscussMsg_EX(__eventDiscussMsg)
eve.message_block();
const string strNickName = getName(eve.fromQQ, eve.fromDiscuss);
string strLowerMessage = eve.message;
transform(strLowerMessage.begin(), strLowerMessage.end(), strLowerMessage.begin(), tolower);
transform(strLowerMessage.begin(), strLowerMessage.end(), strLowerMessage.begin(), [](unsigned char c) { return tolower(c); });
if (strLowerMessage.substr(intMsgCnt, 3) == "bot")
{
intMsgCnt += 3;
Expand Down Expand Up @@ -4122,7 +4122,7 @@ EVE_DiscussMsg_EX(__eventDiscussMsg)
intMsgCnt++;
string strSearch = eve.message.substr(intMsgCnt);
for (auto& n : strSearch)
n = toupper(n);
n = toupper(static_cast<unsigned char>(n));
string strReturn;
if (RuleGetter->analyze(strSearch, strReturn))
{
Expand Down
2 changes: 1 addition & 1 deletion Dice/GetRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ bool GetRule::analyze(string& rawStr, string& des)
des = GlobalMsg["strRulesFailedErr"];
return false;
}
for (auto& chr : rawStr)chr = toupper(chr);
for (auto& chr : rawStr)chr = toupper(static_cast<unsigned char> (chr));

if (rawStr.find(':') != string::npos)
{
Expand Down
10 changes: 5 additions & 5 deletions Dice/RD.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class RD
bool boolContainK = false;
for (auto& i : dice)
{
i = toupper(i);
i = toupper(static_cast<unsigned char>(i));
if (!isdigit(static_cast<unsigned char>(i)))
{
if (i == 'D')
Expand Down Expand Up @@ -388,11 +388,11 @@ class RD
{
if (i != 'a' && i != 'A')
{
i = toupper(i);
i = toupper(static_cast<unsigned char>(i));
}
else
{
i = tolower(i);
i = tolower(static_cast<unsigned char>(i));
}
}
if (strDice.empty())
Expand Down Expand Up @@ -443,11 +443,11 @@ class RD
{
if (i != 'a' && i != 'A')
{
i = toupper(i);
i = toupper(static_cast<unsigned char>(i));
}
else
{
i = tolower(i);
i = tolower(static_cast<unsigned char>(i));
}
}
if (strDice.empty())
Expand Down

0 comments on commit 6573493

Please sign in to comment.