From db38d4af2126ecb2aa62658786d4798e0f81e847 Mon Sep 17 00:00:00 2001 From: Sun Yongyue Date: Sun, 30 Sep 2018 11:09:56 +0800 Subject: [PATCH] Remove some useless code and check array index before using it Signed-off-by: Sun Yongyue --- servant/libservant/StatReport.cpp | 4 ++-- tools/tars2cpp/tars2cpp.cpp | 2 +- util/src/tc_cgi.cpp | 4 ++-- util/src/tc_config.cpp | 1 - 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/servant/libservant/StatReport.cpp b/servant/libservant/StatReport.cpp index f550bd0..3970bcd 100644 --- a/servant/libservant/StatReport.cpp +++ b/servant/libservant/StatReport.cpp @@ -115,7 +115,7 @@ void StatReport::setReportInfo(const StatFPrx& statPrx, _maxReportSize = iMaxReportSize; } vector vtSetInfo = TC_Common::sepstr(strSetDivision,"."); - if (vtSetInfo.size()!=3 ||(vtSetInfo.size()==3&&(vtSetInfo[0]=="*"||vtSetInfo[1]=="*"))) + if (vtSetInfo.size()!=3 ||(vtSetInfo[0]=="*"||vtSetInfo[1]=="*")) { _setArea= ""; _setID = ""; @@ -210,7 +210,7 @@ bool StatReport::divison2SetInfo(const string& str, vector& vtSetInfo) { vtSetInfo = TC_Common::sepstr(str,"."); - if (vtSetInfo.size() != 3 ||(vtSetInfo.size()==3&&(vtSetInfo[0]=="*"||vtSetInfo[1]=="*"))) + if (vtSetInfo.size() != 3 ||(vtSetInfo[0]=="*"||vtSetInfo[1]=="*")) { TLOGERROR(__FUNCTION__ << ":" << __LINE__ << "|bad set name [" << str << endl); return false; diff --git a/tools/tars2cpp/tars2cpp.cpp b/tools/tars2cpp/tars2cpp.cpp index fa08872..326fce1 100644 --- a/tools/tars2cpp/tars2cpp.cpp +++ b/tools/tars2cpp/tars2cpp.cpp @@ -485,7 +485,7 @@ string Tars2Cpp::generateH(const StructPtr& pPtr, const string& namespaceId) con if (vPtr) { BuiltinPtr bPtr = BuiltinPtr::dynamicCast(vPtr->getTypePtr()); - if (!bPtr || (bPtr && bPtr->kind() == Builtin::KindString)) //非内建类型或者string 类型不能memset + if (!bPtr || bPtr->kind() == Builtin::KindString) //非内建类型或者string 类型不能memset { continue; } diff --git a/util/src/tc_cgi.cpp b/util/src/tc_cgi.cpp index 065e4b2..3af7c77 100644 --- a/util/src/tc_cgi.cpp +++ b/util/src/tc_cgi.cpp @@ -199,7 +199,7 @@ void TC_Cgi::parseNormal(multimap &mmpParams, const string& sBuf if(iFlag == 0) { - while ( (sBuffer[pos] != '=') && (pos < len) ) + while ( (pos < len) && (sBuffer[pos] != '=') ) { sTmp += (sBuffer[pos] == '+') ? ' ' : sBuffer[pos]; @@ -208,7 +208,7 @@ void TC_Cgi::parseNormal(multimap &mmpParams, const string& sBuf } else { - while ( (sBuffer[pos] != '&') && (pos < len) ) + while ( (pos < len) && (sBuffer[pos] != '&') ) { sTmp += (sBuffer[pos] == '+') ? ' ' : sBuffer[pos]; diff --git a/util/src/tc_config.cpp b/util/src/tc_config.cpp index 9a0789a..bd05976 100644 --- a/util/src/tc_config.cpp +++ b/util/src/tc_config.cpp @@ -319,7 +319,6 @@ string TC_ConfigDomain::reverse_parse(const string &s) case '\t': param += "\\t"; break; - break; case '=': param += "\\="; break;